Download MetaTrader 5

As long as PARA SAR dots are below price...

To add comments, please log in or register
The entire history on a single page!
windowshopr 2015.03.23 01:59 

Hey guys,

Hoping to get some help to code a close condition.

Just making my own moving average crossover EA. My first close condition says if 5 EMA crosses 21 EMA, but now I want to add another condition, so I have an "OR" condition. Now what I want is the EA to count how many SAR dots are formed since the orders opening. If it's a buy order, if there are 10 dots in a row below the prices, then once the current price touches the previous SAR dot, close the order. Vice Versa for sell. Basic logic would look something like:

// Close Buy Rules

if( 5 EMA[1] > 21 EMA[1] && 5 EMA[0] < 21 EMA[0] )


(wait for 10 SAR dots to form below the prices, then after the 10th dot from orderopen, if close[0] < SAR[0])




I'm wondering if a "FOR" loop would be used here, and I'm hoping so as I have never used one before. It should basically look back after the 10th formed dot (or 10th bar I guess), and if they are all below the prices, there are 10 consecutive "BUY" dots formed, then once the current SAR changes direction, close the order. The standard 0.02 0.2 SAR can be used. Any ideas? Thanks a lot, 

To add comments, please log in or register