The strat synopsis is quite simple :
step1 : open X contracts with a stoploss at, say, -10pips below EntryPrice and a partial exit of X/2 contracts at, say, +20pips above EntryPrice
Then, as soon as the partial exit has been reached and executed :
step2: place a new s/l at break-even (EntryPrice) and a final exit (of the remainder X/2 contracts) at, say, +30pips above EntryPrice
My code works PERFECTLY on backtesting, but does not work quite right on A/T with FXCM.
Step1 works alright, FXCM takes all the orders well, shows them in the TradingStation while MultiCharts shows them right on the chart and both exit and stoploss work great.
But then, when it comes to step2, after the partial exit has been reached : the position is left opened at FXCM with X/2 contracts (that is normal) but the new stoploss (the one at break-even) as well as the new profit (the one at +30pips) are NO LONGER accepted nor rejected (!) by FXCM and my remaining position (X/2) remains opened until I have to close it manually !
Here's the piece of code that I use (LONG entry only in this example) :
Code: Select all
[intrabarOrderGeneration=true] ;
// Opening
// *******
if MP=0 and Long_SetUp=true then Buy ("LongEntry") OpenContracts contracts next bar at targetprice stop;
// Profit Exits
// ************
if MP>0 and CurrentContracts=OpenContracts then Sell ("ProfitExit1") OpenContracts/2 contracts next bar at (Entryprice+20pips) limit;
if MP>0 and CurrentContracts<>OpenContracts then Sell ("ProfitExit2") all contracts next bar at (Entryprice+30pips) limit;
// StopLoss Exits
// **************
if MP>0 and CurrentContracts=OpenContracts then Sell ("LossExit") all contracts next bar at (Entryprice-10pips) stop;
if MP>0 and CurrentContracts<>OpenContracts then Sell ("BEExit") all contracts next bar at (Entryprice) stop;