object name (string) + suffix (int) = trouble == SOLVED

 
string trend0 = StringConcatenate("trend0",_iTimeW1ST);
string trend1 = StringConcatenate("trend1",_iTimeW1ST);
string trend2 = StringConcatenate("trend2",_iTimeW1ST);

ObjectCreate(0,trend0,OBJ_TREND,0,_iTimeW1ST,step0,endTime,step0);
ObjectCreate(0,trend1,OBJ_TREND,0,_iTimeW1ST,step1,endTime,step1);
ObjectCreate(0,trend2,OBJ_TREND,0,_iTimeW1ST,step2,endTime,step2);

ObjectSetInteger(0,trend0, OBJPROP_COLOR, Green);
ObjectSetInteger(0,trend1, OBJPROP_COLOR, Green);
ObjectSetInteger(0,trend2, OBJPROP_COLOR, Green)

Hello, i've searched a lot but i was not able to figure out how to make cycle to manage object with numeric suffix (trend0 .... trend100, step0 ... step100).

Can someone help me with this in mql4 please?

I am sorry moderators i placed this in general topic instead to MQL4 by mistake.

 
Eplain what you mean by "make cycle to manage"
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem
 
William Roeder #:
Eplain what you mean by "make cycle to manage"
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

Sure, the idea is this (cycle to avoid writing 100 rows):

for(int i=0;i<100;i++)  {
         string trend[i] = StringConcatenate("trend[i]",_iTimeW1ST);
         ObjectCreate(0,trend[i],OBJ_TREND,0,_iTimeW1ST,step[i],endTime,step[i]);
         ObjectSetInteger(0,trend[i], OBJPROP_COLOR, Green)
     }
 
vilem.iv #:

Sure, the idea is this (cycle to avoid writing 100 rows):

This?

for(int i=0; i<100; i++)  {
  string trend = StringFormat("trend[%i]", i);
  ObjectCreate(0, trend, OBJ_TREND, 0, _iTimeW1ST, step[i], endTime, step[i]);
  ObjectSetInteger(0, trend, OBJPROP_COLOR, Green);
}
 
Alexandre Borela #:

This?

Thanks, however it doesn't work even the
OBJPROP_COLOR
does not work with
StringFormat("trend%i",i);
and ObjectSetInteger as object name. And how to use variable containing double value step1, step2, step3 .... step100 please?
double step[i];
 
vilem.iv #:
Thanks, it looks like 1/2 problem solved, remain how to use variable containing double value step1, step2, step3 .... step100:

Declare the array somewhere:

double step[100];

// Do the calculation of the steps, I don't know how you are doing it since
// you didn't show the full algorithm.

for(int i=0; i<100; i++)  {
  string trend = StringFormat("trend[%i]", i);
  ObjectCreate(0, trend, OBJ_TREND, 0, _iTimeW1ST, step[i], endTime, step[i]);
  ObjectSetInteger(0, trend, OBJPROP_COLOR, Green);
}

https://www.mql5.com/en/docs/basis/variables#array_define

Documentation on MQL5: Language Basics / Variables
Documentation on MQL5: Language Basics / Variables
  • www.mql5.com
Variables - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
vilem.iv #:
Thanks, however it doesn't work even the does not work with and ObjectSetInteger as object name. And how to use variable containing double value step1, step2, step3 .... step100 please?
Show the full code.
 
Alexandre Borela #:
Show the full code.
void drawEntries() {
        double _iHighestW1 = iHighest(  Symbol(), PERIOD_D1, MODE_HIGH, WHOLE_ARRAY, 0 );
        double _iHighW1 = iHigh(  Symbol(), PERIOD_D1, _iHighestW1 );
        double _iTimeW1ST = iTime(  Symbol(), PERIOD_D1, _iHighestW1 );
        

   double step1 = (_iHighW1/2);
   double step2 = (_iHighW1/2.5);
   double step3 = (_iHighW1/3);
   double step4 = (_iHighW1/3.5);
   double step5 = (_iHighW1/4);
   double step6 = (_iHighW1/4.5);
   double step7 = (_iHighW1/5);
   double step8 = (_iHighW1/5.5);
   double step9 = (_iHighW1/6);
  
        
        datetime endTime = Time[0];
        bool fillRec = True;
        int borWid = 2;
        
        
   string trend1 = StringConcatenate("trend1",_iTimeW1ST);
   string trend2 = StringConcatenate("trend2",_iTimeW1ST);
   string trend3 = StringConcatenate("trend3",_iTimeW1ST);
   string trend4 = StringConcatenate("trend4",_iTimeW1ST);
   string trend5 = StringConcatenate("trend5",_iTimeW1ST);
   string trend6 = StringConcatenate("trend6",_iTimeW1ST);
   string trend7 = StringConcatenate("trend7",_iTimeW1ST);
   string trend8 = StringConcatenate("trend8",_iTimeW1ST);
   string trend9 = StringConcatenate("trend9",_iTimeW1ST);   
   
  
   ObjectCreate(0,trend1,OBJ_TREND,0,_iTimeW1ST,step1,endTime,step1);
   ObjectCreate(0,trend2,OBJ_TREND,0,_iTimeW1ST,step2,endTime,step2);
   ObjectCreate(0,trend3,OBJ_TREND,0,_iTimeW1ST,step3,endTime,step3);
   ObjectCreate(0,trend4,OBJ_TREND,0,_iTimeW1ST,step4,endTime,step4);
   ObjectCreate(0,trend5,OBJ_TREND,0,_iTimeW1ST,step5,endTime,step5);
   ObjectCreate(0,trend6,OBJ_TREND,0,_iTimeW1ST,step6,endTime,step6);
   ObjectCreate(0,trend7,OBJ_TREND,0,_iTimeW1ST,step7,endTime,step7);
   ObjectCreate(0,trend8,OBJ_TREND,0,_iTimeW1ST,step8,endTime,step8);
   ObjectCreate(0,trend9,OBJ_TREND,0,_iTimeW1ST,step9,endTime,step9);
  

   ObjectSetInteger(0,trend1, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend2, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend3, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend4, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend5, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend6, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend7, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend8, OBJPROP_COLOR, Green);
   ObjectSetInteger(0,trend9, OBJPROP_COLOR, Green);
   
   
   for(int i=1; i<10; i++)  {
      string trend = StringFormat("trend%i", i);
      Print(trend);
      ObjectSetInteger(0, trend, OBJPROP_COLOR, Green);
   }

        
   ObjectSetInteger(0,trend1, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend2, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend3, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend4, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend5, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend6, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend7, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend8, OBJPROP_WIDTH, borWid);
   ObjectSetInteger(0,trend9, OBJPROP_WIDTH, borWid);
   
   ObjectSetInteger(0,trend1, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend2, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend3, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend4, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend5, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend6, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend7, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend8, OBJPROP_RAY, false);
   ObjectSetInteger(0,trend9, OBJPROP_RAY, false);
   
   ObjectMove(0,trend1,0,_iTimeW1ST,step1);
   ObjectMove(0,trend2,0,_iTimeW1ST,step2);
   ObjectMove(0,trend3,0,_iTimeW1ST,step3);
   ObjectMove(0,trend4,0,_iTimeW1ST,step4);
   ObjectMove(0,trend5,0,_iTimeW1ST,step5);
   ObjectMove(0,trend6,0,_iTimeW1ST,step6);
   ObjectMove(0,trend7,0,_iTimeW1ST,step7);
   ObjectMove(0,trend8,0,_iTimeW1ST,step8);
   ObjectMove(0,trend9,0,_iTimeW1ST,step9);
   
   ObjectMove(0,trend1,1,endTime,step1);
   ObjectMove(0,trend2,1,endTime,step2);
   ObjectMove(0,trend3,1,endTime,step3);
   ObjectMove(0,trend4,1,endTime,step4);
   ObjectMove(0,trend5,1,endTime,step5);
   ObjectMove(0,trend6,1,endTime,step6);
   ObjectMove(0,trend7,1,endTime,step7);
   ObjectMove(0,trend8,1,endTime,step8);
   ObjectMove(0,trend9,1,endTime,step9);
  return 0;
  }
 
vilem.iv #:
void drawEntries() {
  double _iHighestW1 = iHighest(  Symbol(), PERIOD_D1, MODE_HIGH, WHOLE_ARRAY, 0);
  double _iHighW1 = iHigh(  Symbol(), PERIOD_D1, _iHighestW1);
  double _iTimeW1ST = iTime(  Symbol(), PERIOD_D1, _iHighestW1);
        
  datetime endTime = Time[0];
  bool fillRec = True;
  int borWid = 2;

  for (int i = 0; i < 9; ++i) {
    double step = _iHighW1 / (2 + 0.5 * i);
    string name = StringFormat("trend%i", i);

    ObjectCreate(0, name, OBJ_TREND, 0, _iTimeW1ST, step, endTime, step);
    ObjectSetInteger(0, name, OBJPROP_COLOR, clrGreen);
    ObjectSetInteger(0, name, OBJPROP_WIDTH, borWid);
    ObjectSetInteger(0, name, OBJPROP_RAY, false);
    ObjectMove(0, name, 0, _iTimeW1ST, step);
    ObjectMove(0, name, 1, endTime, step);
  }
}
 
Alexandre Borela #:
Thank You Mr. Borela! You solved my very big pain in my head.
Reason: