ParabolicSAR - PSAR Moving Average Strategy For ThinkOrSwim

I'm using your strategy to trade but using other indicators to confirm trades.
So far so good? Im still papertrading atm. I can report amazing days and bad days.. Im working toward consistency. What other indicators do you like with this?

Here is a snippet of the logic I am developing totally in testing right now.

CSS:
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;
 

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

So far so good? Im still papertrading atm. I can report amazing days and bad days.. Im working toward consistency. What other indicators do you like with this?

Here is a snippet of the logic I am developing totally in testing right now.

CSS:
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;
Im using TTM Squeeze and another indicator created by a friend but I did modify a bit. I called it Kang Indicator named after a person who is a great trader. He uses the 34 and 89 moving averages with RSI. Posted below

declare lower;

input PoopieMALength = 20;
input PoopieAverageType = AverageType.SIMPLE;
input ShowLabel = yes;


def SMA_34 = MovAvgExponential(length=34);
def SMA_89 = MovAvgExponential(length = 89);

Plot momentum = (SMA_34 - SMA_89);

# plot the RSI Moving Average
def PoopiersiMA = MovingAverage(PoopieAverageType, momentum, PoopieMALength);
plot pooprsiMA = poopiersima;
pooprsima.AssignValueColor(if poopiersima > poopiersima[2] then Color.GREEN else if poopiersima < poopiersima[2] then Color.RED else Color.GRAY);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.DefineColor("Positive and Up", Color.GREEN);
momentum.DefineColor("Positive and Down", Color.DARK_GREEN);
momentum.DefineColor("Negative and Down", Color.RED);
momentum.Defin…
 
So far so good? Im still papertrading atm. I can report amazing days and bad days.. Im working toward consistency. What other indicators do you like with this?

Here is a snippet of the logic I am developing totally in testing right now.

CSS:
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;
Can you please post complete code with these changes?
 
Its not perfect and if someone has a better way please advise
try this:
CSS:
input simpleLabels = no;
AddLabel (simpleLabels,
if BuySignal  then  "         " else   "         ",
if BuySignal  then Color.GREEN else Color.WHITE);
AddLabel (simpleLabels,
if BuyExit then  "         " else   "         ",
if BuyExit then Color.MAGENTA else Color.WHITE);
AddLabel (simpleLabels,
if SellSignal then  "         " else   "         ",
if SellSignal then Color.RED else Color.WHITE);
AddLabel (simpleLabels,
if SellExit then  "         " else   "         ",
if SellExit then Color.LIGHT_GREEN else Color.WHITE);
Thank You.
 
@SilverWolf thanks for the stragety. Would it be possilbe to add color labels for buy, sell and close for the strategy to auto trade on macro recorder. Thanks.
That’s a excellent idea, I was trying to do something with Ema 5 to a 1 minute chart are you able to write that code?
 
I was able to convert this code into python auto trading strategy over the weekend. I will test this week and will report back how good the results are. Even if they are half of what they are on TOS should be a profitable stragety.
 
Dear @HenryK, I have tried to make an auto strategy in Macro Recorder. It works well while waiting for the colour specified, clicks precisely the Buy, Flatten or Sell Button, but I was unable to make the strategy click only once per direction and to wait till the new color emerges. Can you share your auto trader script in Macro Recorder. Mine is shared, but it is not working as expected. Thank you in advance, Nelly
@NellyN , I haven’t had chance to load up macro recorder. I am not getting color coded buy, sell or close on tos chart as you see in my above post. So I am not able to use it yet with macro recorder. If you can share your tos code that gives color coded buy, sell and close label it would very helpful to me.

However, @dap711 has this .mrf file for macro recorder posted in other strategy that he had developed. I was gonna use it for this strategy. See if it helps you.

https://drive.google.com/file/d/13iG-OSO21UsMVRQDVPHb0BO0EfP2WrEC/view?usp=sharing


Thanks.
 
Good work. I spent time reviewing the results. Are the exits correct? They seem to be off by approx 4 to 6 ticks depending on the chart. If they are correct, what conditions have you coded for the exit?
Thanks.
 
I am trying to make a label that appears at the buy candle and disappears after that but it is not showing at all. Can anyone guide me? Thanks

Code:
AddLabel(BuySignal,  "     BUY      ", CreateColor(153, 255, 153));
AddLabel(BuyExit, "     CLOSE     ", CreateColor(102, 0, 0));
 
I have tried to modify and use it and @dap711 was kind and helpful. The strategy buys numerous times and sells. Even with a limitation to open 1 contract only and to work once. It opens one contract and immediately closes and loops.


Use for starting point one of the @dap711 strategies. The labels are part of the code of the strategies. Then modify the script. I used only mouse click and deleted the key combinations as the author suggested and also the Reverse signal. Nevertheless everything worked well, but the script buys and closes numerous times per minute. For the time being I do not see a working solution. When there is limitation to open only 1 contract, the script opens and closes 1 contract constantly.
You may also try the AHK algo trading script written by @SilverWolf. Good luck!
Thanks @NellyN for detailed explation. Sure Macro recorder is something new for me so will have to play around with it.
 
Last edited by a moderator:
So far so good? Im still papertrading atm. I can report amazing days and bad days.. Im working toward consistency. What other indicators do you like with this?

Here is a snippet of the logic I am developing totally in testing right now.

CSS:
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;
Hello @SilverWolf, I am new to this forum and also to day trading. This strategy is amazing. I have used it on SPY and it is very very useful. Looking forward to your upgrades. Big thanks for sharing.

If I may ask 1 question, please. What is the default settings you use and do you change it for different time frames. Please share your recommendations.
 
Improved/Corrected Entry and Exit orders. Works well on mobile too

CSS:
# 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;

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 = 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 = 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 ===================================================================


input Price = close;#{default Close, Open, high[1] + low[1]/2};



AddOrder(OrderType.BUY_TO_OPEN, BuySignal, Price[1], TradeSize, Color.GREEN, Color.GREEN, name = "Long");

AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, Price[1], TradeSize, Color.RED, Color.RED, name = "Close");

AddOrder(OrderType.SELL_TO_OPEN, SellSignal, Price[1], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short");

AddOrder(OrderType.BUY_TO_CLOSE, SellExit, Price[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 ===========================================================================
could you please share the import link and your chart settings? I use this code and i dont see anything

I'm using your strategy to trade but using other indicators to confirm trades.


Im using TTM Squeeze and another indicator created by a friend but I did modify a bit. I called it Kang Indicator named after a person who is a great trader. He uses the 34 and 89 moving averages with RSI. Posted below

declare lower;

input PoopieMALength = 20;
input PoopieAverageType = AverageType.SIMPLE;
input ShowLabel = yes;


def SMA_34 = MovAvgExponential(length=34);
def SMA_89 = MovAvgExponential(length = 89);

Plot momentum = (SMA_34 - SMA_89);

# plot the RSI Moving Average
def PoopiersiMA = MovingAverage(PoopieAverageType, momentum, PoopieMALength);
plot pooprsiMA = poopiersima;
pooprsima.AssignValueColor(if poopiersima > poopiersima[2] then Color.GREEN else if poopiersima < poopiersima[2] then Color.RED else Color.GRAY);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.DefineColor("Positive and Up", Color.GREEN);
momentum.DefineColor("Positive and Down", Color.DARK_GREEN);
momentum.DefineColor("Negative and Down", Color.RED);
momentum.Defin…
can you provide shareable link for full indicator, i try to use this code but not worked and what time frame you use
 
Last edited:
could you please share the import link and your chart settings? I use this code and i dont see anything





can you provide shareable link for full indicator, i try to use this code but not worked and what time frame you use
You can find TTM squeeze indicator in this forum, I have given the code for the other I use.
 
You can find TTM squeeze indicator in this forum, I have given the code for the other I use.
i see some error Invalid statement: momentum at 21:1
is it full code
# plot the RSI Moving Average
def PoopiersiMA = MovingAverage(PoopieAverageType, momentum, PoopieMALength);
plot pooprsiMA = poopiersima;
pooprsima.AssignValueColor(if poopiersima > poopiersima[2] then Color.GREEN else if poopiersima < poopiersima[2] then Color.RED else Color.GRAY);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.DefineColor("Positive and Up", Color.GREEN);
momentum.DefineColor("Positive and Down", Color.DARK_GREEN);
momentum.DefineColor("Negative and Down", Color.RED);
momentum.Defin…
 
Last edited:
I'm using your strategy to trade but using other indicators to confirm trades.
declare lower;

input PoopieMALength = 20;
input PoopieAverageType = AverageType.SIMPLE;
input ShowLabel = yes;


def SMA_34 = MovAvgExponential(length=34);
def SMA_89 = MovAvgExponential(length = 89);

Plot momentum = (SMA_34 - SMA_89);

# plot the RSI Moving Average
def PoopiersiMA = MovingAverage(PoopieAverageType, momentum, PoopieMALength);
plot pooprsiMA = poopiersima;
pooprsima.AssignValueColor(if poopiersima > poopiersima[2] then Color.GREEN else if poopiersima < poopiersima[2] then Color.RED else Color.GRAY);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.DefineColor("Positive and Up", Color.GREEN);
momentum.DefineColor("Positive and Down", Color.DARK_GREEN);
momentum.DefineColor("Negative and Down", Color.RED);
momentum.DefineColor("Negative and Up", Color.DARK_RED);
momentum.AssignValueColor(if momentum >= 0 then if momentum > momentum[1] then momentum.color("Positive and Up") else momentum.color("Positive and Down") else if momentum < momentum[1] then momentum.color("Negative and Down") else momentum.color("Negative and Up"));
plot line = 0;
line.SetDefaultColor(Color.WHITE);
#line.SetStyle (Curve.FIRM);

AddLabel(yes, "Momentum:" + Round(momentum,2) + " ",(if momentum > 0 then Color.GREEN else Color.RED));
 
Hello @SilverWolf, I am new to this forum and also to day trading. This strategy is amazing. I have used it on SPY and it is very very useful. Looking forward to your upgrades. Big thanks for sharing.

If I may ask 1 question, please. What is the default settings you use and do you change it for different time frames. Please share your recommendations.
I tweak the settings every day. A lot of the times I keep the logic settings the same and just adjust the tick chart as well.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
187 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