Strategy with CCI (adjustable TF depending on the trading asset)
Forums › ProRealTime English forum › ProOrder support › Strategy with CCI (adjustable TF depending on the trading asset)
- This topic has 2 replies, 2 voices, and was last updated 3 years ago by
macdopa.
-
-
05/27/2021 at 8:44 AM #170367
It is clear that it is difficult to have a trading code that could take place for a long time exactly as intended by its designers. On the other hand, this code could well be profitable on certain financial instruments (Crypto, Forex, Shares or Indices) while checking it beforehand on backtest at different timeframes. Example: BTC / USD at TimeFrame = 20min and 2 minutes; EUR / USD at TimeFrame = 100 ticks or 15 30 45 min or 1 hour; DAX, etc. NB: There is the possibility of being able to improve it by the professionals that you are and to share …
12345678910111213141516171819202122232425262728DEFPARAM CumulateOrders=False//CCI strategy with limit threshold for input or output signalOnce Quantite = 1 //(1*PipValue)Once Interval = 55Once SeuilCCI = 170 //(OK at: 100,150,'170',180)indicoteNegatif = CCI[Interval](Close) < -SeuilCCIindicotePositif = CCI[Interval](Close) > SeuilCCIindicator1 = CCI[Interval](Close)indicator2 = Highest[7](CCI[Interval](Close[1]))indicator3 = Highest[6](CCI[Interval](Close[3]))c1 = (indicator3 < indicator2) AND (indicator2 < indicator1)c2 = (indicator3 > indicator2) AND (indicator2 > indicator1)REM BUYIF indicoteNegatif AND c1 THENBUY Quantite SHARES AT MARKETELSIF LongOnMarket AND indicotePositif THENEXITSHORT AT MARKETENDIFREM SELLIF indicotePositif AND c2 THENSELLSHORT Quantite SHARES AT MARKETELSIF Not LongOnMarket AND indicoteNegatif THENEXITSHORT AT MARKETENDIFThanks…
2 users thanked author for this post.
05/29/2021 at 11:59 AM #170728I modified it by using MTF (1h TF for the setup & entry + 5m TF for the trailing stop):
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889DEFPARAM CumulateOrders=False//CCI strategy with limit threshold for input or output signaltimeframe(1h,UpdateOnClose)//Once Quantite = 1 //(1*PipValue)Once Interval = 55Once SeuilCCI = 170 //(OK at: 100,150,'170',180)indicoteNegatif = CCI[Interval](Close) < -SeuilCCIindicotePositif = CCI[Interval](Close) > SeuilCCIindicator1 = CCI[Interval](Close)indicator2 = Highest[7](CCI[Interval](Close[1]))indicator3 = Highest[6](CCI[Interval](Close[3]))c1 = (indicator3 < indicator2) AND (indicator2 < indicator1)c2 = (indicator3 > indicator2) AND (indicator2 > indicator1)REM BUYIF indicoteNegatif AND c1 THENBUY Quantite SHARES AT MARKETELSIF LongOnMarket AND indicotePositif THENEXITSHORT AT MARKETENDIFREM SELLIF indicotePositif AND c2 THENSELLSHORT Quantite SHARES AT MARKETELSIF Not LongOnMarket AND indicoteNegatif THENEXITSHORT AT MARKETENDIF//Timeframe(default)//// Nicolas' trailing stop code, slightly modified to://// - acount for minimum distance required by the broker for pending orders// - start trailing not only from the first bar, but from any later bar//IF (BarIndex - TradeIndex) >= 0 THEN //start from the first bar or a later onetrailingstart = 20 //20 trailing will start @trailinstart points profittrailingstep = 10 //10 trailing step to move the "stoploss"distance = 10 //10 pips distance from caurrent price (if required by the broker)//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENIF LongOnMarket THENIF (close + distance) > newSL THENSELL AT newSL STOPELSIF (close - distance) < newSL THENSELL AT newSL LIMITELSESELL AT MarketENDIFELSIF ShortOnmarket THENIF (close + distance) < newSL THENEXITSHORT AT newSL STOPELSIF (close - distance) > newSL THENEXITSHORT AT newSL LIMITELSEEXITSHORT AT MarketENDIFENDIFENDIFENDIF//*********************************************************************************1 user thanked author for this post.
05/30/2021 at 12:41 PM #170779Thank you very much RobertoGozzi
The code worked well with the gains and loss limitation.
NB: The CCI Threshold and TimeFrame parameters should be adjusted for each financial asset.
Here are the best results obtained with the optimal values of the 2 adjustable parameters:
– For BTC/USD ==>
CCI threshold = 170
TimeFrame (1 minutes, UpdateOnClose)– For EUR/USD ==>
CCI threshold = 140
TimeFrame (3 minutes, UpdateOnClose)– For GBP/USD ==>
CCI threshold = 170
TimeFrame (10 minutes, UpdateOnClose)– For USD/CHF ==>
CCI threshold = 100 and 120
TimeFrame (3 minutes, UpdateOnClose)Even more, it would be necessary to define the values of Stop and follower, as for example:
trailingstart = 150 // 20 trailing will start @trailinstart points profit
trailingstep = 15 // 10 trailing step to move the “stoploss”
distance = 15 // 10 pips distance from caurrent price (if required by the broker)Thanks…
5 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on