Problem with Position reversal

Questions about MultiCharts and user contributed studies.
User avatar
aiti
Posts: 43
Joined: 25 May 2009
Location: Germany
Has thanked: 43 times
Been thanked: 20 times

Problem with Position reversal

Postby aiti » 29 Jan 2011

Hello MC community,

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
begin
Buy ( "LE1W" ) Lot contracts this bar on close ;
end;

if ((marketposition = 1) and (currentcontracts = Lot))
then
begin
Sell ("LX1W" ) 2*Lot contracts next bar at Exitlong limit;
Sell ("LX1SL" ) Lot contracts next bar at Stoplong stop;
end;

if condition2 then
begin
sellshort ( "SE1W" ) Lot contracts this bar on close ;
end;

if ((marketposition = -1) and (currentcontracts=Lot))
then
begin
buytocover ("SX1W" ) 2*Lot contracts next bar at Exitshort limit;
buytocover ("SX1SL" ) Lot contracts next bar at Stopshort stop;

end;
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?

aiti

Return to “MultiCharts”