NexusFi: Find Your Edge


Home Menu

 





Setdollartrailing for Each Position, not All


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #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?
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
TradingView Deploys AI to Monitor SEC Filings in Real Ti …
TradingView
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
Iran Forward Curve: June 30 at 56% vs June 15 at 28% -- …
Prediction Markets & Event Contracts
Orban at 29pct as Hungary Votes Tomorrow -- McIlroy Surg …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
197 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #2 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
Systematic Algo Trader
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,270 since Feb 2017
Thanks Given: 2,960
Thanks Received: 2,856


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 X 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
Systematic Algo Trader
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,270 since Feb 2017
Thanks Given: 2,960
Thanks Received: 2,856


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 X Visit my NexusFi Trade Journal Reply With Quote




Last Updated on October 15, 2020


© 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