|
BIRMINGHAM
Posts: 7 since Oct 2020
Thanks Given: 4
Thanks Received: 2
|
Please see if this helps.
Would be interested, in knowing how you use this? Guess this is like closing range/opening range for next day.
There is a debug flag to see the lines used in calculations etc, disabled by default.
Looks like I don't have enough posts, so it is not letting me images or links as reference to this post.
# source NexusFi link here
# 02/26/2023 Raj B, initial version of closing range clouds
declare upper;
input sampleStartTime = 1515;
input sampleEndTime = 1600;
input debug = no;
def isSampleTime = if SecondsFromTime(sampleStartTime) >= 0 and SecondsTillTime(sampleEndTime) >= 0 then yes else no;
def emaLength = 20;
def ema = MovingAverage(AverageType.EXPONENTIAL, close, emaLength);
# mark higher of high or ema
plot highPlot = if isSampleTime then Max(high, ema) else Double.NaN;
# mark lower of low or ema
plot lowPlot = if isSampleTime then Min(low, ema) else Double.NaN;
#calculate values for after 1600/sampleEndTime
def closingHigh = if isSampleTime and !isSampleTime[1]
then highPlot
else Max(highPlot, closingHigh[1]);
def closingLow = if isSampleTime and !isSampleTime[1]
then lowPlot
else Min(lowPlot, closingLow[1]);
def yDayClosingHigh = if isSampleTime[1] and !isSampleTime then closingHigh[1]
else if isSampleTime then Double.NaN
else yDayClosingHigh[1];
plot yDayClosingHighPlot = yDayClosingHigh;
def yDayClosingLow = if isSampleTime[1] and !isSampleTime then closingLow[1]
else if isSampleTime then Double.NaN
else yDayClosingLow[1];
plot yDayClosingLowPlot = yDayClosingLow;
#hidelines, disable them to debug
highPlot.setHiding(!debug);
lowPlot.setHiding(!debug);
yDayClosingHighPlot.SetHiding(!debug);
yDayClosingLowPlot.SetHiding(!debug);
AddCloud(yDayClosingLowPlot, yDayClosingHighPlot, Color.GRAY, Color.GRAY);
|