ParabolicSAR - PSAR Moving Average Strategy For ThinkOrSwim

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.
 
Last edited:
thanks for helping
and anyone know what is stop loss logic here and best time frame for this . does it only for ES or tested on other instrument

From the original version in the original post ( @SilverWolf should considering giving versions to this already)

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

# if the buy signal was set, then set the stop loss to previous candle's low.

def buyStopLoss = if IsNaN(close) then buyStopLoss[1] else if !IsNaN(BuySignal) == 1 then low[1] else buyStopLoss[1];

#plot xbuystoploss = buyStopLoss; #Remember to hide on mobile app
#xbuystoploss.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# if the sell signal was set, then set the stop loss to previous candle's high.

You can try the strategy on various tickers and see what the Pnl is at various timeframes
After you have loaded in the strategy and it runs m you can go back to edit studies and strategies : Global strategy settings and tick Floating PL study with strategies

 
From the original version in the original post ( @SilverWolf should considering giving versions to this already)

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

# if the buy signal was set, then set the stop loss to previous candle's low.

def buyStopLoss = if IsNaN(close) then buyStopLoss[1] else if !IsNaN(BuySignal) == 1 then low[1] else buyStopLoss[1];

#plot xbuystoploss = buyStopLoss; #Remember to hide on mobile app
#xbuystoploss.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# if the sell signal was set, then set the stop loss to previous candle's high.

You can try the strategy on various tickers and see what the Pnl is at various timeframes
After you have loaded in the strategy and it runs m you can go back to edit studies and strategies : Global strategy settings and tick Floating PL study with strategies

thanks , I am new to this tool
what is ticker and where I can find this information and I see two green arrows one bug green arrow before signal which one the signal to take trade
 
thanks , I am new to this tool
what is ticker and where I can find this information and I see two green arrows one bug green arrow before signal which one the signal to take trade
Hello,

These are my understanding. Bar positions are based on logic including evaluating the next candle. @SilverWolf can correct and provide more color.

White arrows represent exit signs. White from the bottom directing up, indicates the exit short position, while white from the top directing below, indicates the exit long position. The green small arrow is a parabolic indicator cross from short to long, while the pink/red small arrow is a parabolic indicator cross from long to short.

Big green or red arrows are trade indicators.

This is one of the well-written strategy providing a simple approach. Thanks to @SilverWolf for sharing this with us.
 
mod note:
This post was edited.
In this forum, we only support the posting of scripts that use the open of the next bar for backtesting. It's important to remember that any strategy that plots on the close of the previous bar is not written correctly and will give you misleading results.
Now, we know it would be amazing to be able to go back in history and place trades after we know the outcome, but unfortunately, that's just not possible. That's why it's crucial to write your strategies using open[-1]. This way, the order price reflects the next moment in time - the open of the following bar. And in the real world, that's the earliest a trade can be placed.

thanks , I am new to this tool
what is ticker and where I can find this information and I see two green arrows one bug green arrow before signal which one the signal to take trade
Examples of ticker include /ES SPY , QQQ , TSLA , AAPL.

You can find this information from the code itself

#======== STRATEGY ORDERS ===================================================================
AddOrder(OrderType.BUY_TO_OPEN, BuySignal, 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, 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);

Alternatively , you can see and change each symbol under customising / plot .
You can do this by right clicking it if it is already in your added studies and strategies



From the documented page :

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

Rules for Long Entry.
Rule #1- Apply indicators to chart
Rule #2- Dot must change to be below price candle. This is a sign that a reversal may be happening.
Rule #3- Another element that must occur is the moving averages must cross over.
In a long trade, the 40 period moving average will cross and go below the 20 period moving average.
Rule #4- Dot must be below price candle AND moving averages cross to where 20 period MA is above 40 period MA.
Note** One of these elements may occur before the other. The reversal dot can appear before the MA lines cross. Or the Moving averages can cross before the reversal candle. As long as we have both elements the entry criteria is met.
Rule #5- Enter Next Price Candle. Enter the very next price candle after the dot appears below candle + MA lines cross and 20 period MA is above 40 period.
Rule #6- Stop loss / Take Profit
The stop loss you will place 30-50 pips away from your entry. Always look for prior resistance or support to determine a stop loss.
Your exit criteria in the example below were when the dot appeared above the candle.

There are changes made by Silverwolf (e.g. Exponential Moving Averages 9 and 21 instead of 20/40).

Entry is done when there is a confluence of multiple rules. That part is indicated by the word Long.
Rule # 1 is done when you apply the strategy ( as seen in your picture)
Rule #2 occurs when the dots are below the price
Rules #3 occurs when there is a crossover in the moving averages
Rule #4 is when both #2 and #3 are met
Rule #5 is why you see two green arrows up
 
Last edited by a moderator:
Here is a suggestion for those who use this idea .
I think ADX /DMI+ DM- is a good way to complement parabolic albeit a bit too tightly.

Still in the process of refining
but here is the idea :

https://www.tradingsetupsreview.com/ultimate-parabolic-sar-trading-guide/

The current ParabolicSAR is with exponential moving average close.

It is good when it is trending but not so good when it is ranging.

Possible idea is to combine it with Increasing / Decreasing ADX as well as DMi+ / DM-

#2: Parabolic SAR + Directional Movement System​


Parabolic SAR + DM Trading Rules

For this strategy, the entry rules are the same as Strategy #1, with these added filter rules:

  • For all entries, ADX > 25.
  • For long entries, DI+ > DI-.
  • For short entries DI- > DI+.
2nd idea
from : https://usethinkscript.com/threads/script-for-an-increasing-or-decreasing-adx-indicator.8079/

You can sum up the secret to using ADX indicator in a single word: SLOPE.

Interpreting ADX Slope
Rising ADX slope means trending market
When prices are moving in one direction, the slope of ADX should stay positive.
Falling ADX points to Ranging Market

for the second idea , I took the idea from : https://usethinkscript.com/threads/script-for-an-increasing-or-decreasing-adx-indicator.8079/

and LBR_SmartADX ( default from TOS)


#### this lower indicator allows you to see both directional changes and whether DM+ or DM- is on top###
#### Rising ADX slope means trending market
#### Falling ADX points to Ranging Market
#### For all entries, ADX > 25.
#### For long entries, DI+ > DI-.
#### For short entries DI- > DI+.

declare lower;

input lengthX = 14;
input averageType = AverageType.Wilders;
input level_1 = 15.0;
input level_2 = 30.0;

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), lengthX);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, lengthX) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, lengthX) / ATR;
#def "DI+" = 100 * MovingAverage(averageType, plusDM, lengthX) / ATR;
#def "DI-" = 100 * MovingAverage(averageType, minusDM, lengthX) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, lengthX);
plot Level1 = level_1;
plot Level2 = level_2;


ADX.SetDefaultColor(Color.Plum);
ADX.DefineColor("Up", Color.Green);
ADX.DefineColor("Down", Color.Red);
ADX.AssignValueColor(if ADX > ADX[1] then ADX.color("Up") else ADX.color("Down"));
ADX.SetLineWeight(3);
##########end of code######

I will backtest a bit to see what I can use to further filter for good trades only
 
Here is a suggestion for those who use this idea .
I think ADX /DMI+ DM- is a good way to complement parabolic albeit a bit too tightly.

Still in the process of refining
but here is the idea :

https://www.tradingsetupsreview.com/ultimate-parabolic-sar-trading-guide/

The current ParabolicSAR is with exponential moving average close.

It is good when it is trending but not so good when it is ranging.

Possible idea is to combine it with Increasing / Decreasing ADX as well as DMi+ / DM-

#2: Parabolic SAR + Directional Movement System​


Parabolic SAR + DM Trading Rules

For this strategy, the entry rules are the same as Strategy #1, with these added filter rules:

  • For all entries, ADX > 25.
  • For long entries, DI+ > DI-.
  • For short entries DI- > DI+.
2nd idea
from : https://usethinkscript.com/threads/script-for-an-increasing-or-decreasing-adx-indicator.8079/

You can sum up the secret to using ADX indicator in a single word: SLOPE.

Interpreting ADX Slope
Rising ADX slope means trending market
When prices are moving in one direction, the slope of ADX should stay positive.
Falling ADX points to Ranging Market

for the second idea , I took the idea from : https://usethinkscript.com/threads/script-for-an-increasing-or-decreasing-adx-indicator.8079/

and LBR_SmartADX ( default from TOS)


#### this lower indicator allows you to see both directional changes and whether DM+ or DM- is on top###
#### Rising ADX slope means trending market
#### Falling ADX points to Ranging Market
#### For all entries, ADX > 25.
#### For long entries, DI+ > DI-.
#### For short entries DI- > DI+.

declare lower;

input lengthX = 14;
input averageType = AverageType.Wilders;
input level_1 = 15.0;
input level_2 = 30.0;

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), lengthX);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, lengthX) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, lengthX) / ATR;
#def "DI+" = 100 * MovingAverage(averageType, plusDM, lengthX) / ATR;
#def "DI-" = 100 * MovingAverage(averageType, minusDM, lengthX) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
plot ADX = MovingAverage(averageType, DX, lengthX);
plot Level1 = level_1;
plot Level2 = level_2;


ADX.SetDefaultColor(Color.Plum);
ADX.DefineColor("Up", Color.Green);
ADX.DefineColor("Down", Color.Red);
ADX.AssignValueColor(if ADX > ADX[1] then ADX.color("Up") else ADX.color("Down"));
ADX.SetLineWeight(3);
##########end of code######

I will backtest a bit to see what I can use to further filter for good trades only
Thank you for sharing. I am new to ToS as well but learning through this forum, which is amazing. I took the smart supertrend from this forum and applied that to this strategy to learn. Using both on a visual basis, not by single code, I could see how I can reduce some of the short trades. ADX may be a better option, which I will try and learn.

If we can add stop loss and profit target versions to the strategy, it would help.
 
Examples of ticker include /ES SPY , QQQ , TSLA , AAPL.

You can find this information from the code itself

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


input Price = open[-1] ;



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

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

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

AddOrder(OrderType.BUY_TO_CLOSE, SellExit, Price, 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);

Alternatively , you can see and change each symbol under customising / plot .
You can do this by right clicking it if it is already in your added studies and strategies



From the documented page :

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

Rules for Long Entry.
Rule #1- Apply indicators to chart
Rule #2- Dot must change to be below price candle. This is a sign that a reversal may be happening.
Rule #3- Another element that must occur is the moving averages must cross over.
In a long trade, the 40 period moving average will cross and go below the 20 period moving average.
Rule #4- Dot must be below price candle AND moving averages cross to where 20 period MA is above 40 period MA.
Note** One of these elements may occur before the other. The reversal dot can appear before the MA lines cross. Or the Moving averages can cross before the reversal candle. As long as we have both elements the entry criteria is met.
Rule #5- Enter Next Price Candle. Enter the very next price candle after the dot appears below candle + MA lines cross and 20 period MA is above 40 period.
Rule #6- Stop loss / Take Profit
The stop loss you will place 30-50 pips away from your entry. Always look for prior resistance or support to determine a stop loss.
Your exit criteria in the example below were when the dot appeared above the candle.

There are changes made by Silverwolf (e.g. Exponential Moving Averages 9 and 21 instead of 20/40).

Entry is done when there is a confluence of multiple rules. That part is indicated by the word Long.
Rule # 1 is done when you apply the strategy ( as seen in your picture)
Rule #2 occurs when the dots are below the price
Rules #3 occurs when there is a crossover in the moving averages
Rule #4 is when both #2 and #3 are met
Rule #5 is why you see two green arrows up

@Wockets, your explanation was more detailed than my short notes. Thanks for taking the time to do that.
 

Examples of ticker include /ES SPY , QQQ , TSLA , AAPL.

You can find this information from the code itself

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


input Price = open[-1] ;



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

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

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

AddOrder(OrderType.BUY_TO_CLOSE, SellExit, Price, 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);

Alternatively , you can see and change each symbol under customising / plot .
You can do this by right clicking it if it is already in your added studies and strategies



From the documented page :

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

Rules for Long Entry.
Rule #1- Apply indicators to chart
Rule #2- Dot must change to be below price candle. This is a sign that a reversal may be happening.
Rule #3- Another element that must occur is the moving averages must cross over.
In a long trade, the 40 period moving average will cross and go below the 20 period moving average.
Rule #4- Dot must be below price candle AND moving averages cross to where 20 period MA is above 40 period MA.
Note** One of these elements may occur before the other. The reversal dot can appear before the MA lines cross. Or the Moving averages can cross before the reversal candle. As long as we have both elements the entry criteria is met.
Rule #5- Enter Next Price Candle. Enter the very next price candle after the dot appears below candle + MA lines cross and 20 period MA is above 40 period.
Rule #6- Stop loss / Take Profit
The stop loss you will place 30-50 pips away from your entry. Always look for prior resistance or support to determine a stop loss.
Your exit criteria in the example below were when the dot appeared above the candle.

