NexusFi: Find Your Edge


Home Menu

 





profit target turns into trailing stop loss


Discussion in NinjaTrader

Updated
    1. trending_up 4,045 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?
Sundays Verdict: Lebanon Locked at 99.85% as Iran June 7 …
Prediction Markets & Event Contracts
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
April CPI Preview: +3.7% YoY Expected at 8:30 AM ET -- C …
Traders Hideout
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
Weekend Update: First Qatari LNG Transit Attempted -- IR …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 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