First Bar

 

Is there way to find if it's a first bar above/below the MA (first bar's open above/below the MA)?

Thanks

Example

 

if (MA(x) < 0)

if (MA(x) > 0)

 

Let's say when i started EA price is on bar 3 (i don't want to open an order on bar 3) first i want to check if it's bar 1 and then open an order...

 
R_Jang:

Let's say when i started EA price is on bar 3 (i don't want to open an order on bar 3) first i want to check if it's bar 1 and then open an order...

Try something like...

calc two variables using shift 0 & 1 to get the current mva value [0], and the prev mva value [1].


if Open[0] > yourmva_current && Open[1] <= yourmva_prev

then it's the first bar above.


if Open[0] < yourmva_current && Open[1] >= yourmva_prev

it's the first bar below your mva.

Reason: