Request for a simple double time frame strategy to be coded for spread betting
Forums › ProRealTime English forum › ProOrder support › Request for a simple double time frame strategy to be coded for spread betting
- This topic has 19 replies, 3 voices, and was last updated 3 years ago by GraHal.
-
-
08/09/2020 at 6:58 AM #141184
Request for a simple double-time-frame strategy to be coded for spread betting
I’d love to ask you clever folk on this forum for some help in creating a ProRealCode system that uses 2 timeframes, 200 EMAs and a MACD on the shorter time frame chart.
Here’s the proposed system for testing on EUR/USD (and other major FX pairs):
LONG TRADE
If price is > 200EMA on DAILY chart then execute LONG only trades
[and]
If price is > 200EMA on 30 min chart
[and]
If there’s a bullish cross on the MACD on the 30 min chart (where the 12ma moves up through the 26ma regardless of where it is).
[If ALL of the above, then]
BUY 1 / pip on next candle open
STOP LOSS: 50 pips (Spread betting, so not using ‘LOTS’)
TAKE PROFIT: 100 pips (Spread betting, so not using ‘LOTS’)
SHORT TRADE
If price is < 200EMA on DAILY chart then execute SHORT only trades
[and]
If price is < 200EMA on 30 min chart
[and]
If there’s a bearish cross on the MACD on the 30 min chart (where the 12ma moves down through the 26ma regardless of where it is).
[If ALL of the above, then]
SELL 1 / pip on next candle open
STOP LOSS: 50 pips (Spread betting, so not using ‘LOTS’)
TAKE PROFIT: 100 pips (Spread betting, so not using ‘LOTS’)
BONUS POINTS
I’d also love to see how this model would work if used with a TRAILING STOP LOSS rather than a fixed risk/reward. If you felt inclined to also include a version of the code with a trailing stop loss then, I’d probably want to test it trailing by say 25 pips.
QUESTIONS?
I’m open to them 🙂
Thank you so much for taking the time to read and consider this, I’d be very grateful for any help or comments on this from the community.
All the best!
Matt
08/09/2020 at 7:16 AM #141185*I meant to say in parenthesis next to the MACD specification that “when the MACD line moves through the 9ma Signal line”
08/09/2020 at 7:25 AM #141186This is what I have so far from trying to do it myself. But I can’t add the second time frame on the Daily in for another level of confirmation of the trend (above the 200ema for bullish and visa versa).
123456789101112131415161718192021222324252627282930313233343536373839404142434445// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)indicator2 = MACDline[12,26,9](close)indicator3 = MACDSignal[12,26,9](close)c2 = (indicator2 CROSSES OVER indicator3)IF c1 AND c2 THENBUY 1 SHARES AT MARKETENDIF// Conditions to enter short positionsindicator4 = ExponentialAverage[200](close)c3 = (close < indicator4)indicator5 = MACDline[12,26,9](close)indicator6 = MACDSignal[12,26,9](close)c4 = (indicator5 CROSSES UNDER indicator6)IF c3 AND c4 THENSELLSHORT 1 SHARES AT MARKETENDIF// Stops and targetsSET STOP pLOSS 50SET TARGET pPROFIT 10008/09/2020 at 7:49 AM #141187Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
I tidied it up for you.
Thank you 🙂
1 user thanked author for this post.
08/09/2020 at 9:20 AM #141191Try below, not tested, but you get the general idea?
123456789Timeframe (Daily, updateonclose)indDaily = ExponentialAverage[200](close)cDaily = (close > indDaily)Timeframe (30 mn, updateonclose)ind30m = ExponentialAverage[200](close)c30m = (close > ind30m)1 user thanked author for this post.
08/09/2020 at 10:19 AM #141203Ah excellent, many thanks for looking at this for me, it means a lot that you’ve taken the time.
So, excuse my ignorance, that’s why I’m here haha, but do I just insert this into the pre-existing code that I’ve posted above? Will this take into account the MACD trigger crossovers that I use for entry if the price is above the 2 time-frame EMAs?
Cheers
Matt
08/09/2020 at 6:18 PM #141234Below is the Buy side, you do the SellShort and post the full code please.
1234567891011121314151617181920212223242526272829DEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsTimeframe (Daily, updateonclose)indDaily = ExponentialAverage[200](close)cDaily = (close > indDaily)Timeframe (30 mn, updateonclose)ind30m = ExponentialAverage[200](close)c30m = (close crosses over ind30m)//indicator1 = ExponentialAverage[200](close)//c1 = (close > indicator1)//indicator2 = MACDline[12,26,9](close)//indicator3 = ExponentialAverage[9](MACDline[12,26,9](close))//c2 = (indicator2 CROSSES OVER indicator3)IF cDaily AND c30m THENBUY 1 SHARES AT MARKETENDIF08/09/2020 at 6:28 PM #141235Above is not quite what you want as I have rem’d out C2 (I’ve had a few wines and beers! 🙂 ).
But, in your original code, you had the the MACD Signal line incorrectly coded, it should be …
1indicator3 = ExponentialAverage[9](MACDline[12,26,9](close))1 user thanked author for this post.
08/09/2020 at 8:29 PM #141245Thanks for that, I’ve really battled with it this evening, but like you, I’m a couple of G&Ts and some craft ales deep, and now I’m not seeing the wood for the trees. But I didn’t want to end the day without something to show for our efforts.
I ended up running this, and it’s miles away from the expected results I had from manual backtesting, so I think I’m back to the drawing board.
Here’s the code I ended up with:
EMA & MACD on Daily/30m123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263DEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsTimeframe (Daily, updateonclose)indDaily = ExponentialAverage[200](close)cDaily = (close > indDaily)Timeframe (30 mn, updateonclose)ind30m = ExponentialAverage[200](close)c30m = (close crosses over ind30m)indicator1 = ExponentialAverage[200](close)c1 = (close > indicator1)indicator2 = MACDline[12,26,9](close)indicator3 = ExponentialAverage[9](MACDline[12,26,9](close))c2 = (indicator2 CROSSES OVER indicator3)IF cDaily AND c30m AND c1 AND c2 THENBUY 1 SHARES AT MARKETENDIF// Conditions to enter short positionsTimeframe (Daily, updateonclose)indDaily = ExponentialAverage[200](close)cDailySell = (close < indDaily)Timeframe (30 mn, updateonclose)ind30m = ExponentialAverage[200](close)c30mSell = (close crosses under ind30m)indicator1 = ExponentialAverage[200](close)c3 = (close < indicator1)indicator2 = MACDline[12,26,9](close)indicator3 = ExponentialAverage[9](MACDline[12,26,9](close))c4 = (indicator3 CROSSES UNDER indicator2)IF cDaily AND c30mSell AND c3 AND c4 THENSELL 1 SHARES AT MARKETENDIF// Stops and targetsSET STOP pLOSS 50SET TARGET pPROFIT 100and the corresponding results are attached.
However, the code I had above in the thread yielded much better results over the year, and this wasn’t using multiple time frames (also see results attached)
I think something’s amiss, to be honest, but I’m too confused and don’t know how to code myself, I just use the ‘simplified creation’ bit normally, or I take programmed code and tinker using as much common sense/logic as I’m able to muster haha.
Anyway, back to the drawing board. I really appreciate the help on trying to code this, my expectations of how it should perform (based on manual backtesting on GBP/USD over 7 months in 2020 are:
- Profit = 11%
- Trades = 37
- Win Rate = 76.19%
- Max Consecutive Wins = 3
- Max Consecutive Losses = 4
- Max Drawdown = 7%
- Max Run up = 12%
Hope you’ve had a great weekend GraHal. I’m sure as I get more involved in the community I’ll be able to better solve errors and contribute. But I have to find the time to start formerly learning how first!
Cheers
Matt
08/09/2020 at 8:50 PM #141248Hahah … what a pair we are!
In my (drunken) opinion 🙂 No I’ve sobered up a bit now!
You don’t need C1 and C2 now on the Buy side nor C3 and C4 as you have replaced with CDaily and C30m.
Opening a Short is made using SellShort (not Sell as you have above) so I’m not surprised your results are all over the place ! 🙂
Come back Roberto … all is forgiven! 🙂
08/09/2020 at 8:54 PM #141249Hmm, that’s really odd, I couldn’t get it to even show results unless I did it like that. It just kept showing ‘No Data’. Do you happen to get any results show up on a backtest of the code snippet you gave me above for the buy-side trades? I’m not getting it to show any results.
08/09/2020 at 10:17 PM #14125408/09/2020 at 10:21 PM #141255Principally because I don’t know how to programme trading systems, and was asking for help haha. So I’m just guessing how to do it, and using trial and error. I originally did use cDailySell (which I made up in the first place), but then I figured that it would have been a constant/the same on both the buy and sell side. So, only changed the bits that I thought were different for a sell trade, as opposed to what you gave me for the buy trade.
I don’t really have a latest code version at present other than what had been shared, because none of it came close sadly.
08/09/2020 at 10:37 PM #141258Ha … best way to learn is to try try and try again.
I am not the best at coding and I am watching a film with one eye and trying to help you at same time.
Why don’t you just get the Buy side working first as that means that there is only half the code to keep changing etc?
08/09/2020 at 10:39 PM #141259I also had a pizza and a beer, but I think this should do:
1234567891011121314151617181920212223242526272829Defparam CumulateOrders = false//Timeframe(Daily,UpdateOnClose)EmaD = average[200,1](close)//TimeFrame(30 minute,UpdateOnClose)Ema30 = average[200,1](close)MyMACD = ExponentialAverage[12](close) - ExponentialAverage[26](close)MySignalLine = ExponentialAverage[9](MyMACD)//MyHisto = MyMACD - MySignalLine//TimeFrame(Default)L1 = close > EmaDL2 = close > Ema30L3 = MyMACD CROSSES OVER MySignalLineLcond = L1 AND L2 AND L3 AND Not OnMarket//S1 = close < EmaDS2 = close < Ema30S3 = MyMACD CROSSES UNDER MySignalLineScond = S1 AND S2 AND S3 AND Not OnMarket//IF Lcond THENBUY 1 Contract at Market //Contracts/Lots/Perpont make no differenceELSIF Scond THENSELLSHORT 1 Contract at MarketENDIFSET STOP pLOSS 50SET TARGET pPROFIT 1002 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on