Request for help on how to get the end of a trendline moved to a specific bar

 

Hello everyone,

I wrote the code below that, in my mind, should move the endpoint of the trend line to the high of the highest bar, or the low of the lowest bar, but it doesn't.

The end of the trend line is moved to the correct level, but not to the right bar, instead it is moved to the most recent bar. How do I get it to be moved to the bar corresponding with the highest high or lowest low?

      if(ObjectType(TrendName)==OBJ_TREND)
     {
      WaveStartP     = ObjectGet(TrendName,OBJPROP_PRICE1);
      WaveStart_Bar  = iBarShift(NULL,0,WaveStartT,false);
      WaveLength     = WaveStart_Bar;

      double LL_Wave        = Low[iLowest(NULL, 0, MODE_LOW,WaveLength, i)];//get the price of the lowest point between T1 and the current bar
      double HH_Wave        = High[iHighest(NULL, 0, MODE_HIGH,WaveLength, i)];//get the price of the lowest point between T1 and the current bar
      datetime TimeLL_Wave  = Time[iLowest(NULL, 0, MODE_TIME,WaveLength, i)];
      datetime TimeHH_Wave  = Time[iHighest(NULL, 0, MODE_TIME,WaveLength, i)];
      
      if (Long) {ObjectMove(TrendName,1,TimeHH_Wave, HH_Wave);} else {ObjectMove(TrendName,1,TimeLL_Wave, LL_Wave);}
      
     }
 
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. The highest time will always be now. The lowest time will always be then.
    int iLL = iLowest(NULL, 0, MODE_LOW,WaveLength, i);
    int iHH = iHighest(NULL, 0, MODE_HIGH,WaveLength, i)
    double LL        = Low[iLL];
    double HH        = High[iHH];
    //    datetime TimeLL  = Time[iLowest(NULL, 0, MODE_TIME,WaveLength, i)];
    //    datetime TimeHH  = Time[iHighest(NULL, 0, MODE_TIME,WaveLength, i)];
          datetime TimeLL  = Time[iLL];
          datetime TimeHH  = Time[iHH];
 

Thanks for your response whroeder1, much appreciated, have a nice day.


reacto

Reason: