NaN means Not a Number. The double.NaN function in thinkScript code can be used to prevent a line, signal, or bubble from being displayed. In other words, if a plot's condition is no longer true, the plot stops displaying on your chart.
This code plot an up arrow at every candle when the closing price is above the 200 simple moving average. If the closing price is below the moving average, then nothing will be displayed.
Code:
Usage
Code:
plot Data = if condition then value else double.nan;
Example
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#
input price = close;
input length = 200;
input displace = 0;
plot SMA = Average(price[-displace], length);
plot UpSignal = if price > SMA then close else double.nan;
SMA.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
This code plot an up arrow at every candle when the closing price is above the 200 simple moving average. If the closing price is below the moving average, then nothing will be displayed.
Additional scripts related to double.NaN
- https://usethinkscript.com/threads/double-nan-question.7931/
- https://usethinkscript.com/threads/...anding-isnan-coding-function.4244/#post-39117
Useful Notes from the thinkScript Lounge
Code:
Code:
def ClsUp = close > open;
def HiLw2 = hl2;
def PSAR_Line = parabolicSAR(0.02,0.2);
def hl2XDwn = HiLw2[1] >= PSAR_Line[1] && HiLw2 < PSAR_Line;
Rec Rzstnce = if IsNan(Rzstnce[1]) or (close[1] < Rzstnce[1] and close > Rzstnce[1]) then 0 else if hl2XDwn then PSAR_Line else Rzstnce[1];
plot TrndLine = PSAR_Line;
Plot Resistance = if Rzstnce > 0 then Rzstnce else double.nan;
Resistance.SetLineWeight(3);
Plot ResistanceBroken = Rzstnce[1] > 0 and Rzstnce == 0;
ResistanceBroken.SetPaintingStrategy(PaintingStrategy.boolean_arrow_Up);
ResistanceBroken.SetLineWeight(3);
ResistanceBroken.SetDefaultColor(color.green);