NexusFi: Find Your Edge


Home Menu

 





Update profit target or trailing stop based on trade conditions


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #1 (permalink)
 
ShadowFox's Avatar
 ShadowFox 
CO/USA
 
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
Posts: 129 since Jun 2020
Thanks Given: 70
Thanks Received: 159

Does setprofittarget, SetPercentTrailing, and setstoploss get called on each bar or is it run once per strategy? I am struggling to get the below to be able to update values. Any ideas?

If Condition1 = true then Begin
PT = Condition1PT;
TrlAmnt = Condition1TrlAmnt;
TrlPcnt = Condition1TrlPcnt;
SL = Condition1SL;
end
else if Condition2 = true then begin
PT = Condition2PT;
TrlAmnt = Condition2TrlAmnt;
TrlPcnt = Condition2TrlPcnt;
SL = Condtion2SL;
end;

setprofittarget(PT*Bigpointvalue);
SetPercentTrailing( TrlAmnt, TrlPcnt );
setstoploss(SL*Bigpointvalue);


Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CME Group Fee Schedule Changes Hit All Four Exchanges -- …
Traders Hideout
CME Lists U.S. Election Event Contracts as 2028 Democrat …
Prediction Markets & Event Contracts
Kalshi Rockets to $22B, Passes Polymarket in Volume -- B …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
Ceasefire in Name Only: Three Numbers That Define the Ir …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
BERN ALGOS algo trading journal
8 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

jeffc1000,

when you say "I am struggling to get the below to be able to update values", what happens exactly within your code? Did you use the print statement to check if the Condition1 and Condition2 variables are actually true on separate bars and if the values for your variables are updated?

Regards,

ABCTG


jeffc1000 View Post
Does setprofittarget, SetPercentTrailing, and setstoploss get called on each bar or is it run once per strategy? I am struggling to get the below to be able to update values. Any ideas?

If Condition1 = true then Begin
PT = Condition1PT;
TrlAmnt = Condition1TrlAmnt;
TrlPcnt = Condition1TrlPcnt;
SL = Condition1SL;
end
else if Condition2 = true then begin
PT = Condition2PT;
TrlAmnt = Condition2TrlAmnt;
TrlPcnt = Condition2TrlPcnt;
SL = Condtion2SL;
end;

setprofittarget(PT*Bigpointvalue);
SetPercentTrailing( TrlAmnt, TrlPcnt );
setstoploss(SL*Bigpointvalue);


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
 
ShadowFox's Avatar
 ShadowFox 
CO/USA
 
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
Posts: 129 since Jun 2020
Thanks Given: 70
Thanks Received: 159



ABCTG View Post
jeffc1000,

when you say "I am struggling to get the below to be able to update values", what happens exactly within your code? Did you use the print statement to check if the Condition1 and Condition2 variables are actually true on separate bars and if the values for your variables are updated?

Regards,

ABCTG

You were right ABCTG. Looks like both conditions were false due to some other clearing logic I had going on. I have resolved the issue. Lesson learned, don't wrestle with one problem too long, sleep on it and clarity will come.


Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #4 (permalink)
 
FastNCurious's Avatar
 FastNCurious 
saint louis MO
 
Experience: Intermediate
Platform: TradeStation
Trading: NQ, ES, YM, CL, GC
Posts: 149 since Oct 2017
Thanks Given: 95
Thanks Received: 177

I have a question for @ABCTG ,

I am trying to create a trailing stop that moves my stoploss up to a specific positive value after the trade reaches the first target. I do not want it to be a percentage because as the first target is hit my next target is 2x first target and I want the difference to be the same value
from entry to original stoploss as the 1st profit threshold to 2nd stoploss.

(entry price - stoploss 1) = (profitthreshold1-stoploss 2)

I know I am asking a very simple question but for the life of me I can't figure it out.

I thought about moving the stoploss to a negative value since it is on the opposite side of a negative loss compared to the entry price. I don't think this will work but I will give it a try.

I have also had this idea come up before because I wanted to set a breakeven stop to breakeven plus a few ticks in the positive direction so I will more than likely not eat any slippage and commissions on a breakeven trade. I was unable to figure this out before but I imagine once I have the answer for one the other would be quite easy.


Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

@FastNCurious,

I am not sure I follow you correctly as you seem to have the equation laid out already. You would just have to solve it for "stoploss 2":

stoploss 2 = profitthreshold1 - (entry price - stoploss 1)

You might want to consider using an actual stop order here instead of using negative values for "setstoploss".

Regards,

ABCTG


FastNCurious View Post
I have a question for @ABCTG ,

I am trying to create a trailing stop that moves my stoploss up to a specific positive value after the trade reaches the first target. I do not want it to be a percentage because as the first target is hit my next target is 2x first target and I want the difference to be the same value
from entry to original stoploss as the 1st profit threshold to 2nd stoploss.

(entry price - stoploss 1) = (profitthreshold1-stoploss 2)

I know I am asking a very simple question but for the life of me I can't figure it out.

I thought about moving the stoploss to a negative value since it is on the opposite side of a negative loss compared to the entry price. I don't think this will work but I will give it a try.

I have also had this idea come up before because I wanted to set a breakeven stop to breakeven plus a few ticks in the positive direction so I will more than likely not eat any slippage and commissions on a breakeven trade. I was unable to figure this out before but I imagine once I have the answer for one the other would be quite easy.


Follow me on X Reply With Quote




Last Updated on March 26, 2021


© 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