String als variable

 

Can anyone help me to code this code correctly?

I need a string variable and still don't quite understand how to do it.

...

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

...

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Michael Musin:

Can anyone help me to code this code correctly?

I need a string variable and still don't quite understand how to do it.


Post your code properly please. Use the code button, edit your post, do not repost.
 
void OnTick()
  {
   for(int i = 0; i <= 5; i++)
   {
      double high = iHigh(_Symbol,PERIOD_D1,i);
      double low = iLow(_Symbol,PERIOD_D1,i);
      string name_high = "high" + i;
      string name_low = "low" + i;
      
      ObjectDelete(ChartID(),name_high);
      ObjectDelete(ChartID(),name_low);
      ObjectCreate(ChartID(), name_high, OBJ_HLINE ,0,0, high);
      ObjectCreate(ChartID(), name_low, OBJ_HLINE,0,0, low);
   }

}   
 
Yashar Seyyedin #:
"Do not repost" .... But you did.

Anyways:

      string name_high = StringFormat("high_%i", i);
You should not use a loop counter to create object names.

It be better to use time for that, they would be unique.

      string name_high = StringFormat( "high_%llu", iTime(...));
 
Michael Musin:

Can anyone help me to code this code correctly?

I need a string variable and still don't quite understand how to do it.

What are you trying to achieve ? 

If you want each line to be unique and not only care about the most recent 5 bars then do the naming with Time as Dominik suggested.

Otherwise you don't need to update all of them on each tick (i assume its on tick) , just update the live one and if a new bar forms redesign them.