billionmetrics
New member
@SilverWolf, thank you for your response.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.
@SilverWolf, thank you for your response.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.
@SilverWolf I am trying this code but nothing is appearing on my chart. could you please help on this or share working import linkThank You.
You need to use it as a strategy not a study@SilverWolf I am trying this code but nothing is appearing on my chart. could you please help on this or share working import link
thanks for helpingYou need to use it as a strategy not a study
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
thanks , I am new to this toolFrom 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
Hello,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
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.
Examples of ticker include /ES SPY , QQQ , TSLA , AAPL.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
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.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:
2nd idea
- For all entries, ADX > 25.
- For long entries, DI+ > DI-.
- For short entries DI- > DI+.
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
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
Dot mu
thanks for explainingExamples 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
The post here is correct: https://usethinkscript.com/threads/...e-strategy-for-thinkorswim.13562/#post-114557With 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?
#======== 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 ============================================================================
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)
All of the posts in this thread have been corrected.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 ============================================================================
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: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));
then " BUY " else " ",
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);
did he updated the logic from the version 2 . As you said results are reduced , I copy the latest one by Moderator and I see the results are almost half. which one is good to use ?it works! the results have been significantly reduced
I think Merryday the mod updated the logic? The price was changed to the open of the previous candle as opposed to the current candle ( which looks nice when you backtest but you can't do that in real time. )did he updated the logic from the version 2 . As you said results are reduced , I copy the latest one by Moderator and I see the results are almost half. which one is good to use ?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.