Getting custom gridline indicator to attach - page 2

 
Nagisa Unada # :

I have tried debugging the loop from start to finish and nothing happens.

I can't figure out what the bug is.

Please show a video where you can use debugging.

 
Vladimir Karputov #:

Please show a video where you can use debugging.

I couldn't upload it here due to file size, so I sent it via messenger.

 
Nagisa Unada # :

I couldn't upload it here due to file size, so I sent it via messenger.

Okay. Now study the MathMod documentation and correct your mistake - make sure that the cursor gets inside the loop:

         obj_name = "Grid_" + IntegerToString(i);
         if(ObjectFind(0, obj_name) < 0)
           {
            price = (double)i / (double)Divisor;
            ObjectCreate(0, obj_name, OBJ_HLINE, 0, time[1], price);
            ObjectSetInteger(0, obj_name, OBJPROP_STYLE, Line_Style);
            ObjectSetInteger(0, obj_name, OBJPROP_WIDTH, Line_Width);
            ObjectSetInteger(0, obj_name, OBJPROP_COLOR, Line_Color);
            ObjectSetInteger(0, obj_name, OBJPROP_BACK,  true);
            ObjectSetString(0,  obj_name, OBJPROP_TEXT, DoubleToString(price, Digits() - 2));
           }
Documentation on MQL5: Math Functions / MathMod
Documentation on MQL5: Math Functions / MathMod
  • www.mql5.com
MathMod - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Now the next problem:

you need to prevent the constant re-creation of graphical objects.

 
 ChartRedraw ();

do not need to use - when a new tick arrives, the terminal itself redraws the chart and all graphical objects.

 

Recommendation: change the time

time[1]

on the

time[rates_total-1]
 
Vladimir Karputov #:

Now the next problem:

you need to prevent the constant re-creation of graphical objects.

If an already existing object is found by "ObjectFind", it will not be regenerated.

Vladimir Karputov #:

do not need to use - when a new tick arrives, the terminal itself redraws the chart and all graphical objects.

Indeed it is.

Vladimir Karputov #:

Recommendation: change the time

on the

//ArraySetAsSeries(close, true);
close[rates_total-2]

Since it is the second bar from the last, it is -2.

I changed the MT4 code and unintentionally did so, and you are correct.


 
Nagisa Unada # :

If an already existing object is found by "ObjectFind", it will not be regenerated.

Indeed it is.

Since it is the second bar from the last, it is -2.

I changed the MT4 code and unintentionally did so, and you are correct.


Now the code is working. Are there any other problems?

 
Vladimir Karputov #:

Now the code is working. Are there any other problems?

Nothing in particular. Thank you.

Reason: