Magical Trend strategy question
Forums › ProRealTime English forum › ProOrder support › Magical Trend strategy question
- This topic has 12 replies, 4 voices, and was last updated 1 year ago by MartinB.
-
-
06/28/2023 at 1:56 PM #216925
Hi Nicolas,
Although the discussion was in the French community, I have to continue here as I cannot write in French
I really like your magical trend, but I’m puzzled with the number of trades its making when I use your strategy with the trailing stop.
You will find it at the end.
I made the walk forward testing and it gives very good results in the 15 minutes and 30 minutes timeframes with a trailing stop of 5 pips.
However the number of trades in the IG version of Prorealtime, it is very high and very costly due to the spread.
Is it an IG issue making a real trade every time when the stop is changed, or is it a matter of coding?
Thanks for your help
Martin Bakelaar
12345678910111213141516171819202122232425262728293031323334353637383940// Définition des paramètres du codeDEFPARAM CumulateOrders = false // Cumul des positions désactivé// System closes all orders at 00.00 No new orders allowed until "FLATBEFORE" timeDEFPARAM FLATBEFORE = 080000// Cancel all orders and close all positions at "FLATAFTER" TimeDEFPARAM FLATAFTER = 171500// No new orders or enlarging position beforenoEntryBeforeTime = 080000timeEnterBefore = time >= noEntryBeforeTime// No new orders or enlarging positions afternoEntryAfterTime = 163000timeEnterAfter = time < noEntryAfterTime// Conditions pour ouvrir une position acheteuseindicator1 = CALL "MAGICAL TREND"[25, 2](close)c1 = (close > indicator1)IF c1 AND timeEnterBefore AND timeEnterAfter and not longonmarket THENBUY 1 CONTRACT AT MARKETbe = 0ENDIF// Conditions pour ouvrir une position en vente à découvertindicator2 = CALL "MAGICAL TREND"[25,2](close)c2 = (close < indicator2)IF c2 AND timeEnterBefore AND timeEnterAfter and not shortonmarket THENSELLSHORT 1 CONTRACT AT MARKETbe=0ENDIF// Stops en targetsif be = 0 and close-tradeprice>=5*pointsize thenset stop breakevenbe = 1elseset stop ptrailing 5endif06/28/2023 at 2:17 PM #21692608/05/2023 at 1:06 PM #218625I’m using the above Magical Trend strategy in the 1 hour timeframe with a trailing stop of 8 pips and it gives good results.
In an hour a lot can change and the Magical Trend strategy is lagging, therefore I want to add the signals of the MACD in the 15 min timeframe.
Buy when Close > “Magical Trend” in 1 hour TF and MACD – MACD Signal Line > 0 in 15 min TF
Sell when Close < “Magical Trend” in 1 hour TF and MACD – MACD Signal Line < 0 in 15 min TF
Would someone be willing to help me to add the right programming of the MACD in the 15 min TF, to my strategy.
Thanks in advance
08/08/2023 at 9:40 AM #218721Here is the strategy code modified to add the MACD zero line cross to trigger the order: (not tested)
12345678910111213141516171819202122232425262728293031323334353637383940414243// Définition des paramètres du codeDEFPARAM CumulateOrders = false // Cumul des positions désactivé// System closes all orders at 00.00 No new orders allowed until "FLATBEFORE" timeDEFPARAM FLATBEFORE = 080000// Cancel all orders and close all positions at "FLATAFTER" TimeDEFPARAM FLATAFTER = 171500// No new orders or enlarging position beforenoEntryBeforeTime = 080000timeEnterBefore = time >= noEntryBeforeTime// No new orders or enlarging positions afternoEntryAfterTime = 163000timeEnterAfter = time < noEntryAfterTimetimeframe(15 minutes,updateonclose)// Conditions pour ouvrir une position acheteuseindicator1 = CALL "MAGICAL TREND"[25, 2](close)c1 = (close > indicator1)// Conditions pour ouvrir une position en vente à découvertindicator2 = CALL "MAGICAL TREND"[25,2](close)c2 = (close < indicator2)timeframe(default)imacd=macd[12,26,9]IF c1 and imacd crosses over 0 AND timeEnterBefore AND timeEnterAfter and not longonmarket THENBUY 1 CONTRACT AT MARKETbe = 0ENDIFIF c2 and imacd crosses under 0 AND timeEnterBefore AND timeEnterAfter and not shortonmarket THENSELLSHORT 1 CONTRACT AT MARKETbe=0ENDIF// Stops en targetsif be = 0 and close-tradeprice>=5*pointsize thenset stop breakevenbe = 1elseset stop ptrailing 5endif1 user thanked author for this post.
08/08/2023 at 10:31 AM #21872608/08/2023 at 10:43 PM #218751Dear Nicolas,
The strategy is working in the 15 minute time frame, but not in the 1 hour time frame as I was hoping for.
Maybe I expressed myself wrong, or I’m doing something wrong..
I’m using the Magical Trend Strategy in the 1 hour time frame as default with Pro Order auto trading
At the start of each hourly bar, the Magical Trend Strategy is buying or selling depending on the trend.
At the the start of each new hourly bar the Magical Trend Strategy should have an extra condition
This extra condition is (MACD – MACD Signal line) in the 15 min time frame
When Magical Trend in the 1 hour time frame and (MACD – MACD Signal line) in the 15 min time frame are in line, a position should be taken
In other words, when Magical Trend is positive in the 1 hour time frame, but (MACD- MACD Signal) is negative (<0) in the 15 min Time Frame, no new long position should be taken.
Hope you can explain it to me
Thanks Nicolas
08/09/2023 at 12:00 PM #218816Sorry my bad, change line 16 with:
1timeframe(1 hour,updateonclose)Orders will trigger on MACD cross of the default timeframe (the one you are lauching the strategy on) with line 0, otherwise if you are just testing if >0 and <0, you’ll get plenty of orders because that conditions will be fulfilled for a long period of time.
But, it could be changed of course..!
08/09/2023 at 11:59 PM #218872Dear Nicolas, thanks for your help again.
Unfortunately it is not working what I have in mind.
Let me try again:
I trade in the 1 hour TF, but want to test on >0 and <0 in the 15 min TF, but only at the close/open of the 1 hour bar
When your magical trend in the 1 hour TF makes a buy order at the close/open of the 1 hour bar, but the MACD in 15 TF is <0 on the top of the hour, the buy order should not take place.
In this case you should have less orders
I hope my explanation is more clear, but I’m not sure whether this is possible.
Thanks again Nicolas
08/10/2023 at 8:54 AM #218889In lines 27 and 32 you can add this condition:
1AND (OpenMinute = 0)08/10/2023 at 12:08 PM #21890208/10/2023 at 9:51 PM #218919Dear Robert, Nicolas, thank you both for the help given, its working like I had in mind.
There is only a minor issue, the strategy is taking the position not at the start of the 1 hour bar, but 15 min after
Is this something that can be adjusted?
Thanks again.
Martin
08/11/2023 at 9:25 AM #218929It’s because the order is placed when the 00-minute candle closes, therefore the entry is at minute 15.
You may change the line I suggested, replacing 0 with 45:
1AND (OpenMinute = 45)08/11/2023 at 9:39 AM #218931 -
AuthorPosts
Find exclusive trading pro-tools on