Indicator drawings misplaced when applied by a template or everytime i compile my EA

 

My indicator draws price tag objects (type "arrow right price" OBJ_ARROW_RIGHT_PRICE) on specific conditions.

It works great when added to a chart, when the ndicator properties are reset, when i refresh the terminal, when i compile it, when i change period.

But it works wrong when i apply a template which includes it (despite i delete all objects before saving the template) or when i compile my expert advisor.

The error is very strange to me as the indicator creates all the correct price tags, at the correct prices, except all the tahgs are created at the most current candle's open time and can only resume its correct operation by either reappliying the indicator, refresing the terminal or compiling the indicator again.

Please advice what ami doing wrong?

Thank You.

NOTE: I edited this message to adopt forum rules and placed code and images in files attached on a reply below.

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. If prev_calculated is zero, delete your objects. Then do your computations. You don't need three separate functions. Your look back for CCI is len.
              How to do your lookbacks correctly #9 - #14 & #19

 
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. If prev_calculated is zero, delete your objects. Then do your computations. You don't need three separate functions. Your look back for CCI is len.
              How to do your lookbacks correctly #9 - #14 & #19

Hi William, thank you for your prompt answer, really appreciate it.

I'm so sorry, I will make sure next time. I do not use MQL5 nor MT5.

I do not know how to delete the post or relocate it.

 
boettigerr: I do not know how to delete the post or relocate it.

No one asked you to.

 
William Roeder:

No one asked you to.

Are you mad or that’s just the way you address to people? 
 
boettigerr:

I have moved your topic to the MQL4 and Metatrader 4 section.


 

To do that, I use these fonction, but maybe the ones you use do work :

                  ObjectCreate  (ANLB, OBJ_TEXT, 0, 0,0);
                  ObjectSet     (ANLB, OBJPROP_PRICE1, Ask ); 
                  ObjectSet     (ANLB, OBJPROP_TIME1 , Time[0]);
                  ObjectSetText (ANLB, "   B "+LOTS,10, "Arial Black", PaleGreen );
 
      ObjectCreate(SL_LINE,OBJ_HLINE,0,0,RoBott_stoploss);
      ObjectSet(SL_LINE,OBJPROP_STYLE,STYLE_SOLID);
      ObjectSet(SL_LINE,OBJPROP_COLOR,clrRed);
      ObjectSet(SL_LINE,OBJPROP_WIDTH,1);
      ObjectSetString(0,SL_LINE,OBJPROP_TEXT,"Stop_Loss");
      ObjectSet(SL_LINE,OBJPROP_SELECTED,true);//

 The object created is a "SL_LINE",and :

OBJ_HLINE

It do not fit with this one:

  ObjectSetString(0,SL_LINE,OBJPROP_TEXT,"Stop_Loss");

You have to create another object, for the text

 
ffoorr:

 The object created is a "SL_LINE",and :

It do not fit with this one:

You have to create another object, for the text

Hi ffoorr,

Thx for replying. I used your code but the problem with the indicator remains. Two things happen: 1) When i apply my indicator to my 30 charts as part of a template and 2) When i compile my EA (which is very frecuently). Seems to be that the Time[index] function is not initiated (defaults to current time) when, as my good friend William mentioned, prev_calculated == 0.

I managed to make the calculations for the history candles only after prev_calculated != 0 (after first tick is received), and that solves the problem 1), but does not solve problem 2), when i compile my EA (i do not know why compiling the EA affects the indicator on the chart).