stoploss to breakeven to trailing - futures io
futures io



stoploss to breakeven to trailing


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one wgreenie with 4 posts (2 thanks)
    2. looks_two stephenszpak with 3 posts (1 thanks)
    3. looks_3 Eloy with 2 posts (0 thanks)
    4. looks_4 aslan with 2 posts (5 thanks)
      Best Posters
    1. looks_one aslan with 2.5 thanks per post
    2. looks_two cory with 1 thanks per post
    3. looks_3 Trader.Jon with 1 thanks per post
    4. looks_4 wgreenie with 0.5 thanks per post
    1. trending_up 9,184 views
    2. thumb_up 10 thanks given
    3. group 7 followers
    1. forum 13 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

stoploss to breakeven to trailing

(login for full post details)
  #1 (permalink)
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

Hi

I have an idea regarding trading the YM. I am having a difficult time with the
coding of the stops. I think I know how to take the stop loss stop and turn
it into a breakeven stop. Unfortunately I don't know how to move the breakeven
up with each upward (downward) tick of the YM.

If the YM is above the breakeven by 10 points that is fine.
If the YM goes up one point I would need the breakeven to turn into a trailing
stop, with the YM still above the stop (in this case trailing) by 10 points.

Someone at another forum gave me some code, and some of that is here:

link: NinjaTrader Support Forum - View Single Post - Trailing stop not working on backtest

SLPrice=Position.AvgPrice;
SetStopLoss(CalculationMode.Price,SLPrice);

I realize I can keep incrementing the variable SLPrice if Close[0] increases.
Not positive how, but along these lines I think:


if(Close[0]>Position.AvgPrice+11
{
SLPrice=Position.AvgPrice;
SLPrice=Position.AvgPrice+
1;

SetStopLoss(CalculationMode.Price,SLPrice);
}

First the coding might be wrong, but besides that there would have to
be a few hundred lines of code (just for a bull move) as the YM moves
up. A little block something like the above for every tick up. What if
the YM moves up 50 points?!

Anyway I was hoping that someone already had this problem and had it
answered, or at least maybe someone has an idea to create a loop
(or equivalent) with NinjaScript to avoid writing such a long program.

(Back tomorrow if possible.)

- Stephen

Started this thread Reply With Quote

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(96 thanks from 15 posts)
looks_twoSalao's Journalby Salao
(32 thanks from 7 posts)
looks_3Deetee’s DAX Trading Journal (time based)by Deetee
(26 thanks from 10 posts)
looks_4Learning to Profit - A journey in algorithms and optionsby Syntax
(13 thanks from 8 posts)
looks_5Maybe a little bit different journalby Malykubo
(9 thanks from 8 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Would You Sell Your System?
71 thanks
The Crude Dude Oil Trading System
40 thanks
Big Mike in Ecuador
36 thanks
futures io site changelog and issues/problem reporting
24 thanks
The New Micro Contract - MICRO BITCOIN coming May 2021
23 thanks
 
(login for full post details)
  #2 (permalink)
Eloy
Moscow
 
 
Posts: 12 since Jan 2010
Thanks: 1 given, 8 received

There is no problem with a long program if you post your code into OnBarUpdate() event - the code will execute every incoming tick.

Reply With Quote
 
(login for full post details)
  #3 (permalink)
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received


Thanks for the reply.

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
Eloy
Moscow
 
 
Posts: 12 since Jan 2010
Thanks: 1 given, 8 received

And remember set CalculateOnBarClose = false; to run OnBarUpdate() on each tick - http://ww16.ninjatrader-support.com/HelpGuideV6/helpguide.html?CalculateOnBarClose1&sub1=20210413-1310-5898-8972-259f560e9a75

Reply With Quote
 
(login for full post details)
  #5 (permalink)
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 183 received

Stephen,

This code was written by a consultant for another project of mine. I have parsed out specifics for stops: perhaps it might be useful as you develop your code. Sorry, I cant support it as I am barely at the point of understanding what parts of the strategy go where, but I am trying!

Attached Files
Register to download File Type: txt BE_trailingSTOP.txt (17.4 KB, 459 views)
Reply With Quote
The following user says Thank You to Trader.Jon for this post:
 
(login for full post details)
  #6 (permalink)
 wgreenie 
Cambridge, Ontario
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,203 received

Hi Stephen

I also tried for weeks to have a trail code "functioning" in my strategies. Can certainly understand the stress and frustration when days and nights were spent and nothing seemed working.

Just got the enclosed sample and hope it may help you. Good Luck!

Beth

Attached Files
Register to download File Type: cs ProfitTargetTrailingStop_1[1].01b.cs (7.9 KB, 345 views)
Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to wgreenie for this post:
 
(login for full post details)
  #7 (permalink)
 wgreenie 
Cambridge, Ontario
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,203 received


Eloy View Post

Sorry to throw in another idea here which is opposite to yours. I learned the following from a more experienced member:

Quote
Due to its inherent design, Ninja forces limitations upon your strategy. As an example, Ninja requires that you set OnBarClose to true in order to have any chance at success. That alone limits your design tremendously.
Unquote

Based on my experiences, when I had CalculateOnBarClose @false, sim-trade and Market Replay results had looping trades, ie 1 smooth short trade became choppy trades in-and-out within a second. Not able to identify the cause for sure though with CalculateOnBarClose @true there're no looping trades.

Beth

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #8 (permalink)
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
 
aslan's Avatar
 
Posts: 617 since Jan 2010
Thanks: 351 given, 1,111 received


wgreenie View Post
Quote
Due to its inherent design, Ninja forces limitations upon your strategy. As an example, Ninja requires that you set OnBarClose to true in order to have any chance at success. That alone limits your design tremendously.
Unquote

Sorry, I don't mean to burst your bubble, but this is just not true.

There are two models that you have to choose between. You can either process data at the end of each bar (which is really the beginning of the next bar depending on the bar type) or on each incoming tick. The former is when CalcOnBarClose=true and the latter is when CalcOnBarClose=false.

With either model, you need to understand what Ninja is actually doing behind the scenes when you are calling the enter/exit/setStop/etc routines. Sadly, the doc almost helps (all of the little warnings that this is advanced coding should be a red flag).

Unfortunately, it is pretty easy to write code that works well in backtests, but fails when you run live. This is usually a problem in the strategy coding, not some limitation in Ninja. If you want to be accurate, you need to use COBC=false, but that means you need to dig in and really understand what is going on.

Reply With Quote
The following 3 users say Thank You to aslan for this post:
 
(login for full post details)
  #9 (permalink)
 wgreenie 
Cambridge, Ontario
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,203 received

Thanks aslan. That's good news that CalculateOnBarClose @ false will work IF one knows what's going on! Unfortunately not me as for some unknown reasons seemed it might have triggered looping trades PLUS for weeks now I still have a super-mega big head trying to make a simple strategy with a trail code to work!!

Good Luck to Stephen and me!

Beth

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #10 (permalink)
 cory 
the coin hunter
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
 
cory's Avatar
 
Posts: 6,042 since Jun 2009
Thanks: 854 given, 7,910 received


cut & paste this into goggle box , remember to take out a space between .

Trailing Stop strategy site:www .ninjatrader-support2 .com

Reply With Quote
The following user says Thank You to cory for this post:
 
(login for full post details)
  #11 (permalink)
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
 
aslan's Avatar
 
Posts: 617 since Jan 2010
Thanks: 351 given, 1,111 received

Here are a couple of items to try:

* limit your data set (i.e. specific day or less) to help cut down on the amount of info to sift thru when debugging

* use set TraceOrders = true in Initialize() in order to see all order actions in Ninja in the output window, this combined with your own prints should help you figure out where your looping is coming from.

* make sure you are doing compare of price values correctly, Close[0] > lastPrice does not cut it when comparing double values. Just comparing values works most of the time, but you really need to use the following: Instrument.MasterInstrument.Compare() - see help. I hate needing this, and I usually leave it out until I get to the final code and then add it in. If you have a comparison that you think should trigger this could be it.

Hope this gives you some ideas.

Reply With Quote
The following 2 users say Thank You to aslan for this post:
 
(login for full post details)
  #12 (permalink)
 stephenszpak 
Massachusetts (USA)
 
Experience: None
Platform: NinjaTrader
Trading: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 356 received

Not doing much regarding a system these days. I do thank you all though,
Beth, cory, and Aslan.

P.S. Beth, I did come across a programmer that seems to be very knowledgeable,
should you need his name someday.

- Stephen

Started this thread Reply With Quote
The following user says Thank You to stephenszpak for this post:
 
(login for full post details)
  #13 (permalink)
 danayster 
New York
 
Experience: Intermediate
Platform: thinkorswim
Trading: options
 
Posts: 28 since Feb 2014
Thanks: 62 given, 42 received


wgreenie View Post
Hi Stephen

I also tried for weeks to have a trail code "functioning" in my strategies. Can certainly understand the stress and frustration when days and nights were spent and nothing seemed working.

Just got the enclosed sample and hope it may help you. Good Luck!

Beth

Wow, this script right here is exactly why I joined the elite futures.io (formerly BMT) section. Super thanks, I know its 4 years later but NT is still the leader!

Reply With Quote
 
(login for full post details)
  #14 (permalink)
 wgreenie 
Cambridge, Ontario
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Trading: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,203 received

Yes Stephen. NT Support Forum is extremely important/helpful for my learning. You can also email the NT support team directly for any issues you may have.

Good Trading is about Trading Right!
Want What the Market Wants!
Trade With the Trend!
Visit my futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > stoploss to breakeven to trailing


Last Updated on October 13, 2014


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1,800 in prizes!

April

Seven Trading Mistakes Solved With Smart Trading Tools w/Brannigan Barrett

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts