Usage
plot Data = if condition then value else double.nan;
Example
#
# 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:
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);