There are changes made by Silverwolf (e.g. Exponential Moving Averages 9 and 21 instead of 20/40).

Entry is done when there is a confluence of multiple rules. That part is indicated by the word Long.
Rule # 1 is done when you apply the strategy ( as seen in your picture)
Rule #2 occurs when the dots are below the price
Rules #3 occurs when there is a crossover in the moving averages
Rule #4 is when both #2 and #3 are met
Rule #5 is why you see two green arrows up
thanks for explaining
 
With regards to what the moderator said," That's why it's crucial to write your strategies using open[-1]."
I thought I've copied the code directly from version 2 of silver wolf's code. Is there a change to version 2?
 
Last edited by a moderator:
With regards to what the moderator said," That's why it's crucial to write your strategies using open[-1]."
I thought I've copied the code directly from version 2 of silver wolf's code. Is there a change to version 2?
The post here is correct: https://usethinkscript.com/threads/...e-strategy-for-thinkorswim.13562/#post-114557
Please update your version. You will find the backtesting results are not "as amazing" but more realistic.

We stuff open[-1] directly into the addorder statement (which is the way the thinkscript manual instructs)
Ruby:
#======== STRATEGY ORDERS ===================================================================
AddOrder(OrderType.BUY_TO_OPEN, BuySignal, 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, 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 ============================================================================
All of the posts in this thread have been corrected.
 
Last edited:
The post here is correct: https://usethinkscript.com/threads/...e-strategy-for-thinkorswim.13562/#post-114557
Please update your version. You will find the backtesting results are not "as amazing" but more realistic.

We stuff open[-1] directly into the addorder statement (which is the way the thinkscript manual instructs)
Ruby:
#======== STRATEGY ORDERS ===================================================================
AddOrder(OrderType.BUY_TO_OPEN, BuySignal, 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, 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 ============================================================================
All of the posts in this thread have been corrected.

it works! the results have been significantly reduced :(
 
Last edited by a moderator:
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));
The only way that I have found to have a consistent label is to put the logic in the condition instead of the "BuySignal" I use blank labels... see below but you could easily add text in first quotes like this:
CSS:
then "    BUY     " else "         ",


CSS:
input TheLabelsOn = yes;
#Buy
AddLabel(TheLabelsOn,
if Trend == 1 and (close > TriggerAVG) and (SAR crosses below close)
or Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close)
then "         " else "         ",
if Trend == 1 and (close > TriggerAVG) and (SAR crosses below close)
or Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close)
then Color.GREEN else Color.WHITE);

#BuyClose
AddLabel(TheLabelsOn,
if Closer == 1 and (SAR > close)
or  Closer == 2 and (close < TriggerAVG) then "         " else "         ",
if Closer == 1 and (SAR > close)
or  Closer == 2 and (close < TriggerAVG) then Color.MAGENTA else Color.WHITE);

#Sell
AddLabel(TheLabelsOn,
if Trend == 1 and (close < TriggerAVG) and (SAR crosses above close)
or Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close)
then "         " else "         ",
if Trend == 1 and (close < TriggerAVG) and (SAR crosses above close)
or Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close)
then Color.RED else Color.WHITE);

#SellClose
AddLabel(TheLabelsOn,
if Closer == 1 and (SAR < close)
or Closer == 2 and (close > TriggerAVG) then "         " else "         ",
if Closer == 1 and (SAR < close)
or Closer == 2 and (close > TriggerAVG) then Color.LIGHT_GREEN else Color.WHITE);
 
@SilverWolf, if you don't mind, may I please ask you a question? I see the buy and sell signals are triggered when SAR crosses below or above, but this with close compared with the trigger avg, and has a chance to miss a trade when it doesn't extract cross. Would it work if we simply compare > or < appropriately? Are there any disadvantages to doing that? Thanks for taking the time to read this and in advance for your reply.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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