SilverWolf
Member
Sure can! Great tradeLearned something today. Anyone see the chart?
Sure can! Great tradeLearned something today. Anyone see the chart?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Even though stragety is into the trade wait for the TTM to fire off. Once the trade is taken wait for the next time the TTM fire offs again to get into another trade. Too bad we don't have direct chat. They do have Discord for this but you have to be a VIP member to be on it. Im sure they have to pay lot of money to maintain this website. I congratulate those who do. wealth of info here. I went from nothing knowing any of this stuff to writing my own stargeties.Sure can! Great trade
When I get home I can load yours up with the settings and see if I can see that anomaly. Open close is for exactly that. Low volume price action can have its own rules.Interesting. I did turn the ADX on and off and still got some of the random triggers. This is the ADX indicator I use:
Also, I notice that a lot of coders put in an open and close time. What is the main purpose of that? Is it to just weed out the after market data?
Code:#ADX-Color declare lower; input length = 14; input averageType = AverageType.WILDERS; plot ADX = DMI(length, averageType).ADX; ADX.setDefaultColor(color.blue); plot line = 25; line.setDefaultColor(color.white); AddCloud(ADX, 25, color.green, color.red);
There is a lot that goes into this but briefly.. I would load up the adx lower and change the settings to match the price action. What you want is the adx to be below the mom(filter). Using the color bars on the adx can help you get this part right. once those settings are determined. put those in the strategy settings and turn on adxLogic. I trade /es. Interesting note this process has to be tweaked constantly.. what worked two days ago might not work today.. Volume has a lot to do with it and so does timing. If you can find a better way to tell the strat when the price action is trending sideway or consolidating PLEASE let me know.Okay. I did mess around with the feature quite a bit to see if I could get better results. I will just turn it off for now. I did however, like the chart you showed where it worked in the chop ( https://usethinkscript.com/threads/...ge-strategy-for-thinkorswim.13562/post-117358) You referred to it as ADX Logic 2. How did you get that to work
Sorry for all of the questions. When you refer to color bar on, do you mean the setting in the strategy?
What does mom actually stand for/mean? I have not seen that reference before. I did mess with it but have no idea what I am adjusting.
Yeah, it is a bit of a pain to adjust the setting every day. It would be awesome if there was a way to automate the best settings but that is a pipe dream. One thing I have noticed though, is when I make all of the adjustments to get the Floating P/L to the best I can, I have noticed that the entries and exits don't really change enough to make a huge difference. Enlighten me please if you have any input about this.
Also, What is Blink? How does it apply?
I used the ASAP with better success but also had some bad days so I was really waiting to see if it could be optimized. The one I am using now is the Parabolic SARS by @SilverWolf and I have had really good success with it. It is a work in progress. At the moment I am hoping someone will help out with the labels so they will work with the Macro Recorder. It has Buy, Sell, Close Labels but they stay "Lit" and MR will just keep buying. I made 1700.00 profit on Friday using it scalping SPX. I did have a loss of 630.00 but it was really my fault as I did not focus on my other indicators that I use for confirmation. I use a few different lower indicators in order to confirm/weed out bad trades. It does trigger incorrectly at times in choppy zones but that is to be expected for most all strategies.
Not the best solution but set a signal condition with a trade starting date and end date
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
I am having the exact same issue. My labels stay painted long after the close of the candle.
# 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 > TriggerAVG) and (SAR crosses below close)
then 1
else 0;
#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 < TriggerAVG) and (SAR crosses above close)
then 1
else 0;
#else Double.NaN;
def BuyExit = if Closer == 1 and (close crosses below SAR[-1])
then 1
else if Closer == 2 and (TriggerAVG crosses above CrossingAVG)
then 1
else 0;
#else Double.NaN;
def SellExit = if Closer == 1 and (close crosses above SAR[-1])
then 1
else if Closer == 2 and (TriggerAVG crosses below CrossingAVG)
then 1
else 0;
#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[0], 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[0], 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);
#======== 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 ===========================================================================
input LabelsOn = Yes;
#Buy
AddLabel(LabelsOn, " ", if Trend == 1 and (close > TriggerAVG) and (SAR < close) or Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR < close) then Color.GREEN else Color.WHITE);
#Buy Close
AddLabel(LabelsOn, " ", if Closer == 1 and (SAR > close) or Closer == 2 and (low < TriggerAVG) then Color.YELLOW else Color.WHITE);
#Sell
AddLabel(LabelsOn, " ", if Trend == 1 and (close < TriggerAVG) and (SAR > close) or Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR > close) then Color.RED else Color.WHITE);
#Sell Close
AddLabel(LabelsOn, " ", if Closer == 1 and (SAR < close) or Closer == 2 and (low > TriggerAVG) then Color.YELLOW else Color.WHITE);
#======== EOF =========
mod note: OnDemand could be the problem. Review on live trading and report back.Thanks for working on this. That is getting close. Unless there is an issue testing with OnDemand, the labels are still staying triggered. In order to use them with Macro Recorder they will need to work simiolar to this video provided by @dap711, https://drive.google.com/file/d/1uq1IMBaUw96mFSAgL02d1LQcJT_3V8W_/view?usp=sharing.
I suspect Ondemand as well. If you look at the signal code I used "this crossed that" That should only be true briefly.Thanks for working on this. That is getting close. Unless there is an issue testing with OnDemand, the labels are still staying triggered. In order to use them with Macro Recorder they will need to work simiolar to this video provided by @dap711, https://drive.google.com/file/d/1uq1IMBaUw96mFSAgL02d1LQcJT_3V8W_/view?usp=sharing.
@SilverWolf Here is the version I am using. I just changed the names of the triggers from Long to "Buy"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 =========================================================================
# 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 = "Sell" + 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, "", 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.LIGHT_GREEN 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.LIGHT_GREEN else Color.WHITE);
AddLabel (AdvLabelsOn or simpleLabels,
if Logic == 2 then " Modified Logic " else " Normal Logic ", Color.WHITE);
#======== EOF =========================================================================
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.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.
Interesting. I did turn the ADX on and off and still got some of the random triggers. This is the ADX indicator I use: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
#ADX-Color
declare lower;
input length = 14;
input averageType = AverageType.WILDERS;
plot ADX = DMI(length, averageType).ADX;
ADX.setDefaultColor(color.blue);
plot line = 25;
line.setDefaultColor(color.white);
AddCloud(ADX, 25, color.green, color.red);
You have to use to upload image and then press the 3 dots and select forum code to add images. I would like too compare your settings to mine. I also use the 1m TF but have been testing th 3 and it is quite impressive. I am not sure why the imgur.com link isn't working. it is imgur(dot)com/UploadI 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.
Okay. I did mess around with the feature quite a bit to see if I could get better results. I will just turn it off for now. I did however, like the chart you showed where it worked in the chop ( https://usethinkscript.com/threads/...ge-strategy-for-thinkorswim.13562/post-117358) You referred to it as ADX Logic 2. How did you get that to work?When I get home I can load yours up with the settings and see if I can see that anomaly. Open close is for exactly that. Low volume price action can have its own rules.
EDIT:
Looks like that was it... That feature is totally not needed unless you want to tweak and test the idea.
Sorry for all of the questions. When you refer to color bar on, do you mean the setting in the strategy?There is a lot that goes into this but briefly.. I would load up the adx lower and change the settings to match the price action. What you want is the adx to be below the mom(filter). Using the color bars on the adx can help you get this part right. once those settings are determined. put those in the strategy settings and turn on adxLogic. I trade /es. Interesting note this process has to be tweaked constantly.. what worked two days ago might not work today.. Volume has a lot to do with it and so does timing. If you can find a better way to tell the strat when the price action is trending sideway or consolidating PLEASE let me know.
Hmm. Is there a way to just make the labels change color when triggered but then go back to white. So far, I have noticed they just stay there color for a while. I am trying to test this with Macro Recorder and the issue is that it will keep placing orders as long as the label is "Lit". Hopefully, someone can assist with this.Mom is kinda referring to momentum... over the filter line means there is momentum. Blink will change the color of the Title label on every new bar. I doesnt do anything to trading
I used the ASAP with better success but also had some bad days so I was really waiting to see if it could be optimized. The one I am using now is the Parabolic SARS by @SilverWolf and I have had really good success with it. It is a work in progress. At the moment I am hoping someone will help out with the labels so they will work with the Macro Recorder. It has Buy, Sell, Close Labels but they stay "Lit" and MR will just keep buying. I made 1700.00 profit on Friday using it scalping SPX. I did have a loss of 630.00 but it was really my fault as I did not focus on my other indicators that I use for confirmation. I use a few different lower indicators in order to confirm/weed out bad trades. It does trigger incorrectly at times in choppy zones but that is to be expected for most all strategies.@METAL @dap711 - with quite a few variations of Dap711 work out there, would love to hear which one of these you are seeing produce most consistent results. I continue to test the ASAP original with my morning grid set up (mentioned above) and find tight 1 penny bid/ask spreads stocks to deploy it on. Last week was hit and miss with a few chop days, but overall the ASAP OG strategy is producing good results.
Have you guys tried to program MR to run multiple assets at once ?
@dap711 - have you played around with the Option Alpha Bots service at all? Is it possible to recreate your work via their Bot service ?
Would love to hear your progress.
I am having the exact same issue. My labels stay painted long after the close of the candle.I don't know coding but wanting to learn it one day. Can anyone help to fix a label to change a color back to WHITE after a buy/sell/Flatten button has been clicked. See codes below
# 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 > TriggerAVG) and (SAR crosses below 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 < TriggerAVG) and (SAR crosses above 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 crosses above 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 crosses below 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[0], 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[0], 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);
#======== 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 ===========================================================================
input LabelsOn = Yes;
#Buy
AddLabel(LabelsOn, " ", if Trend == 1 and (close > TriggerAVG) and (SAR < close) or Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR < close) then Color.GREEN else Color.WHITE);
#Buy Close
AddLabel(LabelsOn, " ", if Closer == 1 and (SAR > close) or Closer == 2 and (low < TriggerAVG) then Color.YELLOW else Color.WHITE);
#Sell
AddLabel(LabelsOn, " ", if Trend == 1 and (close < TriggerAVG) and (SAR > close) or Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR > close) then Color.RED else Color.WHITE);
#Sell Close
AddLabel(LabelsOn, " ", if Closer == 1 and (SAR < close) or Closer == 2 and (low > TriggerAVG) then Color.YELLOW else Color.WHITE);
#======== EOF =========
Thanks for working on this. That is getting close. Unless there is an issue testing with OnDemand, the labels are still staying triggered. In order to use them with Macro Recorder they will need to work simiolar to this video provided by @dap711, https://drive.google.com/file/d/1uq1IMBaUw96mFSAgL02d1LQcJT_3V8W_/view?usp=sharing.
I changed the Signal code see below the last line on each to "else 0" instead of double.nan. Try that out.. If I am understanding was the label going black and disappearing? Please describe if not.
@ConCac and @METAL
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 > TriggerAVG) and (SAR crosses below close) then 1 else 0; #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 < TriggerAVG) and (SAR crosses above close) then 1 else 0; #else Double.NaN; def BuyExit = if Closer == 1 and (close crosses below SAR[-1]) then 1 else if Closer == 2 and (TriggerAVG crosses above CrossingAVG) then 1 else 0; #else Double.NaN; def SellExit = if Closer == 1 and (close crosses above SAR[-1]) then 1 else if Closer == 2 and (TriggerAVG crosses below CrossingAVG) then 1 else 0; #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[0], 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[0], 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); #======== 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 =========================================================================== input LabelsOn = Yes; #Buy AddLabel(LabelsOn, " ", if Trend == 1 and (close > TriggerAVG) and (SAR < close) or Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR < close) then Color.GREEN else Color.WHITE); #Buy Close AddLabel(LabelsOn, " ", if Closer == 1 and (SAR > close) or Closer == 2 and (low < TriggerAVG) then Color.YELLOW else Color.WHITE); #Sell AddLabel(LabelsOn, " ", if Trend == 1 and (close < TriggerAVG) and (SAR > close) or Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR > close) then Color.RED else Color.WHITE); #Sell Close AddLabel(LabelsOn, " ", if Closer == 1 and (SAR < close) or Closer == 2 and (low > TriggerAVG) then Color.YELLOW else Color.WHITE); #======== EOF =========
I will test live and let you know how it works. ThanksI suspect Ondemand as well. If you look at the signal code I used "this crossed that" That should only be true briefly.
am i doing something wrong ..i added it as study ..in mobile version it works fine but not on desktopYes, I'm testing this version
This is a strategyam i doing something wrong ..i added it as study ..in mobile version it works fine but not on desktop
@SilverWolf Thank you for adding the labels. I tried it on a real time trading and the BuyClose/SellClose labels are still remain triggered. It should turn off after the next bar.@SilverWolf Here is the version I am using. I just changed the names of the triggers from Long to "Buy"
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 = "Sell" + 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, "", 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.LIGHT_GREEN 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.LIGHT_GREEN else Color.WHITE); AddLabel (AdvLabelsOn or simpleLabels, if Logic == 2 then " Modified Logic " else " Normal Logic ", Color.WHITE); #======== EOF =========================================================================
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!
Interesting. I did turn the ADX on and off and still got some of the random triggers. This is the ADX indicator I use:
Also, I notice that a lot of coders put in an open and close time. What is the main purpose of that? Is it to just weed out the after market data?
Code:#ADX-Color declare lower; input length = 14; input averageType = AverageType.WILDERS; plot ADX = DMI(length, averageType).ADX; ADX.setDefaultColor(color.blue); plot line = 25; line.setDefaultColor(color.white); AddCloud(ADX, 25, color.green, color.red);
You have to use to upload image and then press the 3 dots and select forum code to add images. I would like too compare your settings to mine. I also use the 1m TF but have been testing th 3 and it is quite impressive. I am not sure why the imgur.com link isn't working. it is imgur(dot)com/Upload
Okay. I did mess around with the feature quite a bit to see if I could get better results. I will just turn it off for now. I did however, like the chart you showed where it worked in the chop ( https://usethinkscript.com/threads/...ge-strategy-for-thinkorswim.13562/post-117358) You referred to it as ADX Logic 2. How did you get that to work?
Sorry for all of the questions. When you refer to color bar on, do you mean the setting in the strategy?
What does mom actually stand for/mean? I have not seen that reference before. I did mess with it but have no idea what I am adjusting.
Yeah, it is a bit of a pain to adjust the setting every day. It would be awesome if there was a way to automate the best settings but that is a pipe dream. One thing I have noticed though, is when I make all of the adjustments to get the Floating P/L to the best I can, I have noticed that the entries and exits don't really change enough to make a huge difference. Enlighten me please if you have any input about this.
Also, What is Blink? How does it apply?
What do you think about the ADX filter or any other filter keeping the order trigger even occurring?
Hmm. Is there a way to just make the labels change color when triggered but then go back to white. So far, I have noticed they just stay there color for a while. I am trying to test this with Macro Recorder and the issue is that it will keep placing orders as long as the label is "Lit". Hopefully, someone can assist with this.
I used the ASAP with better success but also had some bad days so I was really waiting to see if it could be optimized. The one I am using now is the Parabolic SARS by @SilverWolf and I have had really good success with it. It is a work in progress. At the moment I am hoping someone will help out with the labels so they will work with the Macro Recorder. It has Buy, Sell, Close Labels but they stay "Lit" and MR will just keep buying. I made 1700.00 profit on Friday using it scalping SPX. I did have a loss of 630.00 but it was really my fault as I did not focus on my other indicators that I use for confirmation. I use a few different lower indicators in order to confirm/weed out bad trades. It does trigger incorrectly at times in choppy zones but that is to be expected for most all strategies.
I am having the exact same issue. My labels stay painted long after the close of the candle.
Thanks for working on this. That is getting close. Unless there is an issue testing with OnDemand, the labels are still staying triggered. In order to use them with Macro Recorder they will need to work simiolar to this video provided by @dap711, https://drive.google.com/file/d/1uq1IMBaUw96mFSAgL02d1LQcJT_3V8W_/view?usp=sharing.
I will test live and let you know how it works. Thanks
@SilverWolf
Hey, how's your progress in using this indicator?
Could you share with us your progress?
What timeframe/stock do you use ?
How do you use it ?
Any juicy pieces of information for us
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.