stoploss to breakeven to trailing - NinjaTrader Programming | futures io social day trading
futures io futures trading


stoploss to breakeven to trailing
Updated: Views / Replies:6,974 / 13
Created: by stephenszpak Attachments:2

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 2  
 
Thread Tools Search this Thread
 

stoploss to breakeven to trailing

  #1 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received

stoploss to breakeven to trailing

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

Reply With Quote
 
  #2 (permalink)
Just starting out...
Moscow
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 12 since Jan 2010
Thanks: 1 given, 6 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
 
  #3 (permalink)
Elite Member
Massachusetts (USA)
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: YM
 
stephenszpak's Avatar
 
Posts: 778 since Jun 2009
Thanks: 144 given, 358 received


Thanks for the reply.

Reply With Quote
 
  #4 (permalink)
Just starting out...
Moscow
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 12 since Jan 2010
Thanks: 1 given, 6 received

And remember set CalculateOnBarClose = false; to run OnBarUpdate() on each tick - http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CalculateOnBarClose1

Reply With Quote
 
  #5 (permalink)
Elite Member
Near the BEuTiFULL Horse Shoe
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: MBTrading Dukascopy ZenFire
Favorite Futures: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 176 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, 416 views)
Reply With Quote
The following user says Thank You to Trader.Jon for this post:
 
  #6 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 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, 313 views)
Reply With Quote
The following 2 users say Thank You to wgreenie for this post:
 
  #7 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 received


Eloy View Post
And remember set CalculateOnBarClose = false; to run OnBarUpdate() on each tick - http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CalculateOnBarClose1

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

Reply With Quote
 
  #8 (permalink)
Elite Member
Madison, WI
 
Futures Experience: Advanced
Platform: Sierra Charts, ALT
Favorite Futures: ES
 
aslan's Avatar
 
Posts: 614 since Jan 2010
Thanks: 342 given, 1,077 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:
 
  #9 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 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

Reply With Quote
 
  #10 (permalink)
Market Wizard
virginia
 
Futures Experience: Intermediate
Platform: ninja
Favorite Futures: ES
 
cory's Avatar
 
Posts: 5,220 since Jun 2009
Thanks: 628 given, 6,318 received
Forum Reputation: Legendary


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:

Reply



futures io > > > > > stoploss to breakeven to trailing

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
StopLoss as fraction of ATR FArias NinjaTrader Programming 5 February 23rd, 2011 03:45 PM
Stops, trailing and breakeven stops jonc NinjaTrader 4 November 9th, 2010 01:06 AM
Help Coding Trailing stoploss in Strategy Darshiit NinjaTrader Programming 3 June 25th, 2010 10:45 AM
Runner Breakeven re entry emini_Holy_Grail Psychology and Money Management 6 May 1st, 2010 09:48 AM
BREAKEVEN + ONE TICK rajafx1 NinjaTrader Programming 1 November 8th, 2009 06:37 PM


All times are GMT -4. The time now is 05:24 AM.

Copyright © 2017 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
Page generated 2017-12-16 in 0.15 seconds with 20 queries on phoenix via your IP 54.160.245.121