A little help, Any idea

 

Please I am trying to replicate a feature, where if price is going up, the distance of the high to the open, is added from the low, bringing the low line upwards, but it should not be greater than the low of the day. If it should get to the low of the day, it would remain unchanged and send a notification confirm it touched the top line. The Two lines are on the start of the day, X distance above (in this case 1 ADR {Average Daily Range} and X distance below. The indicator is also suppose to show "k" historical days. I have tried a lot codes, but it is failing to track the difference in price. I did not write the code, am only suppose to modify it to add some new function. The Function of trailing price is one of these functions.

int BarStart = iBarShift(Symbol(), 0, StartTime);
   // Where UpPrice is for the creation of the top line, similarly DnPrice is for the creation of the down line
   UpPrice = NormalizeDouble(open[BarStart] + ADR * Point, _Digits);
   DnPrice = NormalizeDouble(open[BarStart] - ADR * Point, _Digits); 
            
   //--- ADRTrail is the Function for tracking price         
   if (UseADRTrail)
        {
          // Since when the Price is forming a new low or moving downwards, a new low of the day is formed and,
          // the High of the day remains unchanged
          UpPrice -= (open[BarStart] - LowValues[CurrNmbDays]);
          DnPrice += (HighValues[CurrNmbDays] - open[BarStart]);

               if(pLow == DnPrice)
                 {
                    if(UpPrice < HighValues[CurrNmbDays])
                      {
                         UpPrice = DnPrice + ADR * Point;
                         string t_message = "DnPrice: "+DoubleToStr(DnPrice, _Digits)+" (Challenged Price) Passed ";
                         MessageSend(t_message, AudioFile);
                      }
                 }
               if(pHigh == UpPrice)
                 {
                     if((DnPrice > LowValues[CurrNmbDays]))
                        {
                           DnPrice = UpPrice - ADR*Point;
                           string t_message = "UpPrice: "+DoubleToStr(UpPrice, _Digits)+" (Challenged Price) Passed ";
                           MessageSend(t_message, AudioFile);
                        }      
                 }
            pLow = DnPrice;
            pHigh = UpPrice; 
          } 

It worked well initially when the no of historical days is 0, meaning only one current day. But if the historical days is increased, the low of the previous day or the high of the previous day as a result of the CurrNmbDays iterations, thus causing the running and having to correct itself in the next loop. The values of HighValues and LowValues buffer is already stored, before getting to this point.

Thanks.

Update::

I have discovered the bug, I hope, in the initial code, a condition was added, where if no new bar(limit=0) and CurrNmbDays was less than 2, it should rerun. It is working but am still testing just to ensure.

Files:
Basic_Idea.gif  475 kb
 
Thank-god Avwerosuoghene Odukudu: the distance of the high to the open, is subtracted from the low, bringing the low line upwards,

Subtracting from the low results in a lower price.

 
William Roeder #:

Subtracting from the low results in a lower price.

My mistake, I meant add, thanks