@Townsend @RobertPayne made some progress on the script but there's something off with my aggregation of bars leading to some oddities. Was wondering if you guys could provide some feedback. You can see with the alternating cyan/red lines on the lower study my calculated bars of a day are larger than the actual bar for the day
I know the issue lies here but not sure how to fix (Full Code Below):
FULL CODE:
I know the issue lies here but not sure how to fix (Full Code Below):
Code:
def lowerPeriod = GetAggregationPeriod();
def numberOfLowerInHigher = agg/lowerPeriod;
def counter = counter[1] +1;
def pSwitch = if counter % numberOfLowerInHigher == 0 then if pSwitch[1] == 1 then 0 else 1 else pSwitch[1];
def per1 = if pSwitch == 0 then 1 else double.nan;
def per2 = if pSwitch == 1 then 1 else double.nan;
def per3 = if counter % numberOfLowerInHigher == RoundDown(numberOfLowerInHigher/2,0) then barnumber() else double.nan;
AddCloud( if (per1, c, double.nan), if (per1, o, double.nan), Color.Green, Color.Red);
AddCloud( if (per2, c, double.nan), if (per2, o, double.nan), Color.Green, Color.Red);
# end
FULL CODE:
Code:
# Multi-Time-Frame Candle Overlay version 2.4
# 2020 Paul Townsend modified by User1m
# with code from UseThinkScript.com
input agg = AggregationPeriod.DAY;
input OpenCloseLines = yes;
input HighLowLines = yes;
input HighLowGray = no;
input LineWeight =2;
addlabel(yes,"[" + agg/60000 + "]",color.white);
plot o = open(period = agg);
plot c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
o.sethiding(!OpenCloseLines);
c.sethiding(!OpenCloseLines);
o.setLineWeight(lineweight);
c.setLineWeight(lineweight);
o.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
c.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
def lowerPeriod = GetAggregationPeriod();
def numberOfLowerInHigher = agg/lowerPeriod;
def counter = counter[1] +1;
def pSwitch = if counter % numberOfLowerInHigher == 0 then if pSwitch[1] == 1 then 0 else 1 else pSwitch[1];
def per1 = if pSwitch == 0 then 1 else double.nan;
def per2 = if pSwitch == 1 then 1 else double.nan;
def per3 = if counter % numberOfLowerInHigher == RoundDown(numberOfLowerInHigher/2,0) then barnumber() else double.nan;
AddCloud( if (per1, c, double.nan), if (per1, o, double.nan), Color.Green, Color.Red);
AddCloud( if (per2, c, double.nan), if (per2, o, double.nan), Color.Green, Color.Red);
o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
c.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot pH = if per3 then h else double.nan;
plot pL = if per3 then l else double.nan;
pH.SetPaintingStrategy(PaintingStrategy.POINTS);
pL.SetPaintingStrategy(PaintingStrategy.POINTS);
pH.sethiding(!HighLowLines);
pL.sethiding(!HighLowLines);
pH.setLineWeight(lineweight);
pL.setLineWeight(lineweight);
pH.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);
pL.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);
def hb = if per3 then h else double.nan;
def lb = if per3 then l else double.nan;
AddChart(high = hb, low = lb, open = double.nan, close = double.nan, type = ChartType.bar, growcolor = color.white);
# end
Last edited: