I would like to share a simple intraday strategy with CAC40, but adaptable also with Ftse100 and Eurostoxx.
Improvements and suggestions are welcome, as well as long term backtesting (I get to 100k units)
Main points:
- 1-minute chart
- The code works on the 1-hour timeframe to calculate the highs and lows
- The code works on the 30-minute(long) and 15-minute(short) timeframe to handle the trailing stop
- The trade still closes by 10 p.m.
There are two codes, one for LONG and one for SHORT.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
DEFPARAM CumulateOrders = False DEFPARAM FLATAFTER = 220000 Timeframe (1 Hour, Updateonclose) //Once $MAXI[0] = High //Once $mini[0] = Low Once COMPRA = High //Timeframe (1 Hour, Updateonclose) Timeframe (1 Hour, Updateonclose) IF Time = 080000 AND not OnMarket THEN COMPRA = Highest[7](high[1]) + 5*pipsize BUY 1 CONTRACT AT COMPRA STOP ENDIF //ENDIF Timeframe (30 minutes, Updateonclose) SET STOP pLOSS 70 ////////////////////////////////////////////////////////////////////////////////////////////////////////// // Trailing Stop //------------------------------------------------------------------------------------ IF Not OnMarket THEN TrailStart = 10 //10 Start trailing profits from this point BasePerCent = 0.100 //10.0% Profit to keep StepSize = 6 //6 Pips chunks to increase Percentage PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunk RoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integer PriceDistance = 7 * pipsize//8.9 minimun distance from current price y1 = 0 y2 = 0 ProfitPerCent = BasePerCent ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG x1 = (close - tradeprice) / pipsize //convert price to pips IF x1 >= TrailStart THEN //go ahead only if N+ pips Diff1 = abs(TrailStart - x1) Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit ENDIF ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN//SHORT x2 = (tradeprice - close) / pipsize //convert price to pips IF x2 >= TrailStart THEN //go ahead only if N+ pips Diff2 = abs(TrailStart - x2) Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO)) ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit ENDIF ENDIF IF y1 THEN //Place pending STOP order when y>0 SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price IF abs(close - SellPrice) > PriceDistance THEN IF close >= SellPrice THEN SELL AT SellPrice STOP ELSE SELL AT SellPrice LIMIT ENDIF ELSE SELL AT Market ENDIF ENDIF IF y2 THEN //Place pending STOP order when y>0 ExitPrice = Tradeprice - (y2 * pipsize) //convert pips to price IF abs(close - ExitPrice) > PriceDistance THEN IF close <= ExitPrice THEN EXITSHORT AT ExitPrice STOP ELSE EXITSHORT AT ExitPrice LIMIT ENDIF ELSE EXITSHORT AT Market ENDIF ENDIF SET STOP pLOSS 70 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
DEFPARAM CumulateOrders = False DEFPARAM FLATAFTER = 220000 Timeframe (1 Hour, Updateonclose) //Once $MAXI[0] = High //Once $mini[0] = Low Once VENDI = Low //Timeframe (1 Hour, Updateonclose) Timeframe (1 Hour, Updateonclose) IF Time = 090000 AND not OnMarket THEN VENDI = Lowest[7](low[1]) - 5*pipsize SELLSHORT 1 CONTRACT AT VENDI STOP ENDIF Timeframe (15 minutes, Updateonclose) SET STOP pLOSS 70 ////////////////////////////////////////////////////////////////////////////////////////////////////////// // Trailing Stop //------------------------------------------------------------------------------------ IF Not OnMarket THEN TrailStart = 10 //10 Start trailing profits from this point BasePerCent = 0.100 //10.0% Profit to keep StepSize = 6 //6 Pips chunks to increase Percentage PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunk RoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integer PriceDistance = 7 * pipsize//8.9 minimun distance from current price y1 = 0 y2 = 0 ProfitPerCent = BasePerCent ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG x1 = (close - tradeprice) / pipsize //convert price to pips IF x1 >= TrailStart THEN //go ahead only if N+ pips Diff1 = abs(TrailStart - x1) Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit ENDIF ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN//SHORT x2 = (tradeprice - close) / pipsize //convert price to pips IF x2 >= TrailStart THEN //go ahead only if N+ pips Diff2 = abs(TrailStart - x2) Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO)) ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit ENDIF ENDIF IF y1 THEN //Place pending STOP order when y>0 SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price IF abs(close - SellPrice) > PriceDistance THEN IF close >= SellPrice THEN SELL AT SellPrice STOP ELSE SELL AT SellPrice LIMIT ENDIF ELSE SELL AT Market ENDIF ENDIF IF y2 THEN //Place pending STOP order when y>0 ExitPrice = Tradeprice - (y2 * pipsize) //convert pips to price IF abs(close - ExitPrice) > PriceDistance THEN IF close <= ExitPrice THEN EXITSHORT AT ExitPrice STOP ELSE EXITSHORT AT ExitPrice LIMIT ENDIF ELSE EXITSHORT AT Market ENDIF ENDIF SET STOP pLOSS 70 |
Saluti.
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :
Filename : download the ITF files
How to import ITF files into ProRealTime platform?
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hi Stanko,
thanks to share your strategy, I’m currently testing live, 2 things first trailing stop not working, and second it start long positon today and at 9am had notification that short stratedy failed.
Ciao Crusoe76, questa mattina alle ore 8 il mio sistema ha aperto una posizione Long a 7.352,30 ed attualmente la posizione è ancora aperta senza aver ricevuto notifiche. Forse stai testando LARRY CONNOR? Buona giornata
Ciao sto testando su uk100 e su cac40. Tutti e due sistemi hanno aperto long alle 8am, poi alle 9am ho ricevuo due notifiche che i due sistemi short erano stoppati. Su tutti e due i sistemi long il trailing stop si e attivato per poi tornare alla posizione iniziale. Il cac40 long e ancora aperto,mentre il uk100 era con un 40 punti di profitto e poi il sitema l’ha chiuso con 3 punti di profitto. Non sono sicuro che il trailing stop funzioni bene.
Grazie mille
Ciao Crusoe, grazie per il commento: confermo che il trailing stop non funziona bene. Provo a chiedere aiuto a Roberto o Nicolas. Buona giornata.
I was wondering, you said it works on the 1 min Chart, but you never use it in the code as timeframe. Does it in a one minute intervall trigger the other timeframes too? Even if they have UpdateOnClose? I Checked your exists and entries, all are on 15,30,45,00 for short and 00,30 for long.
Ciao taklause. Utilizzando il grafico a 1 minuto e fino al grafico a 15 minuti il codice funziona regolarmente sia nella versione Long che Short. Nello specifico la versione Long può essere usata solo con grafici da 1 fino a 30 minuti perchè il trailing stop è settato a 30 minuti. La versione Short può essere usata solo con grafici da 1 a 15 minuti perchè il trailing stop è settato a 15 minuti.
Il motivo di questa differenza tra le due versioni è solo per un tentativo di ottimizzazione del codice.