The Center of gravity MT4 Expert Advisor

Post your new strategies, discoveries or just ideas for development

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Sun Oct 18, 2009 6:07 pm

i found a problem in the code
i don't know how it even worked with the wrong numbers in the arrays
seems like it should error out when it tried to access elements past number 2

the line in the code that reads :
double cogCenter[3],cogHigh1[3],cogHigh2[3],cogHigh3[3],cogLow3[3],cogLow2[3],cogLow1[3];
should be :
double cogCenter[181],cogHigh1[181],cogHigh2[181],cogHigh3[181],cogLow3[181],cogLow2[181],cogLow1[181];

it should have 181 in there instead of 3

i tried to speed it up by setting Nmbr_Bars to 3 but it did not work as well
i forgot to change these arrays back to 181
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Mon Oct 19, 2009 8:02 am

this one opens an order if the price goes a half span beyond a cog line and then returns back past the price it was when it first passed the cog line

a span is the distance from one cog line to the next

the stop loss and take profit are still absolute offset from open price
next task is to make them relative to outer cog lines

i have not done much testing but ->
it seems that any setting for trailing stop loss makes things worse - in the code it is set to 0
also - it seems that closing trades if the trend changes is worse - code is commented out

CenterOfGravity2test13.mq4
version .13
for test purposes only
(19.4 KiB) Downloaded 752 times
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

Re: The Center of gravity MT4 Expert Advisor

Postby Edward Revy » Tue Oct 20, 2009 10:10 am

Hi guys, well done!

I saw the latest .13 EA takes multiple entries as price dances back and forth near the same COG line it just took its first trade at.
I guess we should enter only once, or am I missing something?

Regards,
Edward
User avatar
Edward Revy
Site Admin
 
Posts: 209
Joined: Wed Jul 01, 2009 6:20 pm

Re: The Center of gravity MT4 Expert Advisor

Postby Edward Revy » Tue Oct 20, 2009 10:35 am

Another thing:

on 5 min charts where I'm currently running the EA while watching the COG indicator at the same time, I can see that we have multiple instances of double tests of outer COG lines before the true move starts.
Not every test of the COG line will be a double test, but since we have a robot, we should not care about missing some trades (just my opinion).

So, the idea, is to open a trade when the COG line has been tested for the second time and then adding the rest as planned:
if the price goes a half span beyond a cog line and then returns back past the price it was when it first passed the cog line


this way the stop loss will be definitely set behind the lowest of the two bottoms (when buying at the the lower COG line). If there is a loss, we'll know it is justified.

In the attachment, I'm double tests of the COG (although might be a bit different at the moment when it actually happened), but the point is to illustrate the last instance, where the EA already got me into a trade, but it turned out negative pretty quickly. The situation might have been avoided completely, if we were to buy after the second test AND after price returns back above COG, which never happened.
Attachments
cog_double.png
User avatar
Edward Revy
Site Admin
 
Posts: 209
Joined: Wed Jul 01, 2009 6:20 pm

Re: The Center of gravity MT4 Expert Advisor

Postby Edward Revy » Tue Oct 20, 2009 10:46 am

As I was writing this, here is the latest development on the charts.
As you can see, we have a double test now, but it no way looks like a double bottom :)

Now, regarding the idea in some finer details:
- we can consider a double test valid if price in between the tests didn't reach the opposite COG line.
- we can disregard the second test, if price never tried to form a double bottom/top. To identify that we can use certain amount of margin (+- X pips) as allowed difference/distance in between two tops or two bottoms.

Well, after all this, I'd like to add that it might be driving off course, since I've just tried the EA today and have little idea of what is essential for you guys. Anyway, keep it up!

Regards,
Edward
Attachments
cog_no_double.png
User avatar
Edward Revy
Site Admin
 
Posts: 209
Joined: Wed Jul 01, 2009 6:20 pm

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Tue Oct 20, 2009 12:31 pm

Edward Revy - your ideas sound interesting - i am thinking about what you posted
your pics are showing the gravity center 1 indicator
i have one suggestion before you go further
get the gravity center 2 indicator
it has 3 lines above and 3 lines below the center
that is what this ea is using
check my previous post that shows where to download the gravity center 2 indicator
right now i have tried several different stop loss and take profit schemes and they all have good days and bad days
i am working on making each scheme individually selectable for testing
then i will post that code later today i hope
after that i want to work on money management - but maybe first i will look at implementing some of your ideas
but first get the gravity center 2 indicator and see what you think about how it works then
thanks for the feedback
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Tue Oct 20, 2009 1:52 pm

this is an explanation of latest additions
at the top of the code are defines for the stop loss and take profit schemes that can be used :

#define SOFOP 0 // STANDARD_OFFSETS_FROM_OPEN_PRICE
#define OCPSASOC 1 // OUTER_COG_PLUS_SPREAD_AND_SPAN_OFF_CENTER
#define OCPSLASOCPTP 2 // OUTER_COG_PLUS_STOP_LOSS_AND_SPAN_OFF_CENTER_PLUS_TAKE_PROFIT
#define FSPSLOCASOCPTP 3 // FULL_SPAN_PLUS_STOP_LOSS_OFF_CENTER_AND_SPAN_OFF_CENTER_PLUS_TAKE_PROFIT
#define MAXUSLTPS 3 // MAX_USE_STOP_LOSS_TAKE_PROFIT_SCHEMES - reset to 0 if set too high or too low

and there is a variable that can be set to use one of the schemes
extern int useStopLossTakeProfitScheme = 0;

a span is the distance from the center to the first cog line
full span is the distance from the top cog line to the bottom cog line
stop loss and take profit are the variables stopLoss and takeProfit

SOFOP - standard offsets - this is just a normal pip offset from the open price

OCPSASOC - set the stop loss to the outer cog line plus the spread and take profit is set to a span past the center cog line

OCPSLASOCPTP - set the stop loss to the outer cog line plus the stop loss and take profit is set to a span past the center cog line plus the take profit

FSPSLOCASOCPTP - stop loss is set to full span plus stop loss from the center cog line and take profit is set to a span past the center cog line plus the take profit

to change the scheme - just set the variable useStopLossTakeProfitScheme to 0 or 1 or 2 or 3

i have noticed a problem sometimes that the stop loss or take profit do not get set and they are zero -
in that case i have added code in the manageCurrentOrders function to check for that and set the stop loss and take profit to the variable settings
i don't know what is causing that - i only saw it once but it is worrisome -

here is testing version 18
CenterOfGravity2test18.mq4
test 123 only for tests
(23.59 KiB) Downloaded 696 times
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Wed Oct 21, 2009 7:24 am

looks like i fixed the stop loss problem and a couple other errors in the code

CenterOfGravity2test19.mq4
v.19
errors fixed from v.18
(25.63 KiB) Downloaded 740 times
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Wed Oct 21, 2009 12:23 pm

fixed some bugs and added more options :

moveTakeProfit - if set true - if trailstoploss is greater than zero then when stoploss is moved the take profit moves also
openFarthestFromCenterFirst - if set true - orders have to open at the farthest cog line before orders on the inner cog lines can open
abortMaxBalanceWinLoss - if set true - the script will abort when balance increases or decreases more than max values below
maxBalanceLoss - number of dollars
maxBalanceGain - number of dollars

also if the take profit or the stop loss is zero for any reason - the script will close all orders and abort
check the log file or the journal for print out of the reason for script abort



CenterOfGravity2test21.mq4
test test test test test
(28.23 KiB) Downloaded 715 times
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

Re: The Center of gravity MT4 Expert Advisor

Postby edlogic » Thu Oct 22, 2009 12:17 am

added some stuff - and i found out what the stop loss being zero was about
yep it was because the cog lines redrawing and i was putting the stop loss at an offset of the cog line and also using a previous cog line price and that means that the new cog line was quite a distance from the old one so sometimes the old position was not far enough beyond the current market price for a good stop loss setting

anyway here is the description for the new items and the new code

closeNonTrendingOrders - close open orders that are against the current trend
useNonTrendingOrderStrength - if set true - then the closing of non trending orders will be done if current trend is greater than the nonTrendingOrderStrength value
nonTrendingOrderStrength - this is the number which to compare to the current trend ( 555 is 55.5 pips ) for closing non trending open orders
useOpenOrderTrendStrength - if set true - then opening of orders are done if current trend is greater than openOrderOpenTrendStrength value ( oops got the word open in there too many times in that name - will fix later )
openOrderOpenTrendStrength - this is the number which to compare the current trend for opening orders
trendTimeBar - this number specifies how far to the left of the center cog line is used for the trend strength measurement
Attachments
CenterOfGravity2test24.mq4
v .24 - i think i have added enough stuff - now it is time to tweak everything
(32.16 KiB) Downloaded 749 times
http://www.fxecnbroker.com
http://www.mt4tradecopier.com
User avatar
edlogic
 
Posts: 32
Joined: Wed Oct 07, 2009 8:10 am
Location: jacksonville, florida usa

PreviousNext

Return to Forex trading strategies and systems



cron