Hey all!
So I'm rather new to coding and am trying to write an EA/Script/Indicator (whichever will do the job) to draw a vertical line on a selected chart at all points where a certain condition is met. At this point it's pretty basic i.e. draw a vertical line if the close-price of a particular bar is below the 90-candle moving average (of candle close price) AT THAT BAR. Once I get that to work, I can add more conditions and develop the indicator further. Here's what I have so far:
void OnTick()
{
datetime time = iTime(NULL,NULL,0);
if (PRICE_CLOSE < iMA(NULL,0,90,0,0,PRICE_CLOSE,0))
ObjectCreate("Line" + time,OBJ_VLINE,0,time,0,0);
}
Problem is, it starts with a bar where that condition is true, and KEEPS DOING THAT FOR ALL SUBSEQUENT BARS - EVEN IF THE 90-period moving average > close price later.
I know that the current form of the code may draw a line at all bars where the condition is true and not just the bar where the condition BECOMES true - and that's something I hope to address too (and something I need help with), but if I'm not mistaken, isn't that a separate issue from what's happening with the code above?
Also, would it be better to write a script or an EA or a CI for this?
Like I said, I'm a rookie coder so ANY help would be much appreciated.
Thanks!
So I'm rather new to coding and am trying to write an EA/Script/Indicator (whichever will do the job) to draw a vertical line on a selected chart at all points where a certain condition is met. At this point it's pretty basic i.e. draw a vertical line if the close-price of a particular bar is below the 90-candle moving average (of candle close price) AT THAT BAR. Once I get that to work, I can add more conditions and develop the indicator further. Here's what I have so far:
void OnTick()
{
datetime time = iTime(NULL,NULL,0);
if (PRICE_CLOSE < iMA(NULL,0,90,0,0,PRICE_CLOSE,0))
ObjectCreate("Line" + time,OBJ_VLINE,0,time,0,0);
}
Problem is, it starts with a bar where that condition is true, and KEEPS DOING THAT FOR ALL SUBSEQUENT BARS - EVEN IF THE 90-period moving average > close price later.
I know that the current form of the code may draw a line at all bars where the condition is true and not just the bar where the condition BECOMES true - and that's something I hope to address too (and something I need help with), but if I'm not mistaken, isn't that a separate issue from what's happening with the code above?
Also, would it be better to write a script or an EA or a CI for this?
Like I said, I'm a rookie coder so ANY help would be much appreciated.
Thanks!