Trouble with delayed events when coding strategy

 

Hello, I was wondering if anyone could help me with a problem I've been having 


I have pretty much my entire indicator coded, however I'm trying to get it to draw buy/sell arrows based on my strategy so I can hook it up to an EA

Basically I'm saying "if this line touches price then becomes disconnected, then my SMA turns green, place an arrow"


What I originally thought would work is:

int x = 0;

if (line==price)

{

x = 1;

}

if(x==1 && line != price)

{

x =2;

}

if (x==2 && MA==green)

{

place arrow;

x = 0;

}




what's happening is im getting that x = 1, but when the indicator recalculates on every tick its resetting x to 0 due to that original int x = 0;


my question is is there any way to store that event of the line touching (im thinking maybe an array?), so then i can say "it touched, now its not touching, now MA is green, so place arrow".


Thanks in advance

 

Put this declaration:

int x = 0;

Outside of the OnCalculate() function if you dont want it to be set to zero every time in the loop.

Reason: