NexusFi: Find Your Edge


Home Menu

 





Code conditions to close a long position


Discussion in MultiCharts

Updated
    1. trending_up 2,570 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
ruliann
France
 
Posts: 3 since Dec 2013
Thanks Given: 0
Thanks Received: 0

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
// 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?


Reply With Quote

 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

ruliann,

there are some things that catch my eye: the limit exit order should be "next bar" and tick based exits should be converted to points. To exit a trade with the build in setstop loss the input should be positive and is dollar based.
So your code can look something like this:

 
Code
Inputs: PositionBasis( false ), StopTicks( 5 ) ;

Variables:
	vStopPoints	(0),
	StopAmount	(0),
	vOneTick	(0);
	
once
begin
	vOneTick = MinMove/PriceScale;
	vStopPoints = StopTicks * vOneTick;
	
	StopAmount = vStopPoints * BigPointValue;	
end;

//limit exit
If (Marketposition = 1) then 
	Sell ("LX") next bar entryprice + vStopPoints limit;

//stop loss part
if PositionBasis then
	SetStopPosition
else
	SetStopShare ;

SetStopLoss( StopAmount ) ;
Regards,
ABCTG


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
ruliann
France
 
Posts: 3 since Dec 2013
Thanks Given: 0
Thanks Received: 0


Hi ABCTG

Interesting your proposition, I m going to try it

I will keep you updated !

tks


Reply With Quote




Last Updated on March 21, 2014


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts