Code conditions to close a long position

Questions about MultiCharts and user contributed studies.
hendrix
Posts: 54
Joined: 27 Dec 2013
Has thanked: 21 times
Been thanked: 5 times

Code conditions to close a long position

Postby hendrix » 20 Mar 2014

Hello everybody

I m wondering how to code "exitlong" or "exitshort" conditions.
Below, you can see my extrait of my code (which doesn't work...)

Code: Select all

// exitlong conditions

If (Marketposition = 1) then begin
Sell currentbar at entryprice+5 ;
end;
setstoploss (-5);
As soon as a long (buy) position is open (order n°1), I would send two another orders :
order n°2 => it would be placed to "myentryprice + 5 ticks" (with limit order and on the current bar)
and
order n°3 => it would be placed to "myentryprice - 5 ticks" (with market order, a kind of stoploss...)
and "if current price = myentryprice + 2 ticks" then the order n°3 is going up to this level.

Anybody have an idea please?

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Code conditions to close a long position

Postby MAtricks » 20 Mar 2014

Code: Select all

Inputs:
Buffer( 5 ),
SL( 5 ) ;


if MP[1]<=0 and MP>0 then
sell next bar AvgEntryPrice+Buffer Limit ;

Setstoploss( SL ) ;

hendrix
Posts: 54
Joined: 27 Dec 2013
Has thanked: 21 times
Been thanked: 5 times

Re: Code conditions to close a long position

Postby hendrix » 21 Mar 2014

Hi MAtricks

thanks for your proposition, I m going to try it

++

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Code conditions to close a long position

Postby MAtricks » 21 Mar 2014

I hope it helps. If you're trading multiple symbols, you might want to convert the Buffer (PT) into a Points or Ticks which would be universal.


Return to “MultiCharts”