Newly Populated Candles - broke a past Swing High/Low?

 

I'm drawing trendlines on my swings. When a high or low is broken, I want to delete old trendlines (sometimes more than one).

This is simple to do when the chart is live, open and active.

What I am trying to solve is when the trading platform has been shut down for a while. Once the platform is re-opened, the chart will update, and new candles are populated.

The current high may not be higher than the high I drew a trendline on, but somewhere in-between the current candle and the last data prior to shutting down, there can be a swing high or low that broke one of these.

I've attempted to build a solution, but I believe its wrong and there must be an easier way to find the iHighest /iLowest value from current live candle back to the one(s) the trendlines were drawn upon.

What I did was get the 1 hour time of the trendline candle and the 1 hour time of current candle, subtract the difference and then divide by 3600 to give me the amount of candles that have passed, and set my iHighest and iLowest value to that number. Sundays and Holidays keep this from working correctly. Any suggestions - where to look, or what I might try doing instead?

Thanks in advance!

 
JPS:

I'm drawing trendlines on my swings. When a high or low is broken, I want to delete old trendlines (sometimes more than one).

This is simple to do when the chart is live, open and active.

What I am trying to solve is when the trading platform has been shut down for a while. Once the platform is re-opened, the chart will update, and new candles are populated.

The current high may not be higher than the high I drew a trendline on, but somewhere in-between the current candle and the last data prior to shutting down, there can be a swing high or low that broke one of these.

I've attempted to build a solution, but I believe its wrong and there must be an easier way to find the iHighest /iLowest value from current live candle back to the one(s) the trendlines were drawn upon.

What I did was get the 1 hour time of the trendline candle and the 1 hour time of current candle, subtract the difference and then divide by 3600 to give me the amount of candles that have passed, and set my iHighest and iLowest value to that number. Sundays and Holidays keep this from working correctly. Any suggestions - where to look, or what I might try doing instead?

Use iBarShift() with  the 1 hour time of the trendline candle   and   the 1 hour time of current candle  to give you the correct bar numbers,  then use these with your iHighest() and iLowwest() calls.
 
I'll give that a try. Thanks for the input !
 
 for(int s=ObjectsTotal()-1;s>=0;s--)
   if(StringFind(ObjectName(s),"pivotL",0)>=0)
      {returnednameL = StringSubstr(ObjectName(s),6,0);
        PLshift=iBarShift(Symbol(),PERIOD_H1,StrToInteger(returnednameL));

// Above I have stripped the time of that one hour candle which was stored in the trendline's description.
// It is then passed onto returnednameL
// iBarShift then uses that time value under PLshift which is then added below 


        }
 

        GetPLHighest = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,PLshift,0)];
        GetPLLowest = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,PLshift,0)]; 


// Above I have added the same PLShift to iHighest and iLowest

GetPLHighest (which is iHighest) returns the CORRECT High.

GetPlLowest (which is iLowest) returns the Low ONE candle forward of what it should be (no, this is not the rounding of extra price digit).

Any idea why? They are both using same iBarShift value.  

Thank you.

 
JPS:

GetPLHighest (which is iHighest) returns the CORRECT High.

GetPlLowest (which is iLowest) returns the Low ONE candle forward of what it should be (no, this is not the rounding of extra price digit).

Any idea why? They are both using same iBarShift value.  

Thank you.

Don't forget that the last but one parameter in iHighest() and iLowest()   is the count of bars to check,  if you start at 0 and want to include bar number 5 then you want to check,  0,1,2,3,4,5  which is a count of 6,  perhaps you need to use  PLshift + 1  not PLshift ?
 
  1. Count is always Left - Right + 1, so if Left=5 and Right=0 Count=6

    This is why I recommend always write self documenting code, and not combining calls, and not writing things more than once.

    GetPLHighest = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,PLshift,0)];
    int left   = PLshift,
        right  = 0,
        length = left - right + 1,
        iHigh  = iHighest(NULL,PERIOD_H1,MODE_HIGH,length,right);
    GetPLHighest = High[iHigh];
    double HighestH1(int left, int right = 0){
       int length = left - right + 1,
           iHigh  = iHighest(NULL,PERIOD_H1, MODE_HIGH, length, right);
       return(High[iHigh]);
    }
    ///////////////////////////////////////////////////////////////////
    GetPLHighest = HighestH1(PLshift);
    int iGetExtremaH1(int length, int direction, int iStart = 0, int eMode=EMPTY){
       if(direction > 0){
           if(eMode == EMPTY) eMode = MODE_HIGH;
           return(iHighest(NULL,PERIOD_H1, eMode, length, iStart));
       }
       if(eMode == EMPTY) eMode = MODE_LOW;
       return(iLowest(NULL,PERIOD_H1, eMode, length, iStart));
    }
    double GetExtremaH1(int length, int direction, int iStart = 0, int eMode=EMPTY){
       int iE = iGetExtremaH1(length, direction, iStart, eMode);
       if(direction > 0) return(High[iE]);
       return(Low[iE]);
    }
    ///////////////////////////////////////////////////////////////////
    GetPLHighest = GetExtremaH1(PLshift, +1);
    GetPLLowest  = GetExtremaH1(PLshift, -1);

  2. Also Get is a verb, so that could be appropriate for function names. Variables don't get anything, they don't do anything, they are a thing. Use nouns.
  3. PLHighest = GetExtremaH1(PLshift, +1);
    PLLowest  = GetExtremaH1(PLshift, -1);

  4. Likewise
    returnednameL = StringSubstr(ObjectName(s),6,0);
    If I asked you what the color of the sky, would you say "the Returned Color Name is blue?" no, you'd say "the sky is blue." Thus:
     if(StringFind(ObjectName(s),"pivotL",0)>=0)
       {pivotDT = StringSubstr(ObjectName(s),6,0);
 

Thanks Raptor. I added +1 last night thinking this was me using a work around, though not correct to do. Now I see this is okay. Thank you for helping.

WHRoeder, I use what makes sense to me, but I also see your point. Thank you.  

Reason: