need help to create a simple rule for ea

 

if there any function to check when a MA or indicator is turning down or up ? my rule is very simple

  • buy when 50 MA is turn up
  • sell when 50 MA is turn down
 
dotzoo wrote >>

if there any function to check when a MA or indicator is turning down or up ? my rule is very simple

  • buy when 50 MA is turn up
  • sell when 50 MA is turn down

I don't think there is a function to check that on ma's. You need another shorter time ma to compare with the main ma to determine it's direction. If the shorter time ma is below the main ma then it is headed down and vice versa.

 
mqldelta wrote >>

I don't think there is a function to check that on ma's. You need another shorter time ma to compare with the main ma to determine it's direction. If the shorter time ma is below the main ma then it is headed down and vice versa.

can you give me an example for that, and the following is what i try according to what you said, I dont really understand the ma_shift but i believe it is like caculate the last candel for whatever indicator you applying and 0 for current candel ?

// using ma_shift to get the shorter time ma

int shortma = ima(symbol(), timeperiod_h1, 20,-1,50,mode_sma,price_open,0)
int longma = ima(symbol(), timeperiod_h1, 20, 0, 50, mode_sma, price_open, 0)

if (shortma <= longma)
//buy rules
if (shortma >= longma)
//sell rules
 
dotzoo wrote >>

can you give me an example for that, and the following is what i try according to what you said, I dont really understand the ma_shift but i believe it is like caculate the last candel for whatever indicator you applying and 0 for current candel ?

Sorry I should have said shorter period ma.. not shorter time. You would compare the shorter period ma with the longer period ma to determine the direction of the longer ma. However basing trading decisions on ma crosses doen't yeild profitable results on backtesting. Mt4 comes with example EA's. None of them including the moving average one works. They all result in losses.

 
mqldelta:

Sorry I should have said shorter period ma.. not shorter time. You would compare the shorter period ma with the longer period ma to determine the direction of the longer ma. However basing trading decisions on ma crosses doen't yeild profitable results on backtesting. Mt4 comes with example EA's. None of them including the moving average one works. They all result in losses.

Hi,


If I understand correctly you wish to identify the turning point of the MA.

I would write it with two comparison each time; smoething like this :


for a MA increasing and then decreasing, where I suppose you would place an order sell, I would try :


if (

(iMA(NULL,0,MovingPeriod,movingshift,MODE_SMA,PRICE_OPEN,2)
<iMA(NULL,0,MovingPeriod,movingshift,MODE_SMA,PRICE_OPEN,1))
||

(iMA(NULL,0,MovingPeriod,movingshift,MODE_SMA,PRICE_OPEN,1)

>iMA(NULL,0,MovingPeriod,movingshift,MODE_SMA,PRICE_OPEN,0))

)

place order sell


and opposite for buy


This way, you compare the previous and the current MA


Hope this help


Lionel

 
dotzoo:

if there any function to check when a MA or indicator is turning down or up ? my rule is very simple

  • buy when 50 MA is turn up
  • sell when 50 MA is turn down

I'd go with something like what Lionel said... and if you want to check the reversal, use your MA 50 with shifts of 1,2,3:

double MA1 = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,1);

double MA2 = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,2);

double MA3 = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,3);


Buy Position:

if (MA1 > MA2 && MA2 <= MA3)

Now, you know it's going up (MA1>MA2) and before that it was going down, or flat (MA2<=MA3)


Reverse to open sell positions.

See if that's about what you are looking for.

 
paranoidtruth wrote >>

I'd go with something like what Lionel said... and if you want to check the reversal, use your MA 50 with shifts of 1,2,3:

double MA1 = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,1);

double MA2 = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,2);

double MA3 = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,3);

Buy Position:

if (MA1 > MA2 && MA2 <= MA3)

Now, you know it's going up (MA1>MA2) and before that it was going down, or flat (MA2<=MA3)

Reverse to open sell positions.

See if that's about what you are looking for.

isnt if i shift to the right that mean predicting the feature price and use it to compare ? so i suppose shift to the left (example : current bar is 0, last bar is -1, feature bar is unknow (+1)) predicting the feature may get great profit in simulation but in real is a loss system, that is what i read in wealth-lab

 
dotzoo:

isnt if i shift to the right that mean predicting the feature price and use it to compare ? so i suppose shift to the left (example : current bar is 0, last bar is -1, feature bar is unknow (+1)) predicting the feature may get great profit in simulation but in real is a loss system, that is what i read in wealth-lab


Your supposition is logic but unfortunatly wrong according to MQL language...


0 = current bar or indicator

1 = previous

-1 = could be future but I never succeed to use it in my EAs


I agree it's not the instinctive way of seeing things but it's the way it works.


lionel

 
leyoye1 wrote >>

-1 = could be future but I never succeed to use it in my EAs

I had a trader say to me..

"Why dont you just program it to only make winning trades?"

LOL!

This was a guy making a living out of winning 45-48% of the time and wanted his system automating!!


-BB-

Reason: