 # thinkScript double.NaN function in ThinkorSwim

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.

### 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.

### Useful Notes from the thinkScript Lounge

You can use Double.Nan to keep a plot from appearing. There may be times when you may want to keep a plot line from displaying on the chart...Here is an example of using double.nan This code finds a high spot in the price based on a PSAR, and plots the high as a straight line. The code assumes that the new high is a point of resistance. If the price closes over the Resistance line, the code stops displaying the line. [source]

Code:

Code:
``````def ClsUp = close > open;
def HiLw2 = hl2;

def PSAR_Line = parabolicSAR(0.02,0.2);

def hl2XDwn = HiLw2 >= PSAR_Line && HiLw2 < PSAR_Line;

Rec Rzstnce = if IsNan(Rzstnce) or (close < Rzstnce and close > Rzstnce) then 0 else if hl2XDwn then PSAR_Line else Rzstnce;

plot TrndLine = PSAR_Line;

Plot Resistance = if Rzstnce > 0 then Rzstnce else double.nan;
Resistance.SetLineWeight(3);

Plot ResistanceBroken = Rzstnce > 0 and Rzstnce == 0;
ResistanceBroken.SetPaintingStrategy(PaintingStrategy.boolean_arrow_Up);
ResistanceBroken.SetLineWeight(3);
ResistanceBroken.SetDefaultColor(color.green);``````
Author
BenTen
Views
3,150
First release
Last update
Rating
2 ratings