SilverWolf
Member
Try it out.. I believe that would work just fine. I originally did that but wanted to refine it to a single bar condition.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
I cant wait to throw real risk into this and very delighted to hear it's working out well for you and others.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. )
Use the updated version , while the results are reduced , I have compared that to the 1st 3 pages of strategies here and it is still the leading strategy by a mile.
the 2nd closest is the https://usethinkscript.com/threads/multi-timeframe-rsi-strategy-indicator-for-thinkorswim.11327/ which repaints. repainting can give false signals in real time but looks picture perfect when you backtest it.
I plan to forward test this on Monday
For the added Critiera , the ADX thick line should be above 25 to trade. ( I removed the bottom line as the strategy was :
For longs ADX line should be blue while the DMI should be blue( that looks like a histogram). Enter when you see long and put the stop loss on the low of the previous candle.
- For all entries, ADX > 25.
- For long entries, DI+ > DI-.
- For short entries DI- > DI+.)
For Shorts ADX line should be white while DMI should be white.
Enter when you see Short and put the stop loss on the high of the previous candle.
# 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 = 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 = 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;
def TrendingUp = if "DI-" > ADX and ADX > "DI+"
then 1
else Double.NaN;
def TrendingDown = if "DI-" > ADX and ADX > "DI+"
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;
#input Price = close; #{default Close, Open, high[1] + low[1]/2};
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");
#AddOrder(OrderType.BUY_TO_OPEN, BuySignal, Price[0], TradeSize, Color.GREEN, Color.GREEN, name = "Long");
#AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, (HighPrice[-1] + LowPrice[-1]) / 2, TradeSize, Color.RED, Color.RED, name = "Long Close");
#AddOrder(OrderType.SELL_TO_OPEN, SellSignal, Price[0], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short");
#AddOrder(OrderType.BUY_TO_CLOSE, SellExit, (HighPrice[-1] + LowPrice[-1]) / 2, TradeSize, Color.WHITE, Color.WHITE, name = "Short 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 ===========================================================================
#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, " ParabolicSAR Strategy Version 01.11 ", if Clock == 0 then Color.WHITE else Color.YELLOW);
AddLabel(!blink and AdvLabelsOn or SimpleLabels, " ParabolicSAR Strategy Version 01.11 ", Color.WHITE);
#Buy
AddLabel(AdvLabelsOn,
if Logic == 1 and Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close) within SarBars bars
or Logic == 1 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars
or Logic == 2 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 2 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars then " " else " ",
if Logic == 1 and Trend == 1 and (close > TriggerAVG) and (SAR crosses below close) within SarBars bars
or Logic == 1 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars
or Logic == 2 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 2 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars then Color.GREEN else Color.WHITE);
#BuyClose
AddLabel(AdvLabelsOn,
if Logic == 1 and Closer == 1 and (SAR > close) within SarBars bars
or Logic == 1 and Closer == 2 and (close < TriggerAVG) within SarBars bars
or Logic == 2 and Closer == 1 and (SAR < close) within SarBars bars
or Logic == 2 and Closer == 2 and (close > TriggerAVG)
or Logic == 1 and Closer == 1 and (adx crosses above mom) within SarBars bars
or Logic == 1 and Closer == 2 and (adx crosses above mom) within SarBars bars
or Logic == 2 and Closer == 1 and (adx crosses below mom) within SarBars bars
or Logic == 2 and Closer == 2 and (adx crosses below mom) within SarBars bars then " " else " ",
if Logic == 1 and Closer == 1 and (SAR > close) within SarBars bars
or Logic == 1 and Closer == 2 and (close < TriggerAVG) within SarBars bars
or Logic == 2 and Closer == 1 and (SAR < close) within SarBars bars
or Logic == 2 and Closer == 2 and (close > TriggerAVG)
or Logic == 1 and Closer == 1 and (adx crosses above mom) within SarBars bars
or Logic == 1 and Closer == 2 and (adx crosses above mom) within SarBars bars
or Logic == 2 and Closer == 1 and (adx crosses below mom) within SarBars bars
or Logic == 2 and Closer == 2 and (adx crosses below mom) within SarBars bars then Color.MAGENTA else Color.WHITE);
#Sell
AddLabel(AdvLabelsOn,
if Logic == 1 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 1 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 2 and Trend == 1 and (close > TriggerAVG) and (SAR crosses below close) within SarBars bars
or Logic == 2 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars then " " else " ",
if Logic == 1 and Trend == 1 and (close < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 1 and Trend == 2 and (close < TriggerAVG) and (CrossingAVG < TriggerAVG) and (SAR crosses above close) within SarBars bars
or Logic == 2 and Trend == 1 and (close > TriggerAVG) and (SAR crosses below close) within SarBars bars
or Logic == 2 and Trend == 2 and (close > TriggerAVG) and (CrossingAVG > TriggerAVG) and (SAR crosses below close) within SarBars bars then Color.RED else Color.WHITE);
#SellClose
AddLabel(AdvLabelsOn,
if Logic == 1 and Closer == 1 and (SAR < close) within SarBars bars
or Logic == 1 and Closer == 2 and (close > TriggerAVG) within SarBars bars
or Logic == 2 and Closer == 1 and (SAR > close) within SarBars bars
or Logic == 2 and Closer == 2 and (close < TriggerAVG)
or Logic == 1 and Closer == 1 and (adx crosses below mom) within SarBars bars
or Logic == 1 and Closer == 2 and (adx crosses below mom) within SarBars bars
or Logic == 2 and Closer == 1 and (adx crosses above mom) within SarBars bars
or Logic == 2 and Closer == 2 and (adx crosses above mom) within SarBars bars then " " else " ",
if Logic == 1 and Closer == 1 and (SAR < close) within SarBars bars
or Logic == 1 and Closer == 2 and (close > TriggerAVG) within SarBars bars
or Logic == 2 and Closer == 1 and (SAR> close) within SarBars bars
or Logic == 2 and Closer == 2 and (close < TriggerAVG)
or Logic == 1 and Closer == 1 and (adx crosses below mom) within SarBars bars
or Logic == 1 and Closer == 2 and (adx crosses below mom) within SarBars bars
or Logic == 2 and Closer == 1 and (adx crosses above mom) within SarBars bars
or Logic == 2 and Closer == 2 and (adx crosses above mom) within SarBars bars then Color.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 =========================================================================
I havent implemented the trendingup or trendingdown yet.. The only thing I have been testing is ADX above and below the filter(mom)If the logic chosen is slope from :
https://www.tradingsetupsreview.com/secret-using-adx-indicator/
then https://usethinkscript.com/threads/...-or-decreasing-adx-indicator.8079/#post-77095 should be looked at
ADX.AssignValueColor(if ADX > ADX[1] then ADX.color("Up") else ADX.color("Down"));
he compares current ADX with previous ADX value.
the switch over here doesn't seem to switch off ?
e.g. if it is trendingup when the conditions are fulfilled , maybe it is a good idea to turn Trendingdown to 0 ? and viceversa
if the logic chosen is :
so perhaps TrendingUp = "DI+" > "DI-" ?
- For all entries, ADX > 25.
- For long entries, DI+ > DI-.
- For short entries DI- > DI+.
Trending Down = "DI-" > "DI+"
declare lower;
input length = 14;
input averageType = AverageType.WILDERS;
input CutOffLine = 25;
def na = Double.NaN;
plot ADX = DMI(length, averageType).ADX;
ADX.SetDefaultColor(GetColor(5));
plot TheLine = if IsNaN(close) then na else CutOffLine;
TheLine.SetDefaultColor(Color.GREEN);
input ColorBars = yes;
AssignPriceColor(if !ColorBars then Color.CURRENT else
if ADX < TheLine then Color.GRAY else
if ADX > TheLine then Color.GREEN else
if ADX > TheLine + 10 then Color.DARK_GREEN else
if ADX < TheLine - 10 then Color.RED else Color.DARK_RED);
input ShowLabel = yes;
AddLabel(ShowLabel and ADX > CutOffLine, Concat(Round(ADX, 1), " | | Trending"), (Color.GREEN));
AddLabel(ShowLabel and ADX < CutOffLine, Concat(Round(ADX, 1), " | | Choppy"), (Color.RED));
Sounds interesting.. See if you can do it. Id like to check it out.How do you implement multiple timeframes into this Parabolic strategy ?
from https://usethinkscript.com/threads/...verlay-for-thinkorswim.1425/page-2#post-14681
seems like you need to get from here :
_______________________________________________________
# Multi-Time-Frame Candle Overlay version 2.4
# 2020 Paul Townsend
# with code from UseThinkScript.com
input agg = AggregationPeriod.fifteen_min; #e.g. this can be the higher timeframe to aggregate e.g. for 1 min , one can pick 5 / 15 / 30 minutes according to TOS's specifications.
input OpenCloseLines = yes;
input HighLowLines = yes;
input HighLowGray = no;
input LineWeight =2;
addlabel(yes,"[" + agg/60000 + "]",color.white);
plot o = open(period = agg);
plot c = close(period = agg);
plot h = high(period = agg);
plot l = low(period = agg);
_________________________________________________________
Maybe can create a second subsection for PSAR and moving average then aggregate from there?
have all the parameters for the same parabolicSAR subsection be named to _higherTimeframe or something likethat
The same goes for Moving average
then for the buying selling signals , the conditions would double for all the conditions to include similar conditions but in a higher timeframe
#======== ParabolicSAR(higher) =========================================================================
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]));
}
}
#======== Moving Averages (higher) ======================================================================
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);
An MTF study is type of repainter. Think about it. You have a 30-min overlay on a five-min chart. There is no way of predicting at what price that 30min candle is going to close. When the 30min candle finally closes, only then can it repaint the previous 6 bars with the 30min close price that you requested."another idea is your trend break idea . got to go sleep , day 2 of CNY hahaha.
I think the problem with multi timeframe is that it would repaint so there isn't an easy way to deal with it . @MerryDay Could you share your opinion on this ?
AddOrder(OrderType.BUY_TO_OPEN, BuySignal, 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, 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);
Thanks for asking.. I havent implemented the DI trend additions yet.. those are still a work in progress. In fact.. TrendingUp and TrendingDown are defined the same there lol..@SilverWolf, thanks for all your time in developing this strategy. Been learning a lot from this thread.
I am not a coder. But i am lost in understandibng this line of logic.Can you help me. Thanks.
def TrendingUp = if "DI-" > ADX and ADX > "DI+"
then 1
else Double.NaN;
def TrendingDown = if "DI-" > ADX and ADX > "DI+"
then 1
def TrendingUp = if "DI-" < ADX and "DI+" > ADX
then 1
else Double.NaN;
def TrendingDown = if "DI-" > ADX and "DI+" < ADX
then 1
else Double.NaN;
Nothing is opening on my chart, what am i missing ? DISREGARD, Added it as strategyImproved/Corrected Entry and Exit orders. Works well on mobile too
CSS:# Parabolic_SAR_Moving_Average_Trading_Strategy # by BabyTrader using the following article: Parabolic SAR Moving Average Trading Strategy # https://tradingstrategyguides.com/parabolic-sar-moving-average-trade-strategy/ # ParabolicSAR_withAlerts_JQ # 2018-04-15 Mods by Johnny Quotron # with a very helpful kickstart from DMonkey # Mods include # 1. splitting the PSAR into two visible plots so that they can be colored seperately # 2. adding alert arrows at the PSAR to enhance visibility # a. original alert arrows remain available but are hidden by default # 3. add ability to color color alert arrows # # Combined/Modified/Altered by SilverWolf declare upper; #======== Inputs ============================================================================== input accelerationFactor = 0.012; input accelerationLimit = 0.2; input extremeoffset = 0.0; input MovAvgType = AverageType.EXPONENTIAL; input MovAvgTrendMethod = {default "SINGLE", "CROSSING"}; input CrossingAvgLength = 9; input TrendTriggerAvgLength = 21; input TradeClosingMethod = {default "SAR", "MOVAVG"}; input TradeSize = 1; def Trend = if MovAvgTrendMethod == MovAvgTrendMethod."SINGLE" then 1 else if MovAvgTrendMethod == MovAvgTrendMethod."CROSSING" then 2 else 0; def PlotCross = if Trend == 2 then yes else no; def Closer = if TradeClosingMethod == TradeClosingMethod."SAR" then 1 else if TradeClosingMethod == TradeClosingMethod."MOVAVG" then 2 else 0; #======== Moving Averages ====================================================================== plot TriggerAVG = MovingAverage(MovAvgType, close, TrendTriggerAvgLength); TriggerAVG.SetLineWeight(3); TriggerAVG.SetDefaultColor(Color.WHITE); plot CrossingAVG = MovingAverage(MovAvgType, close, CrossingAvgLength); CrossingAVG.SetHiding(!PlotCross); CrossingAVG.SetLineWeight(3); CrossingAVG.SetDefaultColor(Color.PINK); #======== ParabolicSAR ========================================================================= Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor); Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")"); def state = {default init, long, short}; def extreme; def SAR; def acc; switch (state[1]) { case init: state = state.long; acc = accelerationFactor; extreme = high; SAR = low; case short: if (SAR[1] < high) then { state = state.long; acc = accelerationFactor; extreme = high + extremeoffset; SAR = extreme[1]; } else { state = state.short; if (low < extreme[1]) then { acc = Min(acc[1] + accelerationFactor, accelerationLimit); extreme = low - extremeoffset; } else { acc = acc[1]; extreme = extreme[1]; } SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1])); } case long: if (SAR[1] > low) then { state = state.short; acc = accelerationFactor; extreme = low - extremeoffset; SAR = extreme[1]; } else { state = state.long; if (high > extreme[1]) then { acc = Min(acc[1] + accelerationFactor, accelerationLimit); extreme = high + extremeoffset; } else { acc = acc[1]; extreme = extreme[1]; } SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1])); } } #======== SIGNALS ========================================================================= def BuySignal = if Trend == 1 and (close > TriggerAVG ) and (SAR crosses below close) then 1 else if Trend == 2 and (close > TriggerAVG) and (CrossingAVG crosses above TriggerAVG) and (SAR < close) then 1 else Double.NaN; def SellSignal = if Trend == 1 and (close < TriggerAVG ) and (SAR crosses above close) then 1 else if Trend == 2 and (close < TriggerAVG) and (CrossingAVG crosses below TriggerAVG) and (SAR > close) then 1 else Double.NaN; def BuyExit = if Closer == 1 and (close crosses below SAR[-1]) then 1 else if Closer == 2 and (TriggerAVG > CrossingAVG) then 1 else Double.NaN; def SellExit = if Closer == 1 and (close crosses above SAR[-1]) then 1 else if Closer == 2 and (TriggerAVG < CrossingAVG) then 1 else Double.NaN; #======== STRATEGY ORDERS =================================================================== AddOrder(OrderType.BUY_TO_OPEN, BuySignal, open[-1], TradeSize, Color.GREEN, Color.GREEN, name = "Long"); AddOrder(OrderType.SELL_TO_CLOSE, BuyExit, open[-1], TradeSize, Color.RED, Color.RED, name = "Close"); AddOrder(OrderType.SELL_TO_OPEN, SellSignal, open[-1], TradeSize, Color.ORANGE, Color.ORANGE, name = "Short"); AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], TradeSize, Color.WHITE, Color.WHITE, name = "Close"); #======== PLOTS ============================================================================ plot BullPSAR = if SAR < close then SAR else Double.NaN; BullPSAR.SetPaintingStrategy(PaintingStrategy.POINTS); BullPSAR.SetDefaultColor(Color.LIME); plot BearPSAR = if SAR > close then SAR else Double.NaN; BearPSAR.SetPaintingStrategy(PaintingStrategy.POINTS); BearPSAR.SetDefaultColor(Color.PINK); #--- def BullSignalAtCandle = Crosses(SAR, close, CrossingDirection.BELOW); plot BullSignalAtPSAR = if close crosses above SAR then SAR else Double.NaN; BullSignalAtPSAR.SetLineWeight(1); BullSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_UP); BullSignalAtPSAR.SetDefaultColor(Color.LIME); def BearSignalAtCandle = Crosses(SAR, close, CrossingDirection.ABOVE); plot BearSignalAtPSAR = if close crosses below SAR then SAR else Double.NaN; BearSignalAtPSAR.SetLineWeight(1); BearSignalAtPSAR.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); BearSignalAtPSAR.SetDefaultColor(Color.PINK); #--- plot LongEntrySignal = if BuySignal then BuySignal else Double.NaN; LongEntrySignal.SetDefaultColor(Color.UPTICK); LongEntrySignal.SetLineWeight(5); LongEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); plot ShortEntrySignal = if SellSignal then SellSignal else Double.NaN; ShortEntrySignal.SetDefaultColor(Color.DOWNTICK); ShortEntrySignal.SetLineWeight(5); ShortEntrySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); plot LongExitSignal = if BuyExit then BuyExit else Double.NaN; LongExitSignal.SetDefaultColor(Color.White); LongExitSignal.SetLineWeight(1); LongExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); plot ShortExitSignal = if SellExit then SellExit else Double.NaN; ShortExitSignal.SetDefaultColor(Color.White); ShortExitSignal.SetLineWeight(1); ShortExitSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); #======== ALERTS =========================================================================== input AlertsOn = No; Alert(AlertsOn and BullSignalAtCandle, "Bullish PSAR", Alert.BAR, Sound.Ring); Alert(AlertsOn and BearSignalAtCandle, "Bearish PSAR", Alert.BAR, Sound.Ring); Alert(AlertsOn and BuySignal, "Bullish PSAR above AVG", Alert.BAR, Sound.Ring); Alert(AlertsOn and SellSignal, "Bullish PSAR below AVG", Alert.BAR, Sound.Ring); #======== EOF ===========================================================================
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.