Hi I am trying to draw the range of each candle to quickly see the risk unit plotted. For that I added as an indicator the ATR of a single candle that is the range of that candle that serves me, but when plotting the first candle takes for the calculation of the previous day's close, so the value is very large and subsequent values is difficult to visualize. Do you know how to do so that the first candle only calculates it as first bar close - first bar open? I tried to solve it and I put a coding of another query but it does not work:
Here I paste the picture of how that first wrong atr looks like
Code:
input Reset_Time = 0930;
input Length = 1;
input Consecutive_Closes_Above = 1;
input Consecutive_Closes_Below = 1;
def EOD = SecondsTillTime(1800) == 0;
def GB = close > open;
def RB = close < open;
def Doji = close == open;
def Reset = SecondsFromTime(Reset_Time) == 0;
def ResetBN = if Reset then BarNumber() else ResetBN[1];
def Highest_Lowest_TimeFrame = BarNumber() >= ResetBN + Length;
def fH = if GetValue(Reset, Length - 1) == 1 then Highest(high, Length) else fH[1];
def fL = if GetValue(Reset, Length - 1) == 1 then Lowest(low, Length) else fL[1];
def sH = if Reset then fH[-Length + 1] else Double.NaN;
def sL = if Reset then fL[-Length + 1] else Double.NaN;
def Hf = if EOD then Double.NaN else if !IsNaN(sH) then sH else Hf[1];
def Lf = if EOD then Double.NaN else if !IsNaN(sL) then sL else Lf[1];
def BOC = if Reset then 0 else if !IsNaN(BOC[1]) and BOC[1] == Consecutive_Closes_Above then Double.NaN else if RB or EOD or !Highest_Lowest_TimeFrame then 0 else if close > Hf and !Doji and !RB then BOC[1] + 1 else BOC[1];
def BDC = if Reset then 0 else if !IsNaN(BOC[1]) and BDC[1] == Consecutive_Closes_Below then Double.NaN else if GB or EOD or !Highest_Lowest_TimeFrame then 0 else if close < Lf and !Doji and !GB then BDC[1] + 1 else BDC[1];
input averageType = AverageType.simple;
plot zeroline = 0 ;
ZeroLine.SetDefaultColor(GetColor(0));
plot ATR = MovingAverage(averageType, TrueRange(high, open, low), length);
ATR.SetDefaultColor(GetColor(8));
input AtrBands = yes;
plot hATR = Highest(ATR,75);
hATR.SetDefaultColor(GetColor(7));
plot lATR = Lowest(ATR,50);
lATR.SetDefaultColor(GetColor(6));
Here I paste the picture of how that first wrong atr looks like
Last edited by a moderator: