StopLoss as fraction of ATR - NinjaTrader Programming | futures io social day trading
futures io futures trading


StopLoss as fraction of ATR
Updated: Views / Replies:3,084 / 5
Created: by FArias Attachments:0

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
 
Thread Tools Search this Thread
 

StopLoss as fraction of ATR

  #1 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Futures
 
Posts: 6 since Feb 2011
Thanks: 22 given, 1 received

StopLoss as fraction of ATR

Hello all,

I am trying to program a simple stop loss and profit target based on a fraction of the ATR value at the bar where the trade was placed, but can not get it to work. Any help would be much welcome!!!

I am using calculatemode.price for the stops and using an if(BarsSinceEntry()==0) in order to set the value of my stops directly after the trade is placed. The code looks like this:

 
Code
if (Close[0] > SMA(periodoMA)[0])
            { EnterLong("Long");}
 
if(Position.MarketPosition==MarketPosition.Long)
 
   { if(BarsSinceEntry(0,"Long",0)==0)
{ SetStopLoss("Long", CalculationMode.Price, Position.AvgPrice-ATR(PeriodoATR)[0]*fractionstop);
SetProfitTarget("Long",CalculationMode.Price,Position.AvgPrice+ATR(PeriodoATR)[0]*fractiontarget);}
}
Any ideas on how this could be implemented?

Thanks in advance!

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Fiddler
Nashville, TN
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 542 received


You can do your "SetStopLoss" line without the Position check. You effectively are attaching the StopLoss to the Entry Order. However, if your entry is market, then you must figure the price from which you want to calculate your target before execution. Such as Close[0] or Close[0] + assumed slippage - StopLoss.

With a bit more trouble, you can use the following section:

protected override void OnOrderUpdate

And when the order is updated to "filled", only then send out the appropriate StopLoss after getting the confirmed execution price.

There is a section in the NT Help File that discusses this further so that you can make a practical implementation.

Reply With Quote
 
  #4 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Futures
 
Posts: 6 since Feb 2011
Thanks: 22 given, 1 received

Hello Luger,

Thanks for the info, I will read through OnOrderUpdate. However, I think I am already getting the correct entry price with Position.AvgPrice. I am substracting from that entry price the ATR. But the StopLoss is not executing.

I have seen on some examples that you have to reset the StopLoss / TargetProfit after you are flat??. I will give it a try.

Reply With Quote
 
  #5 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Futures
 
Posts: 6 since Feb 2011
Thanks: 22 given, 1 received

Got it!

I think I got it to work... but I do not know exactly why.

I added some code to set the stoploss and targetprofit to 1 and 10000 if the market position is flat. I could have used other values, I just wanted to make sure they would not be triggered by price action in the next bar(s).

Here is the code:

 
Code
 if (Close[0] > SMA(periodoMA)[0])
             {
                EnterLong("Entrada Largos");
             }
 
 
   if(Position.MarketPosition==MarketPosition.Flat)
  {
   SetStopLoss("Entrada Largos",CalculationMode.Price,1,false);
   SetProfitTarget("Entrada Largos",CalculationMode.Price,10000);
     }
 
   if(Position.MarketPosition==MarketPosition.Long)
    { 
   double Variable1 = Instrument.MasterInstrument.Round2TickSize(Position.AvgPrice-ATR(PeriodoATR)[0]*stopPerdidas);
   double Variable2 = Instrument.MasterInstrument.Round2TickSize(Position.AvgPrice+ATR(PeriodoATR)[0]*objBeneficio);
   SetStopLoss("Entrada Largos",CalculationMode.Price, Variable1,false);
   SetProfitTarget("Entrada Largos",CalculationMode.Price,Variable2));
}
What I do not understand has to do with the positioning of this new code. At first, I placed the reseting of the StopLoss and TargetProfit, that is, everything under if(...=MarketPosition.Flat), after the if(...MarketPosition.Long) code and it did not work. But placing it as it is now, it is working. Does anyone know why?

BTW, how can I use the C# code highlighting on my messages?

Reply With Quote
 
  #6 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,351 given, 83,221 received


FArias View Post
BTW, how can I use the C# code highlighting on my messages?

Instead of using CODE block use PHP block for syntax highlighting on posts on futures.io (formerly BMT). Sorry no time to answer the rest, but I'm sure someone will be nice enough to help you.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote

Reply



futures io > > > > > StopLoss as fraction of ATR

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 to breakeven to trailing stephenszpak NinjaTrader Programming 13 October 13th, 2014 04:30 PM
ADX and ATR indicator in panel 1 perryg NinjaTrader 29 May 22nd, 2014 07:17 AM
ATR Stop Trail need help pls Falco11 NinjaTrader Programming 6 January 20th, 2011 05:53 AM
Help Coding Trailing stoploss in Strategy Darshiit NinjaTrader Programming 3 June 25th, 2010 10:45 AM
ATR Bands with 3 modes cclsys The Elite Circle 11 December 29th, 2009 10:05 AM


All times are GMT -4. The time now is 01:08 PM.

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-13 in 0.10 seconds with 19 queries on phoenix via your IP 54.82.79.109