Hello, I have a coding request for the following strategy from Galen Woods. Can someone code that for me, please?
These are the rules for a long trade signal:
The 9-period EMA must be above the 30-period WMA
The two moving averages must be separated from each other
The first bar to close below the 9 EMA is used as the trigger bar for the buy setup
Place a buy limit order above the high of the trigger bar.
If you want to go short, follow this three step process:
The 9-period EMA must be below the 30-period WMA
The two moving averages must be separated from each other
The first bar to close above the 9 EMA is used as the trigger bar for the sales setup
Place a sell limit order below the low of the trigger bar
Trailing stop loss below / above the WMA30
For better reading of the trading rules I found this website:
https://tradingstrategyguides.com/9-30-trading- strategy / # When_to_use_the_930_Trading_Method
There you go:
// 9-30 Trading Method
//
//https://tradingstrategyguides.com/9-30-trading-strategy/
//
DEFPARAM CumulateOrders = false
//
ONCE Trigger = 0
ONCE EntryL = 0
ONCE EntryS = 0
ONCE SL = 0
//
TradeON = (OpenTime >= 090000) AND (OpenTime <= 190000)
//
Ema9 = average[9,1](close)
Wma30 = average[30,2](close)
L1 = Ema9 > Wma30
S1 = Ema9 < Wma30
MAgap = abs(Ema9 - Wma30)
Apart = MAgap > average[20,0](MAgap)
Trigger = (L1 AND (close < Ema9)) OR (S1 AND (close > Ema9))
IF OnMarket OR (L1 <> L1[1]) OR (S1 <> S1[1]) THEN
Trigger = 0
EntryL = 0
EntryS = 0
SL = 0
ENDIF
IF (Apart AND L1) AND Not Trigger THEN
EntryL = high + 1 * PipSize
EntryS = 0
//SL = low - 1 * PipSize
SL = Wma30 - 1 * PipSize
ELSIF (Apart AND S1) AND Not Trigger THEN
EntryS = low - 1 * PipSize
EntryL = 0
//SL = high + 1 * PipSize
SL = Wma30 + 1 * PipSize
ENDIF
//
IF TradeON THEN
IF EntryL AND Not LongOnMarket THEN
BUY 1 CONTRACT AT EntryL STOP
SELL AT SL STOP
ELSIF EntryS AND Not ShortOnMarket THEN
SELLSHORT 1 CONTRACT AT EntryS STOP
EXITSHORT AT SL STOP
ENDIF
ENDIF
IF LongOnMarket THEN
SL = max(SL,Wma30)
SELL AT SL STOP
ELSIF ShortOnMarket THEN
SL = min(SL,Wma30)
EXITSHORT AT SL STOP
ENDIF
//-----------------------
// debugging code
Entry = EntryL
IF Entry = 0 THEN
Entry = EntryS
ENDIF
IF Entry > 0 THEN
graphonprice Entry
ENDIF
IF SL > 0 THEN
graphonprice SL coloured(0,128,0,155)
ENDIF
I used the more conservative trailing stop based on WMA30, but I also commented out the more aggressive way. You can simply use either by swapping comment slashes (but I think it shouldn’t be rewarding).
I tested it on DAX € 5, 1h TF, 200K units.
Thank you very much Roberto, the strategy looks good. The way it should work. I think the results are better on Nasdaq or SP500.
Can you please explain the function of lines 18 and 19 to me? In words?
Can you add a take profit? In relation to the SL, 1: 1 or 1: 1.5?
That’s to make sure the two averages have some gap in between them. I use GAP (difference) to calculate their distance, then I set variable APART only when that gap is greater than the its average over a given period.
Replace lines 27-37 by these ones (I couldn’t test them, though):
IF (Apart AND L1) AND Not Trigger THEN
EntryL = high + 1 * PipSize
EntryS = 0
//SL = low - 1 * PipSize
SL = Wma30 - 1 * PipSize
TP = abs(EntryL - SL) * 1.5
SET TARGET PROFIT TP
ELSIF (Apart AND S1) AND Not Trigger THEN
EntryS = low - 1 * PipSize
EntryL = 0
//SL = high + 1 * PipSize
SL = Wma30 + 1 * PipSize
TP = abs(EntryS - SL) * 1.5
SET TARGET PROFIT TP
ENDIF
replace 1.5 with any multiplier of your choice.
Thank you Roberto. I will test it in peace.
Hi Phoentz,
Thanks for digging on other sites to get new ideas ^^
did you get a good backtest on this one and on which asset ? Mine are negative before 2021 on NAS H1;
best
The strategy is intended intraday… I got it to work quite adequately with changed values in the TF M1 on Nasdaq. It’s been a while. But I had the feeling that it wasn’t stable. But I’m a little smarter now than I was then. It’s possible that I didn’t have much of a clue as to how the system worked.
Ah ok I was updating the backtest of Roberto that was in “1 ora”
Coding request for EMA9 / WMA30 strategy
here is the backtest ;
Maybe inverting the conditions can make it a winner 😉
Thanks anyway,
Chris