NexusFi: Find Your Edge


Home Menu

 





Code conditions to close a long position


Discussion in MultiCharts

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




 
Search this Thread

Code conditions to close a long position

  #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

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

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 Twitter 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts