So I got this code from the TOS & Thinkscript Collection and it works great. It displays the highest price over a look back period.
I wanted to modify it do the same displaying the lowest price over a period. Simple right? Not so much. I have some thinkscript experience but this is my first foray into calculating and displaying information based on price bars in the chart.
This line always seems to evalutate to 0.
def lastBar = LowestAll( if IsNaN(price) then 0 else barNum );
I would think that LowestAll performs similarly to HighestAll in the working code. But it doesn't. Any ideas on what I'm missing?
Here is my simplified code to find the lowest price. I split out the lowest functionality for debugging. I know there are several ways to do this. But this is my first foray into bar by bar calculations and I'm looking for something simple that I can build on as I learn.
Code:
#hint:<b>Plots a line for the highest in the last ? bars</b>\nHas option for a % lower plot
declare upper;
input numBars = 50;#hint numBars: The number of bars monitored
input price = high;#hint price:Select the price to monitor
input hidePctLowerPlot = yes;#hint hidePctLowerPlot: Yes hides the hidePctLowerPlot
input PctLower = 5;#hint PctLower: define the % lower plot criteria
def barNum = barNumber();
def lastBar = HighestAll( if IsNaN(price) then 0 else barNum );
def startBar = if lastBar <= numBars then 1 else lastBar - numBars;
def totBars = if lastBar <= numBars then lastBar else numBars;
def data = if barNum < startBar then 0 else price;
def highestData = HighestAll( data );
plot HighestHigh = highestData;
plot PercentDown = highestData * (1 - (PctLower/100));
HighestHigh.SetPaintingStrategy( PaintingStrategy.LINE );
HighestHigh.SetLineWeight(3);
HighestHigh.AssignValueColor( color.CYAN );
#HighestHigh.SetDefaultColor(Color.CYAN);
HighestHigh.HideBubble();
PercentDown.SetStyle( Curve.SHORT_DASH );
PercentDown.SetLineWeight(1);
PercentDown.SetDefaultColor(Color.RED);
PercentDown.HideBubble();
PercentDown.SetHiding( hidePctLowerPlot );
AddChartBubble( barNum == startBar, HighestHigh, "Highest High in the Past " + totBars + " bars: " + HighestHigh, color.CYAN );
AddChartBubble( barNum == startBar and !hidePctLowerPlot, PercentDown,
PctLower + " % Below Highest High in the Past " + totBars + " bars: " + PercentDown,
color.RED );
I wanted to modify it do the same displaying the lowest price over a period. Simple right? Not so much. I have some thinkscript experience but this is my first foray into calculating and displaying information based on price bars in the chart.
This line always seems to evalutate to 0.
def lastBar = LowestAll( if IsNaN(price) then 0 else barNum );
I would think that LowestAll performs similarly to HighestAll in the working code. But it doesn't. Any ideas on what I'm missing?
Here is my simplified code to find the lowest price. I split out the lowest functionality for debugging. I know there are several ways to do this. But this is my first foray into bar by bar calculations and I'm looking for something simple that I can build on as I learn.
Code:
declare upper;
input numBars = 50;#hint numBars: The number of bars monitored
input price = low;#hint price:Select the price to monitor
input hidePctUpperPlot = yes;#hint hidePctUpperPlot: Yes hides the hidePctUpperPlot
input PctLower = 5;#hint PctLower: define the % lower plot criteria
def barNum = barNumber();
def lastBar = LowestAll( if IsNaN(price) then 0 else barNum );
def startBar = if lastBar <= numBars then 1 else lastBar - numBars;
def totBars = if lastBar <= numBars then lastBar else numBars;
def data = if barNum < startBar then 0 else price;
def lowestData = LowestAll( data );
plot LowestLow = lowestData;
plot PercentUp = lowestData * (1 - (PctLower/100));
LowestLow.SetPaintingStrategy( PaintingStrategy.LINE );
LowestLow.SetLineWeight(3);
LowestLow.AssignValueColor( color.Yellow );
#HighestHigh.SetDefaultColor(Color.Yellow);
LowestLow.HideBubble();
PercentUp.SetStyle( Curve.SHORT_DASH );
PercentUp.SetLineWeight(1);
PercentUp.SetDefaultColor(Color.RED);
PercentUp.HideBubble();
PercentUp.SetHiding( hidePctUpperPlot );
AddChartBubble( barNum == startBar, LowestLow, "Lowest Low in the Past " + totBars + " bars: " + LowestLow, color.Yellow );
AddChartBubble( barNum == startBar and !hidePctUpperPlot, PercentUp,
PctLower + " % Above Lowest Low in the Past " + totBars + " bars: " + PercentUp,
color.RED );