I tried a strategy when an once opened Position reaches takeprofit it should close and open a reverse Position.
Code: Select all
inputs: Price( Close ), LengthMA( 20 ), Distance( 0.002 ), TakeProfit( 0.0025),Lot( 25000 ),
Stoploss( 0.005 );
variables: SMA( 0 ), Exitlong( 0 ), Exitshort( 0 ), Stoplong( 0 ),Stopshort( 0 );
[IntrabarOrderGeneration = true];
SMA= Average( Price, LengthMA );
Exitlong = (entryprice + TakeProfit);
Exitshort = (entryprice - TakeProfit);
Stoplong=(entryprice - Stoploss);
Stopshort=(entryprice + Stoploss);
condition1 = Currentbar > 1 and (marketposition=0) and (Close < SMA-Distance);
condition2 = Currentbar > 1 and (marketposition=0) and (Close > SMA+Distance);
if condition1 then
Buy ( "LE1W" ) Lot contracts this bar on close ;
if ((marketposition = 1) and (currentcontracts = Lot))
Sell ("LX1W" ) 2*Lot contracts next bar at Exitlong limit;
Sell ("LX1SL" ) Lot contracts next bar at Stoplong stop;
if condition2 then
sellshort ( "SE1W" ) Lot contracts this bar on close ;
if ((marketposition = -1) and (currentcontracts=Lot))
buytocover ("SX1W" ) 2*Lot contracts next bar at Exitshort limit;
buytocover ("SX1SL" ) Lot contracts next bar at Stopshort stop;
Instead of "close and open" MC only close the Position and starts with condition1 again.
For Future-markets I could change the code to 2 different orders instead of " 2*Lot ".
But I need this strategy in Forex markets and at IB one order costs $ 2.50+.
So I tried to make the reversal with 1 order instead of 2.
Is there a way to force MC to sell/buy the double amount of the current open position to the opposite direction?