ParabolicSAR - PSAR Moving Average Strategy For ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Besides /ES or SPY , there are other tickers that are good to watch for ParabolicMA ( they have the highest PnL for 5days aggregated to 1minute candles.

QQQ : 23.13
NVDA : 24.92
SPY : 24.29
FSLR : 29.95
HD : 25.20 New find
TSLA : 40:37
NFLX : 51.68
ENPH : 66.11 New find

The question is , is there any that might establish a correlation to the PnL to benefit even more from this strategy?
 
each ? comparing version 2 with 1_18 ?

Is it possible to modify the strategy to only include regular trading hours or entries only during the 1st 2 hours ?
this is for regular trading hours
input open_time = 915;
input closing_time = 1600;

and add the folowint to the long short open orders

&& SecondsFromTime(open_time) > 900 && SecondsTillTime(closing_time) > 1800
like this

AddOrder(OrderType.BUY_TO_OPEN, BuySignal, open[-1],
&& SecondsFromTime(open_time) > 900 && SecondsTillTime(closing_time) > 1800,
TradeSize, Color.GREEN, Color.GREEN, name = "Long");
 
this is for regular trading hours
input open_time = 915;
input closing_time = 1600;

and add the folowint to the long short open orders

&& SecondsFromTime(open_time) > 900 && SecondsTillTime(closing_time) > 1800
like this

AddOrder(OrderType.BUY_TO_OPEN, BuySignal, open[-1],
&& SecondsFromTime(open_time) > 900 && SecondsTillTime(closing_time) > 1800,
TradeSize, Color.GREEN, Color.GREEN, name = "Long");

Do not use this yet as there are some known problems in Signalling

# Parabolic_SAR_Moving_Average_Trading_Strategy

# by BabyTrader using the following article: Parabolic SAR Moving Average Trading Strategy

# https://tradingstrategyguides.com/parabolic-sar-moving-average-trade-strategy/

# ParabolicSAR_withAlerts_JQ
# 2018-04-15 Mods by Johnny Quotron
# with a very helpful kickstart from DMonkey
# Mods include
# 1. splitting the PSAR into two visible plots so that they can be colored seperately
# 2. adding alert arrows at the PSAR to enhance visibility
# a. original alert arrows remain available but are hidden by default
# 3. add ability to color color alert arrows
#

# Combined/Modified/Altered by SilverWolf


declare upper;

#======== Inputs ==============================================================================



input accelerationFactor = 0.012;
input accelerationLimit = 0.2;
input extremeoffset = 0.0;

input MovAvgType = AverageType.EXPONENTIAL;
input MovAvgTrendMethod = {default "SINGLE", "CROSSING"};
input CrossingAvgLength = 9;
input TrendTriggerAvgLength = 21;

input TradeClosingMethod = {default "SAR", "MOVAVG"};
input TradeSize = 1;

input open_time = 915;
input closing_time = 1600;

def RTH = Secondsfromtime(open_time) >= 0 and secondstillTime(closing_time) >= 0;


def Trend = if MovAvgTrendMethod == MovAvgTrendMethod."SINGLE" then 1 else
if MovAvgTrendMethod == MovAvgTrendMethod."CROSSING" then 2 else 0;

def PlotCross = if Trend == 2 then yes else no;

def Closer = if TradeClosingMethod == TradeClosingMethod."SAR" then 1 else
if TradeClosingMethod == TradeClosingMethod."MOVAVG" then 2 else 0;





#======== Moving Averages ======================================================================

plot TriggerAVG = MovingAverage(MovAvgType, close, TrendTriggerAvgLength);
TriggerAVG.SetLineWeight(3);
TriggerAVG.SetDefaultColor(Color.WHITE);

plot CrossingAVG = MovingAverage(MovAvgType, close, CrossingAvgLength);
CrossingAVG.SetHiding(!PlotCross);
CrossingAVG.SetLineWeight(3);
CrossingAVG.SetDefaultColor(Color.PINK);

#======== ParabolicSAR =========================================================================

Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high)
then {
state = state.long;
acc = accelerationFactor;
extreme = high + extremeoffset;
SAR = extreme[1];
} else {
state = state.short;
if (low < extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = low - extremeoffset;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
}
case long:
if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low - extremeoffset;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high + extremeoffset;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
}
}


#======== SIGNALS =========================================================================


#def BuySignal = close > TriggerAVG and ADX > ADX[-1];

def BuySignal = if Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close)
then 1

else if Trend == 2 and (close > TriggerAVG) and (CrossingAVG crosses above TriggerAVG) and (SAR < close)

then 1
else Double.NaN;

#def SellSignal = close < TriggerAVG and ADX > ADX[-1];
def SellSignal = if Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close)
then 1

else if Trend == 2 and (close < TriggerAVG) and (CrossingAVG crosses below TriggerAVG) and (SAR > close)

then 1

else Double.NaN;


def BuyExit = if Closer == 1 and (close crosses below SAR[-1])

then 1

else if Closer == 2 and (TriggerAVG > CrossingAVG)

then 1

else Double.NaN;


def SellExit = if Closer == 1 and (close crosses above SAR[-1])

then 1

else if Closer == 2 and (TriggerAVG < CrossingAVG)

then 1

else Double.NaN;


#======== STRATEGY ORDERS ===================================================================
AddOrder(OrderType.BUY_TO_OPEN, BuySignal and RTH, open[-1], TradeSize, Color.GREEN, Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, open[-1], TradeSize, Color.RED, Color.RED, name = "Close");
AddOrder(OrderType.SELL_TO_OPEN, SellSignal and RTH, open[-1], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short");
AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], TradeSize, Color.WHITE, Color.WHITE, name = "Close");
#======== PLOTS ============================================================================

plot BullPSAR = if SAR < close then SAR else Double.NaN;
BullPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BullPSAR.SetDefaultColor(Color.LIME);

plot BearPSAR = if SAR > close then SAR else Double.NaN;
BearPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BearPSAR.SetDefaultColor(Color.PINK);

#---

def BullSignalAtCandle = Crosses(SAR, close, CrossingDirection.BELOW);
plot BullSignalAtPSAR = if close crosses above SAR
then SAR
else Double.NaN;
BullSignalAtPSAR.SetLineWeight(1);
BullSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignalAtPSAR.SetDefaultColor(Color.LIME);

def BearSignalAtCandle = Crosses(SAR, close, CrossingDirection.ABOVE);
plot BearSignalAtPSAR = if close crosses below SAR
then SAR
else Double.NaN;
BearSignalAtPSAR.SetLineWeight(1);
BearSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignalAtPSAR.SetDefaultColor(Color.PINK);

#---

plot LongEntrySignal = if BuySignal then BuySignal else Double.NaN;
LongEntrySignal.SetDefaultColor(Color.UPTICK);
LongEntrySignal.SetLineWeight(5);
LongEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


plot ShortEntrySignal = if SellSignal then SellSignal else Double.NaN;
ShortEntrySignal.SetDefaultColor(Color.DOWNTICK);
ShortEntrySignal.SetLineWeight(5);
ShortEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot LongExitSignal = if BuyExit then BuyExit else Double.NaN;
LongExitSignal.SetDefaultColor(Color.White);
LongExitSignal.SetLineWeight(1);
LongExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


plot ShortExitSignal = if SellExit then SellExit else Double.NaN;
ShortExitSignal.SetDefaultColor(Color.White);
ShortExitSignal.SetLineWeight(1);
ShortExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);



#======== ALERTS ===========================================================================

input AlertsOn = No;
Alert(AlertsOn and BullSignalAtCandle, "Bullish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BearSignalAtCandle, "Bearish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BuySignal, "Bullish PSAR above AVG", Alert.BAR, Sound.Ring);
Alert(AlertsOn and SellSignal, "Bullish PSAR below AVG", Alert.BAR, Sound.Ring);

#======== EOF ===========================================================================
 
Last edited:
Has anyone successfully added Labels that will stay visible and change color when triggered? I would like to test this with Macro Recorder.

@dap711 Hopefully you can work your magic on this strategy. I have been testing it and it is extremely promising. I think you may even find it quite profitable when auto trading. Can you make the labels work like the ASAP strat? Where you have three. 1 for buy. 1 for sell , and 1 for close? I tried but cannot get it to work with 3. I think it is working with four but it doesn't function like yours in that the labels fire and just stay for a while. Here is the code:

@SilverWolf is the creator for this one. He has been a great help.

Code:
# Parabolic_SAR_Moving_Average_Trading_Strategy
# ParabolicSAR_Trendy_Strategy_1_18

# by BabyTrader using the following article: Parabolic SAR Moving Average Trading Strategy

# https://tradingstrategyguides.com/parabolic-sar-moving-average-trade-strategy/

# ParabolicSAR_withAlerts_JQ
# 2018-04-15 Mods by Johnny Quotron
#    with a very helpful kickstart from DMonkey
# Mods include
#    1. splitting the PSAR into two visible plots so that they can be colored seperately
#    2. adding alert arrows at the PSAR to enhance visibility
#        a. original alert arrows remain available but are hidden by default
#    3. add ability to color color alert arrows
#

# Combined/Modified/Altered by SilverWolf


declare upper;
 
#======== Inputs ==============================================================================

input TradeSize = 1;
input SarBars = 1;
input accelerationFactor = 0.012;
input accelerationLimit = 0.2;
input extremeoffset = 0.0;

input MovAvgType = AverageType.EXPONENTIAL;
input MovAvgTrendMethod = {default "SINGLE", "CROSSING"};
input CrossingAvgLength = 9;
input TrendTriggerAvgLength = 21;

input TradeClosingMethod = {default "SAR", "MOVAVG"};


def Trend = if MovAvgTrendMethod == MovAvgTrendMethod."SINGLE" then 1 else
            if MovAvgTrendMethod == MovAvgTrendMethod."CROSSING" then 2 else 0;

def PlotCross = if Trend == 2 then yes else no;

def Closer = if TradeClosingMethod == TradeClosingMethod."SAR" then 1 else
             if TradeClosingMethod == TradeClosingMethod."MOVAVG" then 2 else 0;

#======== Moving Averages ======================================================================

plot TriggerAVG = MovingAverage(MovAvgType, close, TrendTriggerAvgLength);
TriggerAVG.SetLineWeight(3);
TriggerAVG.SetDefaultColor(Color.WHITE);

plot CrossingAVG = MovingAverage(MovAvgType, close, CrossingAvgLength);
CrossingAVG.SetHiding(!PlotCross);
CrossingAVG.SetLineWeight(3);
CrossingAVG.SetDefaultColor(Color.PINK);

#======== ParabolicSAR =========================================================================

Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
    state = state.long;
    acc = accelerationFactor;
    extreme = high;
    SAR = low;
case short:
    if (SAR[1] < high)
    then {
        state = state.long;
        acc = accelerationFactor;
        extreme = high + extremeoffset;
        SAR = extreme[1];
    } else {
        state = state.short;
        if (low < extreme[1])
        then {
            acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = low - extremeoffset;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
case long:
    if (SAR[1] > low)
    then {
        state = state.short;
        acc = accelerationFactor;
        extreme = low - extremeoffset;
        SAR = extreme[1];
    } else {
        state = state.long;
        if (high > extreme[1])
        then {
            acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = high + extremeoffset;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
}

#======== ADX ===========================================================================

input ADXlength = 14;
input averageType = AverageType.WILDERS;
input mom = 20;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), ADXlength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, ADXlength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, ADXlength) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, ADXlength);


#======== Logic =========================================================================
input adxLogic = yes;

def Logic = if adxLogic and ADX > mom

then 1

else if adxLogic and ADX < mom

then 2

else if !adxLogic

then 1

else Double.NaN;



#======== SIGNALS =========================================================================

def BuySignal = if Logic == 1 and Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close)

then 1

else if Logic == 1 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close)

then 1

else if Logic == 2 and Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close)

then 1

else if Logic == 2 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close)

then 1

else Double.NaN;


def SellSignal = if Logic == 1 and Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close)

then 1

else if Logic == 1 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close)

then 1

else if Logic == 2 and Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close)

then 1

else if Logic == 2 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close)

then 1

else Double.NaN;


def BuyExit = if Logic == 1 and Closer == 1 and (close crosses below SAR)

then 1

else if Logic == 1 and Closer == 2 and (close crosses below TriggerAVG)

then 1

else if Logic == 2 and Closer == 1 and (close crosses above SAR)

then 1

else if Logic == 2 and Closer == 2 and (close crosses above TriggerAVG)

then 1

else if Logic == 1 and Closer == 1 and (adx crosses mom)

then 1

else if Logic == 1 and Closer == 2 and (adx crosses mom)

then 1

else if Logic == 2 and Closer == 1 and (adx crosses mom)

then 1

else if Logic == 2 and Closer == 2 and (adx crosses mom)

then 1

else Double.NaN;


def SellExit = if Logic == 1 and Closer == 1 and (close crosses above SAR)

then 1

else if Logic == 1 and Closer == 2 and (close crosses above TriggerAVG)

then 1

else if Logic == 2 and Closer == 1 and (close crosses below SAR)

then 1

else if Logic == 2 and Closer == 2 and (close crosses below TriggerAVG)

then 1

else if Logic == 1 and Closer == 1 and (adx crosses mom)

then 1

else if Logic == 1 and Closer == 2 and (adx crosses mom)

then 1

else if Logic == 2 and Closer == 1 and (adx crosses mom)

then 1

else if Logic == 2 and Closer == 2 and (adx crosses mom)

then 1

else Double.NaN;


#======== STRATEGY ORDERS ===================================================================

def VolStrength = Lg(volume[1]) - Lg(SimpleMovingAvg(volume[1], 2000));
def HighPrice = high;
def LowPrice = low;


AddOrder(OrderType.BUY_TO_OPEN, BuySignal, open[-1], TradeSize, Color.GREEN, Color.GREEN, name = "Buy" + Logic + " T" + Trend);

AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, open[-1], TradeSize, Color.RED, Color.RED, name = "Close B" + Logic + " C" + Closer);

AddOrder(OrderType.SELL_TO_OPEN, SellSignal, open[-1], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short" + Logic + " T" + Trend);

AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], TradeSize, Color.WHITE, Color.WHITE, name = "Close S" + Logic + " C" + Closer);


#======== PLOTS ============================================================================

plot BullPSAR = if SAR < close then SAR else Double.NaN;
BullPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BullPSAR.SetDefaultColor(Color.LIME);

plot BearPSAR = if SAR > close then SAR else Double.NaN;
BearPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BearPSAR.SetDefaultColor(Color.PINK);

#---

def BullSignalAtCandle = Crosses(SAR, close, CrossingDirection.BELOW);
plot BullSignalAtPSAR = if close crosses above SAR
                     then SAR
                     else Double.NaN;
BullSignalAtPSAR.SetLineWeight(1);
BullSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignalAtPSAR.SetDefaultColor(Color.LIME);

def BearSignalAtCandle = Crosses(SAR, close, CrossingDirection.ABOVE);
plot BearSignalAtPSAR = if close crosses below SAR
                     then SAR
                     else Double.NaN;
BearSignalAtPSAR.SetLineWeight(1);
BearSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignalAtPSAR.SetDefaultColor(Color.PINK);

#---

plot LongEntrySignal = if BuySignal then BuySignal else Double.NaN;
LongEntrySignal.SetDefaultColor(Color.UPTICK);
LongEntrySignal.SetLineWeight(5);
LongEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


plot ShortEntrySignal = if SellSignal then SellSignal else Double.NaN;
ShortEntrySignal.SetDefaultColor(Color.DOWNTICK);
ShortEntrySignal.SetLineWeight(5);
ShortEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot LongExitSignal = if BuyExit then BuyExit else Double.NaN;
LongExitSignal.SetDefaultColor(Color.WHITE);
LongExitSignal.SetLineWeight(1);
LongExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


plot ShortExitSignal = if SellExit then SellExit else Double.NaN;
ShortExitSignal.SetDefaultColor(Color.WHITE);
ShortExitSignal.SetLineWeight(1);
ShortExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#======== ALERTS ===========================================================================

input AlertsOn = No;
Alert(AlertsOn and BullSignalAtCandle, "Bullish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BearSignalAtCandle, "Bearish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BuySignal, "Bullish PSAR above AVG", Alert.BAR, Sound.Ring);
Alert(AlertsOn and SellSignal, "Bullish PSAR below AVG", Alert.BAR, Sound.Ring);

#======== Paint Bars =======================================================================

input paintBars = No;
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if SAR < close
        then Color.GREEN
        else if  SAR > close
            then Color.RED
            else Color.CURRENT);

#======== Labels ===========================================================================

#Spacer
input blink = no;
input AdvLabelsOn = no;
input simpleLabels = no;

def NewBar = if close[1] != close[2] or high[1] != high[2] or low[1] != low[2] then yes else Double.NaN;
def Clock = if !IsNaN(NewBar) and Clock[1] == 1 then 0 else if !IsNaN(NewBar) and Clock[1] == 0 then 1 else Clock[1];

#AddLabel(blink and AdvLabelsOn or SimpleLabels, "", if Clock == 0 then Color.WHITE else Color.YELLOW);
#AddLabel(!blink and AdvLabelsOn or SimpleLabels, "                                                                     ParabolicSAR Strategy Version 01.11                                                                                                     ",  Color.WHITE);


#Buy
AddLabel(AdvLabelsOn,
if  Logic == 1 and Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close) within SarBars bars
or  Logic == 1 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars
or  Logic == 2 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or  Logic == 2 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars then "         " else "         ",

if  Logic == 1 and Trend == 1 and (close > TriggerAVG) and (SAR crosses below close) within SarBars bars
or  Logic == 1 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars
or  Logic == 2 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or  Logic == 2 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars then Color.GREEN else Color.WHITE);


#BuyClose
AddLabel(AdvLabelsOn,
if  Logic == 1 and Closer == 1 and (SAR > close) within SarBars bars
or  Logic == 1 and  Closer == 2 and (close < TriggerAVG) within SarBars bars
or  Logic == 2 and Closer == 1 and (SAR < close) within SarBars bars
or  Logic == 2 and Closer == 2 and (close > TriggerAVG)
or  Logic == 1 and Closer == 1 and (adx crosses above mom) within SarBars bars
or  Logic == 1 and Closer == 2 and (adx crosses above mom) within SarBars bars
or  Logic == 2 and Closer == 1 and (adx crosses below mom) within SarBars bars
or  Logic == 2 and Closer == 2 and (adx crosses below mom) within SarBars bars then "         " else "         ",

if  Logic == 1 and Closer == 1 and (SAR > close) within SarBars bars
or  Logic == 1 and  Closer == 2 and (close < TriggerAVG) within SarBars bars
or  Logic == 2 and Closer == 1 and (SAR < close) within SarBars bars
or  Logic == 2 and Closer == 2 and (close > TriggerAVG)
or  Logic == 1 and Closer == 1 and (adx crosses above mom) within SarBars bars
or  Logic == 1 and Closer == 2 and (adx crosses above mom) within SarBars bars
or  Logic == 2 and Closer == 1 and (adx crosses below mom) within SarBars bars
or  Logic == 2 and Closer == 2 and (adx crosses below mom) within SarBars bars then Color.MAGENTA else Color.WHITE);

#Sell
AddLabel(AdvLabelsOn,
if  Logic == 1 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or  Logic == 1 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 2 and Trend == 1 and (close > TriggerAVG) and (SAR crosses below close) within SarBars bars
or  Logic == 2 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars then "         " else "         ",

if  Logic == 1 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or  Logic == 1 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars
or  Logic == 2 and Trend == 1 and (close > TriggerAVG) and (SAR crosses below close) within SarBars bars
or  Logic == 2 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars then Color.RED else Color.WHITE);


#SellClose
AddLabel(AdvLabelsOn,
if  Logic == 1 and Closer == 1 and (SAR < close) within SarBars bars
or  Logic == 1 and Closer == 2 and (close > TriggerAVG) within SarBars bars
or  Logic == 2 and Closer == 1 and (SAR > close) within SarBars bars
or  Logic == 2 and Closer == 2 and (close < TriggerAVG)
or  Logic == 1 and Closer == 1 and (adx crosses below mom) within SarBars bars
or  Logic == 1 and Closer == 2 and (adx crosses below mom) within SarBars bars
or  Logic == 2 and Closer == 1 and (adx crosses above mom) within SarBars bars
or  Logic == 2 and Closer == 2 and (adx crosses above mom) within SarBars bars then "         " else "         ",

if  Logic == 1 and Closer == 1 and (SAR < close) within SarBars bars
or  Logic == 1 and Closer == 2 and (close > TriggerAVG) within SarBars bars
or Logic == 2 and Closer == 1 and (SAR> close) within SarBars bars
or  Logic == 2 and Closer == 2 and (close < TriggerAVG)
or  Logic == 1 and Closer == 1 and (adx crosses below mom) within SarBars bars
or  Logic == 1 and Closer == 2 and (adx crosses below mom) within SarBars bars
or  Logic == 2 and Closer == 1 and (adx crosses above mom) within SarBars bars
or  Logic == 2 and Closer == 2 and (adx crosses above mom) within SarBars bars then Color.MAGENTA else Color.WHITE);




AddLabel (simpleLabels, if BuySignal within SarBars bars then  "         " else   "         ", if BuySignal >= 1 within SarBars bars then Color.GREEN else Color.WHITE);
AddLabel (simpleLabels, if BuyExit within SarBars bars then  "         " else   "         ", if BuyExit >= 1 within SarBars bars then Color.MAGENTA else Color.WHITE);
AddLabel (simpleLabels, if SellSignal within SarBars bars then  "         " else   "         ", if SellSignal >= 1 within SarBars bars then Color.RED else Color.WHITE);
AddLabel (simpleLabels, if SellExit within SarBars bars then  "         " else   "         ", if SellExit >= 1 within SarBars bars then Color.YELLOW else Color.WHITE);



#AddLabel (AdvLabelsOn or simpleLabels,
#if Logic == 2 then "  Modified Logic  " else "   Normal Logic   ", Color.WHITE);


#======== EOF =========================================================================Y_AUTO, no);
 
Has anyone successfully added Labels that will stay visible and change color when triggered? I would like to test this with Macro Recorder.
In the code where it defines each signal... try to change the last else.. from "else Double.NaN;" to "else 0;" when double.nan is used if not true it means nothing. When you change it to zero it now is something... and will then show the other color. Hope this helps
 
# Parabolic_SAR_Moving_Average_Trading_Strategy

# by BabyTrader using the following article: Parabolic SAR Moving Average Trading Strategy

# https://tradingstrategyguides.com/parabolic-sar-moving-average-trade-strategy/

# ParabolicSAR_withAlerts_JQ
# 2018-04-15 Mods by Johnny Quotron
# with a very helpful kickstart from DMonkey
# Mods include
# 1. splitting the PSAR into two visible plots so that they can be colored seperately
# 2. adding alert arrows at the PSAR to enhance visibility
# a. original alert arrows remain available but are hidden by default
# 3. add ability to color color alert arrows
#

# Combined/Modified/Altered by SilverWolf


declare upper;

#======== Inputs ==============================================================================



input accelerationFactor = 0.012;
input accelerationLimit = 0.2;
input extremeoffset = 0.0;

input MovAvgType = AverageType.EXPONENTIAL;
input MovAvgTrendMethod = {default "SINGLE", "CROSSING"};
input CrossingAvgLength = 9;
input TrendTriggerAvgLength = 21;

input TradeClosingMethod = {default "SAR", "MOVAVG"};
input TradeSize = 1;

input open_time = 915;
input closing_time = 1600;

def RTH = Secondsfromtime(open_time) >= 0 and secondstillTime(closing_time) >= 0;


def Trend = if MovAvgTrendMethod == MovAvgTrendMethod."SINGLE" then 1 else
if MovAvgTrendMethod == MovAvgTrendMethod."CROSSING" then 2 else 0;

def PlotCross = if Trend == 2 then yes else no;

def Closer = if TradeClosingMethod == TradeClosingMethod."SAR" then 1 else
if TradeClosingMethod == TradeClosingMethod."MOVAVG" then 2 else 0;





#======== Moving Averages ======================================================================

plot TriggerAVG = MovingAverage(MovAvgType, close, TrendTriggerAvgLength);
TriggerAVG.SetLineWeight(3);
TriggerAVG.SetDefaultColor(Color.WHITE);

plot CrossingAVG = MovingAverage(MovAvgType, close, CrossingAvgLength);
CrossingAVG.SetHiding(!PlotCross);
CrossingAVG.SetLineWeight(3);
CrossingAVG.SetDefaultColor(Color.PINK);

#======== ParabolicSAR =========================================================================

Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high)
then {
state = state.long;
acc = accelerationFactor;
extreme = high + extremeoffset;
SAR = extreme[1];
} else {
state = state.short;
if (low < extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = low - extremeoffset;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
}
case long:
if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low - extremeoffset;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high + extremeoffset;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
}
}


#======== SIGNALS =========================================================================


#def BuySignal = close > TriggerAVG and ADX > ADX[-1];

def BuySignal = if Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close)
then 1

else if Trend == 2 and (close > TriggerAVG) and (CrossingAVG crosses above TriggerAVG) and (SAR < close)

then 1
else Double.NaN;

#def SellSignal = close < TriggerAVG and ADX > ADX[-1];
def SellSignal = if Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close)
then 1

else if Trend == 2 and (close < TriggerAVG) and (CrossingAVG crosses below TriggerAVG) and (SAR > close)

then 1

else Double.NaN;


def BuyExit = if Closer == 1 and (close crosses below SAR[-1])

then 1

else if Closer == 2 and (TriggerAVG > CrossingAVG)

then 1

else Double.NaN;


def SellExit = if Closer == 1 and (close crosses above SAR[-1])

then 1

else if Closer == 2 and (TriggerAVG < CrossingAVG)

then 1

else Double.NaN;


#======== STRATEGY ORDERS ===================================================================
AddOrder(OrderType.BUY_TO_OPEN, BuySignal and RTH, open[-1], TradeSize, Color.GREEN, Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, open[-1], TradeSize, Color.RED, Color.RED, name = "Close");
AddOrder(OrderType.SELL_TO_OPEN, SellSignal and RTH, open[-1], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short");
AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], TradeSize, Color.WHITE, Color.WHITE, name = "Close");
#======== PLOTS ============================================================================

plot BullPSAR = if SAR < close then SAR else Double.NaN;
BullPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BullPSAR.SetDefaultColor(Color.LIME);

plot BearPSAR = if SAR > close then SAR else Double.NaN;
BearPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BearPSAR.SetDefaultColor(Color.PINK);

#---

def BullSignalAtCandle = Crosses(SAR, close, CrossingDirection.BELOW);
plot BullSignalAtPSAR = if close crosses above SAR
then SAR
else Double.NaN;
BullSignalAtPSAR.SetLineWeight(1);
BullSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignalAtPSAR.SetDefaultColor(Color.LIME);

def BearSignalAtCandle = Crosses(SAR, close, CrossingDirection.ABOVE);
plot BearSignalAtPSAR = if close crosses below SAR
then SAR
else Double.NaN;
BearSignalAtPSAR.SetLineWeight(1);
BearSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignalAtPSAR.SetDefaultColor(Color.PINK);

#---

plot LongEntrySignal = if BuySignal then BuySignal else Double.NaN;
LongEntrySignal.SetDefaultColor(Color.UPTICK);
LongEntrySignal.SetLineWeight(5);
LongEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


plot ShortEntrySignal = if SellSignal then SellSignal else Double.NaN;
ShortEntrySignal.SetDefaultColor(Color.DOWNTICK);
ShortEntrySignal.SetLineWeight(5);
ShortEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot LongExitSignal = if BuyExit then BuyExit else Double.NaN;
LongExitSignal.SetDefaultColor(Color.White);
LongExitSignal.SetLineWeight(1);
LongExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


plot ShortExitSignal = if SellExit then SellExit else Double.NaN;
ShortExitSignal.SetDefaultColor(Color.White);
ShortExitSignal.SetLineWeight(1);
ShortExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);



#======== ALERTS ===========================================================================

input AlertsOn = No;
Alert(AlertsOn and BullSignalAtCandle, "Bullish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BearSignalAtCandle, "Bearish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BuySignal, "Bullish PSAR above AVG", Alert.BAR, Sound.Ring);
Alert(AlertsOn and SellSignal, "Bullish PSAR below AVG", Alert.BAR, Sound.Ring);

#======== EOF ===========================================================================


the above code has some phantom orders. It doesn't seem to work when I introduce orders only during regular trading hours
the report shows it but some of the signals don't show on the charts
 
Is it possible to put the FloatingPL value into a watchlist scanner ?
ToS does not make the floating P/L data available to the condition wizard. Which means it can't be used in the scanner, watchlist, conditional orders, chart alerts, etc… It is only available to us in the charting.
 
@SilverWolf and others. When using the 1_18 version, I keep getting this throughout the entire day of trading and was wandering if this is a glitch or what I am doing wrong. I have adjusted the settings to show the absolute best P/L as well as just tried to get these ghost triggers to go away and cannot seem to get anywhere. Here is an example of what I am getting.
For this example I have the following settings:
1 <--trade size
1
0.012
0.2
0.0
Hull <--Mov avg type
crossing
2
22
sar
20
simple
20 <--mom
Yes
no
Yes
Yes <--Blink
Yes
No



CsNDy9t.jpg
 
@SilverWolf and others. When using the 1_18 version, I keep getting this throughout the entire day of trading and was wandering if this is a glitch or what I am doing wrong. I have adjusted the settings to show the absolute best P/L as well as just tried to get these ghost triggers to go away and cannot seem to get anywhere. Here is an example of what I am getting.
For this example I have the following settings:
1 <--trade size
1
0.012
0.2
0.0
Hull <--Mov avg type
crossing
2
22
sar
20
simple
20 <--mom
Yes
no
Yes
Yes <--Blink
Yes
No



CsNDy9t.jpg
In your image there it is showing "Buy2 T2" Where does that point to in the signal code? If you can post the exact code you are using i can check it out. That looks like the adx reverse logic if I were to guess though.. I was testing the idea of reversing the buy and sells when the adx was below the mom to anticipate sideways price action. So.. if you dont want that feature be sure to turn that off in the settings.
 
@SilverWolf Is there any chance you could put a version # at ech of the different versions you have. And what version are you presently using?
My setup is a mess at the moment.. I dont want to confuse anyone if I were to post the latest version. Let me look over and I can post my latest testing version. PLEASE remember I am testing and not a super pro thinkscript programmer.
 
This is another testing version. I have made changes that allow me to use this with another project. You can disable the labels in the settings. I am currently testing this on a /ES 4tick Renko Range chart. Finding the right chart for consistency and matching the settings is quite a challenge. Some days have a amazing results others are no good. I also have played around with the built in StopLossLX/SX and TakeProfitLX/SX strategies to incorporate stops lately with good results. As always if you have any modifications or corrections.. go for it. I share this so you can enjoy. Have fun and good luck



CSS:
# Parabolic_SAR_Moving_Average_Trading_Strategy
# ParabolicSAR_Trendy_Strategy_02_04

# by BabyTrader using the following article: Parabolic SAR Moving Average Trading Strategy

# https://tradingstrategyguides.com/parabolic-sar-moving-average-trade-strategy/

# ParabolicSAR_withAlerts_JQ
# 2018-04-15 Mods by Johnny Quotron
#    with a very helpful kickstart from DMonkey
# Mods include
#    1. splitting the PSAR into two visible plots so that they can be colored seperately
#    2. adding alert arrows at the PSAR to enhance visibility
#        a. original alert arrows remain available but are hidden by default
#    3. add ability to color color alert arrows
#

# Combined/Modified/Altered by SilverWolf


declare upper;
 
#======== Inputs ==============================================================================

input TradeSize = 1;
input open_time = 930;
input closing_time = 1645;
def RTH = Secondsfromtime(open_time) >= 0 and secondstillTime(closing_time) >= 0;
input SarBars = 3;
input accelerationFactor = 0.012;
input accelerationLimit = 0.2;
input extremeoffset = 0.0;

input MovAvgType = AverageType.EXPONENTIAL;
input MovAvgTrendMethod = {default "SINGLE", "CROSSING"};
input CrossingAvgLength = 9;
input TrendTriggerAvgLength = 21;

input TradeClosingMethod = {default "SAR", "MOVAVG"};


def Trend = if MovAvgTrendMethod == MovAvgTrendMethod."SINGLE" then 1 else
            if MovAvgTrendMethod == MovAvgTrendMethod."CROSSING" then 2 else 0;

def PlotCross = if Trend == 2 then yes else no;

def Closer = if TradeClosingMethod == TradeClosingMethod."SAR" then 1 else
             if TradeClosingMethod == TradeClosingMethod."MOVAVG" then 2 else 0;

#======== Moving Averages ======================================================================

plot TriggerAVG = MovingAverage(MovAvgType, close, TrendTriggerAvgLength);
TriggerAVG.SetLineWeight(3);
TriggerAVG.SetDefaultColor(Color.WHITE);

plot CrossingAVG = MovingAverage(MovAvgType, close, CrossingAvgLength);
CrossingAVG.SetHiding(!PlotCross);
CrossingAVG.SetLineWeight(3);
CrossingAVG.SetDefaultColor(Color.PINK);

#======== ParabolicSAR =========================================================================

Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
    state = state.long;
    acc = accelerationFactor;
    extreme = high;
    SAR = low;
case short:
    if (SAR[1] < high)
    then {
        state = state.long;
        acc = accelerationFactor;
        extreme = high + extremeoffset;
        SAR = extreme[1];
    } else {
        state = state.short;
        if (low < extreme[1])
        then {
            acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = low - extremeoffset;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
case long:
    if (SAR[1] > low)
    then {
        state = state.short;
        acc = accelerationFactor;
        extreme = low - extremeoffset;
        SAR = extreme[1];
    } else {
        state = state.long;
        if (high > extreme[1])
        then {
            acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = high + extremeoffset;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
}

#======== ADX ===========================================================================

input ADXlength = 14;
input averageType = AverageType.WILDERS;
input mom = 20;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), ADXlength);
def "DI+" = 100 * MovingAverage(averageType, plusDM, ADXlength) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, ADXlength) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, ADXlength);


#======== Logic =========================================================================
input adxLogic = no;

def Logic = if adxLogic and ADX > mom

then 1

else if adxLogic and ADX < mom

then 2

else if !adxLogic

then 1

else Double.NaN;

input UseDiTrends = no;

def TrendingUp = if UseDiTrends and "DI-" < ADX and "DI+" > ADX

then 1

else if !UseDiTrends

then 1

else Double.NaN;



def TrendingDown = if UseDiTrends and "DI-" > ADX and "DI+" < ADX

then 1

else if !UseDiTrends

then 1

else Double.NaN;


#======== SIGNALS =========================================================================

def BuySignal =

     if Logic == 1 and Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close) within SarBars bars and TrendingUp

then 1

else if Logic == 1 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) within SarBars bars and (SAR crosses below close) and TrendingUp

then 1

else if Logic == 2 and Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close) within SarBars bars and TrendingDown

then 1

else if Logic == 2 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars and TrendingDown

then 1

else 0;

def SellSignal =
     if Logic == 1 and Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close) within SarBars bars and TrendingDown

then 1

else if Logic == 1 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) within SarBars bars and (SAR crosses above close) and TrendingDown

then 1

else if Logic == 2 and Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close) within SarBars bars and TrendingUp

then 1

else if Logic == 2 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) within SarBars bars and (SAR crosses below close) and TrendingUp

then 1

else 0;

def BuyExit =
      if Logic == 1 and Closer == 1 and (close crosses below SAR)

then 1

else if Logic == 1 and Closer == 2 and (close crosses below TriggerAVG)

then 1

else if Logic == 2 and Closer == 1 and (close crosses above SAR)

then 1

else if Logic == 2 and Closer == 2 and (close crosses above TriggerAVG)

then 1

else if adxLogic and (adx crosses mom)

then 1

else 0;

def SellExit =
     if Logic == 1 and Closer == 1 and (close crosses above SAR)

then 1

else if Logic == 1 and Closer == 2 and (close crosses above TriggerAVG)

then 1

else if Logic == 2 and Closer == 1 and (close crosses below SAR)

then 1

else if Logic == 2 and Closer == 2 and (close crosses below TriggerAVG)

then 1

else if adxLogic and (adx crosses mom)

then 1

else 0;

#======== STRATEGY ORDERS ===================================================================

def VolStrength = Lg(volume[1]) - Lg(SimpleMovingAvg(volume[1], 2000));
def HighPrice = high;
def LowPrice = low;
#input Price = close; #{default Close, Open, high[1] + low[1]/2};


AddOrder(OrderType.BUY_TO_OPEN, BuySignal and RTH, open[-1], TradeSize, Color.GREEN, Color.GREEN, name = "Long L" + Logic + " T" + Trend);

AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, open[-1], TradeSize, Color.RED, Color.RED, name = "Close L" + Logic + " C" + Closer);

AddOrder(OrderType.SELL_TO_OPEN, SellSignal and RTH, open[-1], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short L" + Logic + " T" + Trend);

AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], TradeSize, Color.WHITE, Color.WHITE, name = "Close L" + Logic + " C" + Closer);


#======== PLOTS ============================================================================

plot BullPSAR = if SAR < close then SAR else Double.NaN;
BullPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BullPSAR.SetDefaultColor(Color.LIME);

plot BearPSAR = if SAR > close then SAR else Double.NaN;
BearPSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
BearPSAR.SetDefaultColor(Color.PINK);

#---

def BullSignalAtCandle = Crosses(SAR, close, CrossingDirection.BELOW);
plot BullSignalAtPSAR = if close crosses above SAR
                     then SAR
                     else Double.NaN;
BullSignalAtPSAR.SetLineWeight(1);
BullSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignalAtPSAR.SetDefaultColor(Color.LIME);

def BearSignalAtCandle = Crosses(SAR, close, CrossingDirection.ABOVE);
plot BearSignalAtPSAR = if close crosses below SAR
                     then SAR
                     else Double.NaN;
BearSignalAtPSAR.SetLineWeight(1);
BearSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignalAtPSAR.SetDefaultColor(Color.PINK);

#---

plot LongEntrySignal = if BuySignal then BuySignal else Double.NaN;
LongEntrySignal.SetDefaultColor(Color.UPTICK);
LongEntrySignal.SetLineWeight(5);
LongEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


plot ShortEntrySignal = if SellSignal then SellSignal else Double.NaN;
ShortEntrySignal.SetDefaultColor(Color.DOWNTICK);
ShortEntrySignal.SetLineWeight(5);
ShortEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot LongExitSignal = if BuyExit then BuyExit else Double.NaN;
LongExitSignal.SetDefaultColor(Color.WHITE);
LongExitSignal.SetLineWeight(1);
LongExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


plot ShortExitSignal = if SellExit then SellExit else Double.NaN;
ShortExitSignal.SetDefaultColor(Color.WHITE);
ShortExitSignal.SetLineWeight(1);
ShortExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#======== ALERTS ===========================================================================

input AlertsOn = No;
Alert(AlertsOn and BullSignalAtCandle, "Bullish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BearSignalAtCandle, "Bearish PSAR", Alert.BAR, Sound.Ring);
Alert(AlertsOn and BuySignal, "Bullish PSAR above AVG", Alert.BAR, Sound.Ring);
Alert(AlertsOn and SellSignal, "Bullish PSAR below AVG", Alert.BAR, Sound.Ring);

#======== Paint Bars =======================================================================

input paintBars = No;
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if SAR < close
        then Color.GREEN
        else if  SAR > close
            then Color.RED
            else Color.CURRENT);

#======== Labels ===========================================================================

#Spacer
input simpleLabels = yes;

AddLabel(SimpleLabels, "                                                                     ParabolicSAR Strategy Version 02.04                                                                                                     ",  Color.WHITE);


AddLabel (simpleLabels, "         ",
if BuySignal >= 1 and RTH then Color.GREEN else Color.WHITE);

AddLabel (simpleLabels, "         ",
if BuyExit >= 1 and RTH then Color.MAGENTA else Color.WHITE);

AddLabel (simpleLabels, "         ",
if SellSignal >= 1 and RTH then Color.RED else Color.WHITE);

AddLabel (simpleLabels, "         ",
if SellExit >= 1 and RTH then Color.LIGHT_GREEN else Color.WHITE);




AddLabel (ADXLogic and simpleLabels,
if Logic == 2 then "  Modified Logic  " else "   Normal Logic   ", Color.WHITE);


#======== EOF =========================================================================
 
Looks like you do have the adxLogic setting set to yes. In the input settings change that to no and it wont change the logic. If you load adx lower indicator it will make more sense.

https://usethinkscript.com/threads/...ge-strategy-for-thinkorswim.13562/post-117322

BTW, I used this strategy to scalp SPX on Friday and I profited 1,700.00 by just buying option buys and puts at the 2nd sar dot. I did lose 630.00 on one trade because I was stupid and did not keep track of the other confirmations I use. I use a chop lower indicator that told me not to buy when I did. I FOMO'd in and paid for it. The 1700.00 was the final profit on the day. I think I got the labels to work but still having issues with them staying "lit". I eventually would like to test and possibly use this strat for auto trading with Macro Recorder so I need for the labels to trigger and then go white until the close trigger. Rinse and repeat. The way that @dap711 set up the labels in this thread ( https://usethinkscript.com/threads/...le-strategy-for-thinkorswim.14072/post-117569 ) works awesome for the Macro Recorder.

One other note, I do get quite a bit of random trigger in various areas that don't seem to make since. Maybe, I do not understand the actual reason. This would not work with an auto trade feature. Thank you for this strat!
 
Last edited:
Looks like you do have the adxLogic setting set to yes. In the input settings change that to no and it wont change the logic. If you load adx lower indicator it will make more sense.

https://usethinkscript.com/threads/...ge-strategy-for-thinkorswim.13562/post-117322
I use TTM Squeeze with this stragety and the damn thing works so good Im making profit everyday. I use it on CL 1min and NQ 1min. I use 1min to take trades on SPX. Wait for the TTM Squeeze to fire in the direction of the trade. I have no idea how to insert images here. Tried dopy and pasting.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
424 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top