NexusFi: Find Your Edge


Home Menu

 





profit target turns into trailing stop loss


Discussion in NinjaTrader

Updated
    1. trending_up 3,957 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)
peaceNlove
Canada
 
Posts: 2 since Aug 2013
Thanks Given: 1
Thanks Received: 0

Hey I am working an an automated strategy and hoping to become an Elite member on this site should the strategy work.

I am wondering if it is possible to write a piece of code that is a profit target like order that turns into a trailing stop should the price of the instrument meet the profit target. What I hope to do with this is maximize the profitability of each position. I have done some back tests and found that sometimes the price continues to fall after the profit target is met and the position is closed.

In other words instead of having the activated profit target close the position, it turns into a trailing stop where the initial profit target number becomes the top of the trailing stop.

Currently I have this code and I hope that its possible to simply switch the profit target line with the described action.

protected override void Initialize()
{
SetStopLoss ("", CalculationMode.Percent, 0, false);
SetProfitTarget ("", CalculationMode.Percent, 0);

CalculateOnBarClose = true;
}

Hope this makes sense, thanks for your time/ patience


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CFTC Requests Tag 50 Trader Identity Data From CME and I …
Traders Hideout
CFTC Rewrites the Rulebook -- Kalshi Cracks $1B Non-Spor …
Prediction Markets & Event Contracts
Energy Futures Shatter All-Time Daily Volume: 8.3 Millio …
Commodities
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 dynoweb 
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 159



peaceNlove View Post
Hey I am working an an automated strategy and hoping to become an Elite member on this site should the strategy work.

I am wondering if it is possible to write a piece of code that is a profit target like order that turns into a trailing stop should the price of the instrument meet the profit target. What I hope to do with this is maximize the profitability of each position. I have done some back tests and found that sometimes the price continues to fall after the profit target is met and the position is closed.

In other words instead of having the activated profit target close the position, it turns into a trailing stop where the initial profit target number becomes the top of the trailing stop.

Currently I have this code and I hope that its possible to simply switch the profit target line with the described action.

protected override void Initialize()
{
SetStopLoss ("", CalculationMode.Percent, 0, false);
SetProfitTarget ("", CalculationMode.Percent, 0);

CalculateOnBarClose = true;
}

Hope this makes sense, thanks for your time/ patience

I'm not sure if I remember the correct combination but I believe that the SetStopLoss and the SetTrailingStop can't be used at the same time and I think that's what you're really wanting to do.

What you can do is to use code to inspect the price, if the target is reached, then change your trailing stop variable value to the target - x ticks (for a long) so it doesn't close immediately when hitting the target. Then on each tick update, check if the price hits the stop and exit your position. You will not be able to do this in the strategy back tester since it only triggers the on bar update at the close of the bar not on each tick, but you'll get a close approximation if your time frame or tick count is low.


Follow me on X Reply With Quote
Thanked by:
  #4 (permalink)
peaceNlove
Canada
 
Posts: 2 since Aug 2013
Thanks Given: 1
Thanks Received: 0

Great! thanks for your input.


Reply With Quote




Last Updated on August 22, 2013


© 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