A poster asked for an 'example' of a combined strategy using Stochastic and EMA. I googled the combination and found this:
https://www.tradingpedia.com/forex-trading-strategies/combining-stochastic-oscillator-and-emas/
I translated that site's strategy into the following script.
CAVEAT: I haven't used this strategy. I am posting it as an 'example' of a combined strategy. I strongly advocate looking at fundamentals, long term trend lines, and current news on an equity before entering a trade. If trading this strategy I would suggest adding a cycle and/or market strength indicator and support and resistance lines to your charts.
When copying this script MAKE SURE you save it as a STRATEGY (the tab next to Study)
HERE IS A STUDY VERSION OF THE ABOVE STRATEGY
https://www.tradingpedia.com/forex-trading-strategies/combining-stochastic-oscillator-and-emas/
I translated that site's strategy into the following script.
CAVEAT: I haven't used this strategy. I am posting it as an 'example' of a combined strategy. I strongly advocate looking at fundamentals, long term trend lines, and current news on an equity before entering a trade. If trading this strategy I would suggest adding a cycle and/or market strength indicator and support and resistance lines to your charts.
When copying this script MAKE SURE you save it as a STRATEGY (the tab next to Study)
Ruby:
# An Example Of A Stochastic and EMA Combined Strategy
# @MerryDay 5/21
def BuyCriteria =
#Go long when the 2-period EMA crosses above the 4-period EMA
MovAvgExponential("length" = 2)."AvgExp"[1] crosses above MovAvgExponential("length" = 4)."AvgExp"[1] and
#AND continues higher:
MovAvgExponential("length" = 2)."AvgExp" is greater than
MovAvgExponential("length" = 2)."AvgExp"[1] and
#WHILE the stochastic is below 50.
reference StochasticFull().FullD is less than 50 ;
def SellCriteria =
#Sell if EMAs cross back:
MovAvgExponential("length" = 2)."AvgExp" crosses below
MovAvgExponential("length" = 4)."AvgExp" OR
#OR Sell if stochastic enters the overbought or oversold areas
reference StochasticFull().FullD is less than 20 or
reference StochasticFull().FullD is greater than 80 ;
# ########################################################
#Order Management
AddOrder(OrderType.BUY_AUTO, BuyCriteria, tickcolor = Color.yellow, arrowcolor = Color.black, name = "Buy", tradeSize = 100);
AddOrder(OrderType.SELL_TO_CLOSE, SellCriteria , tickcolor = Color.pink, arrowcolor = Color.red, name = "sell", tradeSize = 100);
# ########################################################
Ruby:
# An Example Of A Stochastic and EMA Combined Strategy
# @MerryDay 5/21
# ########################################################
# TOS Moving Averages
plot avg1 = MovingAverage(AverageType.eXPONENTIAL, close, 2);
plot avg2 = MovingAverage(AverageType.eXPONENTIAL, close, 4);
AddCloud(avg1, avg2, Color.light_green, Color.pink);
# ########################################################
def BuyCriteria =
#Go long when the 2-period EMA crosses above the 4-period EMA
MovAvgExponential("length" = 2)."AvgExp"[1] crosses above MovAvgExponential("length" = 4)."AvgExp"[1] and
#AND continues higher:
MovAvgExponential("length" = 2)."AvgExp" is greater than
MovAvgExponential("length" = 2)."AvgExp"[1] and
#WHILE the stochastic is below 50.
reference StochasticFull().FullD is less than 50 ;
def SellCriteria =
#Sell if EMAs cross back:
MovAvgExponential("length" = 2)."AvgExp" crosses below
MovAvgExponential("length" = 4)."AvgExp" OR
#OR Sell if stochastic enters the overbought or oversold areas
reference StochasticFull().FullD is less than 20 or
reference StochasticFull().FullD is greater than 80 ;
# ########################################################
Plot BuyTrigger = if BuyCriteria then low else double.NaN ;
BuyTrigger.SetPaintingStrategy(PaintingStrategy.ARROW_up);
BuyTrigger.SetLineWeight(2);
BuyTrigger.SetDefaultColor(color.dark_green) ;
Plot SellTrigger = if SellCriteria then high else double.NaN ;
SellTrigger.SetPaintingStrategy(PaintingStrategy.ARROW_down);
SellTrigger.SetLineWeight(2);
SellTrigger.SetDefaultColor(color.dark_red) ;
Last edited: