NexusFi: Find Your Edge


Home Menu

 





Trail Stop


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Kush with 2 posts (0 thanks)
    2. looks_two Fat Tails with 2 posts (5 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 TigerStripes with 1 posts (0 thanks)
    1. trending_up 3,004 views
    2. thumb_up 5 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Trail Stop

  #1 (permalink)
Kush
San Sebastian/Spain
 
Posts: 12 since Sep 2011
Thanks Given: 0
Thanks Received: 1

Hi can anyone please show me to programm a 1000$ Dollar Trail from Close. This calculates a stop point from Highest close in the direction of the trade. And a 1000$ Dollar Trail from High. In this case this calculate a stop point from Highest High reached during the course of the trade.

I just know this type of trailing stop.

SetTrailStop("", CalculationMode.Ticks, 100, false);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - May 2024
Feedback and Announcements
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
34 thanks
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



Kush View Post
Hi can anyone please show me to programm a 1000$ Dollar Trail from Close. This calculates a stop point from Highest close in the direction of the trade. And a 1000$ Dollar Trail from High. In this case this calculate a stop point from Highest High reached during the course of the trade.

I just know this type of trailing stop.

SetTrailStop("", CalculationMode.Ticks, 100, false);


You would need to convert the $ amount into ticks. For every instrument you know the $ value for a point and you know the tick size.

For example for ES the ticksize is 0.25 and the point value is $ 50. The number of ticks that correspond to $ 1000 are

number of ticks = $ 1000 / (point value * ticksize) = 1000 / (50 * 0.25) = 80


To use this with a trail stop you will first have to calculate the number of ticks that correspond to $ 1000 and then enter that value into SetTrailStop. The first calculation can be done in OnStartUp(), as you will only need to do it once.


 
Code
protected override void OnStartUp()
{
        ......
        // declare trailStopInTicks in the Variables region, as you need it in OnBarUpdate()
        double pointValue = Instrument.MasterInstrument.PointValue;
        double tickSize = Instrument.MasterInstrument.TickSize;
        double trailingAmount = 1000.00 // selected $ amount
        trailStopInTicks =  trailingAmount / (pointValue * tickSize);
        ......
}

....

protected override void OnBarUpdate()
{
        ......
        SetTrailStop(CalculationMode.Ticks, trailStopInTicks);
        ......
 }



This was just to explain the mechanics. If you prefer a simple solution, you can also use

 
Code
SetTrailStop(1000);

Reply With Quote
  #4 (permalink)
Kush
San Sebastian/Spain
 
Posts: 12 since Sep 2011
Thanks Given: 0
Thanks Received: 1

Thank you for the explanation. What I want to know it's difference in point of programming between Dollar Trail from Close and Dollar Trail from High. I mean to see the code in both trail stops... so I can see the difference.

According to page 188 of the book The Computer Analysis of The Futures Market a Dollar Trail from Close is calculated from highest close or lowest close in the direction of the trade.

And a Dollar Trail from High is calculated from highest high or lowest low reached during the course of the trade. What I need is the code to see the difference between both stops.

Thank you.....

Reply With Quote
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Kush View Post
Thank you for the explanation. What I want to know it's difference in point of programming between Dollar Trail from Close and Dollar Trail from High. I mean to see the code in both trail stops... so I can see the difference.

According to page 188 of the book The Computer Analysis of The Futures Market a Dollar Trail from Close is calculated from highest close or lowest close in the direction of the trade.

And a Dollar Trail from High is calculated from highest high or lowest low reached during the course of the trade. What I need is the code to see the difference between both stops.

Thank you.....


@Kush: Whether you want to calculate a trailing stop from the highest high or the highest close is your personal choice. Both is possible.

The book you are referring to dates back to 1991. Charles LeBeau and David Lucas traded futures on daily data, so they used the daily close (probably the settlement price) to trail the stops. If you look at more recent publications by Charles LeBeau, you will realize that he meanwhile trails his stops from the highest high for long and lowest low for short positions. This is what he calls the "Chandelier" exit, as he uses the high points of the candles of the chandelier.

If you run a strategy on NinjaTrader, you will probably run in safe mode, that is set to "CalculateOnBarClose = true". In that case NinjaTrader should adjust the stop price to the close and not to the high or low of the bar. In that case SetTrailStop() cannot be used to build a chandelier exit, as it does not take into account the high or low, when the strategy is set to "CalculateOnBarClose = true".

Actually I never use SetTrailStop(). Instead I use SetStopLoss() and calculate the stop price myself, either from the high, low or from the close. I don't leave that to NinjaTrader.

Reply With Quote
Thanked by:
  #6 (permalink)
Edal Grame
El Salvador
 
Posts: 1 since Jul 2021
Thanks Given: 0
Thanks Received: 0


Fat Tails View Post
@Kush: Whether you want to calculate a trailing stop from the highest high or the highest close is your personal choice. Both is possible.

The book you are referring to dates back to 1991. Charles LeBeau and David Lucas traded futures on daily data, so they used the daily close (probably the settlement price) to trail the stops. If you look at more recent publications by Charles LeBeau, you will realize that he meanwhile trails his stops from the highest high for long and lowest low for short positions. This is what he calls the "Chandelier" exit, as he uses the high points of the candles of the chandelier.

If you run a strategy on NinjaTrader, you will probably run in safe mode, that is set to "CalculateOnBarClose = true". In that case NinjaTrader should adjust the stop price to the close and not to the high or low of the bar. In that case SetTrailStop() cannot be used to build a chandelier exit, as it does not take into account the high or low, when the strategy is set to "CalculateOnBarClose = true".

Actually I never use SetTrailStop(). Instead I use SetStopLoss() and calculate the stop price myself, either from the high, low or from the close. I don't leave that to NinjaTrader.

HOLA, buenas tardes soy de EL SALVADOR, he leído la explicación a @Kush, puedes ayudarme a explicar más sobre SetTrailStop(), tengo una estrategia automática que me hace mis entradas y cierres en el take Profit, pero me gustaría optimizar la con un trail stop, pero me gustaría que el trail stop fuera tick a tick que siga al precio pero entiendo cómo configurar el código para que cuando ya esté dentro de la operación el SetTrailStop() siga tick a tick al precio a una distancia

Puedes por favor enseñarme y mostrarme cómo programar ese código, por favor ? Gracias

Reply With Quote
  #7 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,168 since Jan 2013
Thanks Given: 57,464
Thanks Received: 26,278


Edal Grame View Post
HOLA, buenas tardes soy de EL SALVADOR, he leído la explicación a @Kush, puedes ayudarme a explicar más sobre SetTrailStop(), tengo una estrategia automática que me hace mis entradas y cierres en el take Profit, pero me gustaría optimizar la con un trail stop, pero me gustaría que el trail stop fuera tick a tick que siga al precio pero entiendo cómo configurar el código para que cuando ya esté dentro de la operación el SetTrailStop() siga tick a tick al precio a una distancia

Puedes por favor enseñarme y mostrarme cómo programar ese código, por favor ? Gracias

Hi @Edal Grame,

Please do not post in a non-English language in the English sections of the forum.

It makes it hard for others to understand your posts and to respond.

Thanks.

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
  #8 (permalink)
 TigerStripes   is a Vendor
 
Posts: 109 since Mar 2021
Thanks Given: 33
Thanks Received: 56

Is it possible to help me to code a trailing stop that is defined by me rather than just a satic trailing stop in ninjatrader.

Want to initial paramteres to be met
#1 when trail that a certain number of ticks the trail price improves and continues to act as a trail.

#2 similar to that, instead of a crtain number of ticks price may reach, second is if the first target profit order in a pos is hit the trail improves to a set number of ticks behind price and continues to trail price.

Reply With Quote




Last Updated on October 5, 2021


© 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