I would like some assistance please, to code the stop losses for this system. My idea is that when it takes a trade, say long, it will look back from the entry bar until it finds the previous swing low that is below the low of the entry bar. If there isn’t one within say 100 bars, it will not take the trade.
If it finds one, it will set the stop loss at 5 pips below it.
As the bar closes progress up, the system will then continue to move the stop loss to the next swing low until the close of a bar is above the Super Trend. The Super Trend will then become the stop loss and the close of the trade.
Of course, the reverse will apply for the short trades.
I have attached my code to date. Any comments on that would also be appreciated.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Indicators
COI = CALL "MGC-Coppock"[14, 11, 10](close)
MAC = MACDline[12,26,9](close)
STO = Stochastic[14,3](close)
ST = Supertrend[3.2,22]
// Conditions to enter long positions
c1 = COI > COI[1] AND COI < 0
c2 = MAC > MAC[1]
c3 = STO crosses over 20
IF c1 AND c2 AND c3 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
c5 = close crosses under ST
IF c5 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c11 = COI < COI[1] AND COI > 0
c12 = MAC < MAC[1]
c13 = STO crosses under 80
IF c11 AND c12 AND c13 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
c15 = close crosses over ST
IF c15 THEN
EXITSHORT AT MARKET
ENDIF
//Stops and Targets
Hi Mike, could you please attach the MGC-Coppock indicator? (with the “Add Media” button) For testing purpose of the adapted code of your strategy. Thanks.
Many thanks, Nicolas. I have uploaded the code.
Nicolas, the main reason I think the stop loss is appropriate is that my indicators sometimes give a false signal, a you will see if you run it on the EURAUD. I have attached the pdf showing an excellent trade that was missed. I have run this example for the year from 12/3/15 to 12/3/16.
Would you like to escalate this to the Programming Services level, as I am happy to pay for your expert advice?
Best regards,
Mike
Currencies – Mini S – EUR_AUD Mini (-) – 13-Mar-2016 09_58
Mike, thanks for the files. I’ll investigate them and get back to you on Monday. For the progamming services purpose you can join me directly at prog@prorealcode.com