I am desperately looking for help with writing a strategy in trading view where I'm trying to create a crossover buy and sell signals on 3 different MA's , specifically a 9 ema , 21 ema, and 33 simple moving average. What I'm trying to do is have a long condition present itself when the 9 ema crosses above the 21 ema and also having the same long condition happen when the 21 ema crosses above the 33 simple moving average. I want this to work for both Long's and shorts - using the 9 & 21 as a "Small Signal" while using the 21 and 33 as a "Large Signal" and I can't figure it out... this is the closest I have below and it wont work correctly
//@version=3
//study(title="MA Crossover Strategy", overlay = true)
strategy("EMA Crossover Strategy", overlay=true)
src = input(close, title="Source")
price = security(tickerid, period, src)
ema1 = input(9, title="1st EMA Length")
type1 = input("EMA", "1st EMA Type", options=["SMA", "EMA"])
ema2 = input(21, title="2nd EMA Length")
type2 = input("EMA", "2nd EMA Type", options=["SMA", "EMA"])
sma3 = input(33, title="1st MA Length")
type3 = input("SMA", "2nd SMA type", options=["SMA", "EMA"])
price1 = if (type1 == "EMA")
ema(price, ema1)
else
sma(price, ema1)
price2 = if (type2 == "EMA")
sma(price, ema2)
else
ema(price, ema2)
price3 = if (type3 == "SMA")
sma(price, sma3)
else
ema(price, sma3)
//plot(series=price, style=line, title="Price", color=black, linewidth=1, transp=0)
plot(series=price1, style=line, title="1st EMA", color=blue, linewidth=2, transp=0)
plot(series=price2, style=line, title="2nd EMA", color=yellow, linewidth=2, transp=0)
plot(series=price3, style=line, title="1st MA", color=orange, linewidth=2, transp=0)
longCondition = crossover(price1, price2) and crossover(price2, price3)
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = crossunder(price1, price2) and crossover(price2, price3)
if (shortCondition)
strategy.entry("Short", strategy.short)
The signals wont show up but If you delete the last "and crossover" part of both conditions it will work only for the 9 ema and 21 ema but I want to incorporate the 21 ema and 33 simple cross.
These are the signals I am trying to replicate for a strategy, the code was used to create the indicator but I'm having a hard time translating it to a strategy. You see the initial signal is given when the 9ema crosses the 21ema and the larger signal is given when the 21ema crosses the 33 simple ma...