I am not sure why I struggle with this so much, but I can never get it to work. I am trying to add a higher time frame to this code, so that if I am looking at 30min candles, I will be able to plot when the pivot has reached its high/low points for the hourly candle(for example).
input swing_back = 8;
input swing_forward = 2;
input maxbars = 30;
input showlevels = Yes;
def sb = swing_back;
def sf = swing_forward;
def na = Double.NaN;
def lfor = Lowest(low, sf)[-sf];
def lback = Lowest(low, sb)[1];
def swinglow = if low < lfor and low <= lback then 1 else 0;
plot sl = if swinglow then low else na;
def hfor = Highest(high, sf)[-sf];
def hback = Highest(high, sb)[1];
def swinghigh = if high > hfor and high >= hback then 1 else 0;
plot sh = if swinghigh then high else na;
sh.SetStyle(Curve.POINTS);
sh.SetLineWeight(5);
sh.SetDefaultColor(Color.WHITE);
sl.SetStyle(Curve.POINTS);
sl.SetLineWeight(5);
sl.SetDefaultColor(Color.WHITE);
rec lsl = if IsNaN(close[-sf]) then lsl[1] else if swinglow then low else lsl[1];
rec lsh = if IsNaN(close[-sf]) then lsh[1] else if swinghigh then high else lsh[1];
def bn = BarNumber();
rec hcount = if swinghigh then 1 else hcount[1] + 1;
rec lcount = if swinglow then 1 else lcount[1] + 1;
plot lasthigh = if hcount <= maxbars and IsNaN(close[-sf]) then lsh[1] else if hcount > maxbars then na else if hcount < 2 then na else lsh;
plot lastlow = if lcount <= maxbars and IsNaN(close[-sf]) then lsl[1] else if lcount > maxbars then na else if lcount < 2 then na else lsl;
lasthigh.SetStyle(Curve.SHORT_DASH);
lasthigh.SetDefaultColor(Color.WHITE);
lasthigh.SetHiding(!showlevels);
lastlow.SetStyle(Curve.SHORT_DASH);
lastlow.SetDefaultColor(Color.WHITE);
lastlow.SetHiding(!showlevels);
I am adding:
input agg = AggregationPeriod.HOUR;
But that doesnt seem to be working from what I can tell. Any assistance would be greatly appreciated
input swing_back = 8;
input swing_forward = 2;
input maxbars = 30;
input showlevels = Yes;
def sb = swing_back;
def sf = swing_forward;
def na = Double.NaN;
def lfor = Lowest(low, sf)[-sf];
def lback = Lowest(low, sb)[1];
def swinglow = if low < lfor and low <= lback then 1 else 0;
plot sl = if swinglow then low else na;
def hfor = Highest(high, sf)[-sf];
def hback = Highest(high, sb)[1];
def swinghigh = if high > hfor and high >= hback then 1 else 0;
plot sh = if swinghigh then high else na;
sh.SetStyle(Curve.POINTS);
sh.SetLineWeight(5);
sh.SetDefaultColor(Color.WHITE);
sl.SetStyle(Curve.POINTS);
sl.SetLineWeight(5);
sl.SetDefaultColor(Color.WHITE);
rec lsl = if IsNaN(close[-sf]) then lsl[1] else if swinglow then low else lsl[1];
rec lsh = if IsNaN(close[-sf]) then lsh[1] else if swinghigh then high else lsh[1];
def bn = BarNumber();
rec hcount = if swinghigh then 1 else hcount[1] + 1;
rec lcount = if swinglow then 1 else lcount[1] + 1;
plot lasthigh = if hcount <= maxbars and IsNaN(close[-sf]) then lsh[1] else if hcount > maxbars then na else if hcount < 2 then na else lsh;
plot lastlow = if lcount <= maxbars and IsNaN(close[-sf]) then lsl[1] else if lcount > maxbars then na else if lcount < 2 then na else lsl;
lasthigh.SetStyle(Curve.SHORT_DASH);
lasthigh.SetDefaultColor(Color.WHITE);
lasthigh.SetHiding(!showlevels);
lastlow.SetStyle(Curve.SHORT_DASH);
lastlow.SetDefaultColor(Color.WHITE);
lastlow.SetHiding(!showlevels);
I am adding:
input agg = AggregationPeriod.HOUR;
But that doesnt seem to be working from what I can tell. Any assistance would be greatly appreciated
Last edited by a moderator: