NexusFi: Find Your Edge


Home Menu

 





Setdollartrailing for Each Position, not All


Discussion in EasyLanguage Programming

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




 
Search this Thread

Setdollartrailing for Each Position, not All

  #1 (permalink)
jkepha
San Antonio, TX
 
Posts: 31 since Apr 2020
Thanks Given: 10
Thanks Received: 6

Hello Friends,

So I am pyramiding/ buying at specified intervals. It seems as my trailing profit/set break even is being triggered for ALL the "current shares." I.e. one share breaks even or hits it's trailing profit then all of the shares are closed out.

I'm trying to code it to where each individual buy has its own trailing profit/break even (not if one share breaks even, it closes all my positions).

I'm thinking I might be able to accomplish this by having multiple windows open and running each buy on its own workspace, but seems like there might be an easier way.

Any help would be greatly appreciated!

Thanks,
Ryan

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Futures True Range Report
The Elite Circle
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
 
  #2 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


jkepha View Post
Hello Friends,

So I am pyramiding/ buying at specified intervals. It seems as my trailing profit/set break even is being triggered for ALL the "current shares." I.e. one share breaks even or hits it's trailing profit then all of the shares are closed out.

I'm trying to code it to where each individual buy has its own trailing profit/break even (not if one share breaks even, it closes all my positions).

I'm thinking I might be able to accomplish this by having multiple windows open and running each buy on its own workspace, but seems like there might be an easier way.

Any help would be greatly appreciated!

Thanks,
Ryan

Your method won't work, mainly because the servers don't care about charts, strategies, or anything other than the trade commands sent to it from the platform. You can deal with this in your code by using stop orders and specifying the number of contracts.

First, take a look at the _StpOrLim strategy. It may have some code to get you on your way.

There are a number of ways to scale out. Here is one idea:

 
Code
[IntrabarOrderGeneration = false]
vars: 
ScaleOutContracts(0) ,  // This will hold the number of contracts/shares you want to exit (sell or buytocover)
ScaleOutPrice (0)   // your sell price
;    

ScaleOutContracts = (CurrentContracts / 2 , 0) ;   // just an example... sell half our position

ScaleOutPrice = low[1]  ;   // just an example price

Condition1 = Close < Close[1]  ; // just my example here, but this is your condition for scaling out

//  For a long position
if marketposition = 1 and Condition1
   then
      Sell ScaleOutContracts contracts next bar at ScaleOutPrice stop  ;  this sets the trailing stop price for the number of contracts I want exit
Let me know if this helps.

~vmodus

Enjoy everything!
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
jkepha
San Antonio, TX
 
Posts: 31 since Apr 2020
Thanks Given: 10
Thanks Received: 6


Thank you!! What is scaleout? I can't find this reserved word / function in easy language documentation.


Thanks,
Ryan





vmodus View Post
Your method won't work, mainly because the servers don't care about charts, strategies, or anything other than the trade commands sent to it from the platform. You can deal with this in your code by using stop orders and specifying the number of contracts.

First, take a look at the _StpOrLim strategy. It may have some code to get you on your way.

There are a number of ways to scale out. Here is one idea:

 
Code
[IntrabarOrderGeneration = false]
vars: 
ScaleOutContracts(0) ,  // This will hold the number of contracts/shares you want to exit (sell or buytocover)
ScaleOutPrice (0)   // your sell price
;    

ScaleOutContracts = (CurrentContracts / 2 , 0) ;   // just an example... sell half our position

ScaleOutPrice = low[1]  ;   // just an example price

Condition1 = Close < Close[1]  ; // just my example here, but this is your condition for scaling out

//  For a long position
if marketposition = 1 and Condition1
   then
      Sell ScaleOutContracts contracts next bar at ScaleOutPrice stop  ;  this sets the trailing stop price for the number of contracts I want exit
Let me know if this helps.


Reply With Quote
  #4 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853


jkepha View Post
Thank you!! What is scaleout? I can't find this reserved word / function in easy language documentation.


Thanks,
Ryan

'ScaleOut' refers to my variable names. In the example code I shared, you would need to specify your condition for scaling out of a position (profit target, points, etc.). For example, if you have three contracts of ESZ20, you might want to exit one contract when you hit a profit target of $250. You can use the ContractProfit function to do this:

 
Code
// borrowed from TradeStation documentation
If ContractProfit >= 250 Then
  Sell 1 contract This Bar on Close;
Look at the help for this function, as they discuss using it to scale out of a position.

~vmodus

Enjoy everything!
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on October 15, 2020


© 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