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
// Définition des paramètres du code
DEFPARAM CumulateOrders = false // Cumul des positions désactivé
// System closes all orders at 00.00 No new orders allowed until "FLATBEFORE" time
DEFPARAM FLATBEFORE = 080000
// Cancel all orders and close all positions at "FLATAFTER" Time
DEFPARAM FLATAFTER = 171500
// No new orders or enlarging position before
noEntryBeforeTime = 080000
timeEnterBefore = time >= noEntryBeforeTime
// No new orders or enlarging positions after
noEntryAfterTime = 163000
timeEnterAfter = time < noEntryAfterTime
// Conditions pour ouvrir une position acheteuse
indicator1 = CALL "MAGICAL TREND"[25, 2](close)
c1 = (close > indicator1)
IF c1 AND timeEnterBefore AND timeEnterAfter and not longonmarket THEN
BUY 1 CONTRACT AT MARKET
be = 0
ENDIF
// Conditions pour ouvrir une position en vente à découvert
indicator2 = CALL "MAGICAL TREND"[25,2](close)
c2 = (close < indicator2)
IF c2 AND timeEnterBefore AND timeEnterAfter and not shortonmarket THEN
SELLSHORT 1 CONTRACT AT MARKET
be=0
ENDIF
// Stops en targets
if be = 0 and close-tradeprice>=5*pointsize then
set stop breakeven
be = 1
else
set stop ptrailing 5
endif
A “ptrailing 5” in a 15 minute time frame definitely doesn’t work and just embellishes the backtest.
I’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
Here is the strategy code modified to add the MACD zero line cross to trigger the order: (not tested)
// Définition des paramètres du code
DEFPARAM CumulateOrders = false // Cumul des positions désactivé
// System closes all orders at 00.00 No new orders allowed until "FLATBEFORE" time
DEFPARAM FLATBEFORE = 080000
// Cancel all orders and close all positions at "FLATAFTER" Time
DEFPARAM FLATAFTER = 171500
// No new orders or enlarging position before
noEntryBeforeTime = 080000
timeEnterBefore = time >= noEntryBeforeTime
// No new orders or enlarging positions after
noEntryAfterTime = 163000
timeEnterAfter = time < noEntryAfterTime
timeframe(15 minutes,updateonclose)
// Conditions pour ouvrir une position acheteuse
indicator1 = CALL "MAGICAL TREND"[25, 2](close)
c1 = (close > indicator1)
// Conditions pour ouvrir une position en vente à découvert
indicator2 = 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 THEN
BUY 1 CONTRACT AT MARKET
be = 0
ENDIF
IF c2 and imacd crosses under 0 AND timeEnterBefore AND timeEnterAfter and not shortonmarket THEN
SELLSHORT 1 CONTRACT AT MARKET
be=0
ENDIF
// Stops en targets
if be = 0 and close-tradeprice>=5*pointsize then
set stop breakeven
be = 1
else
set stop ptrailing 5
endif
Thanks for your great help Nicolas, I will test it and come back to you.
Dear 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
Sorry my bad, change line 16 with:
timeframe(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..!
Dear 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
In lines 27 and 32 you can add this condition:
AND (OpenMinute = 0)
Thanks Roberto, I will test later today
Dear 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
It’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:
AND (OpenMinute = 45)
Thanks a lot Roberto, understand the logica now and will test with various options.
Best regards Martin