NexusFi: Find Your Edge


Home Menu

 





Help on strategy stoploss


Discussion in NinjaTrader

Updated
    1. trending_up 5,283 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 1 attachments




 
Search this Thread

Help on strategy stoploss

  #1 (permalink)
 
mea109's Avatar
 mea109 
france
 
Experience: Beginner
Platform: nt
Posts: 201 since Oct 2009
Thanks Given: 1,776
Thanks Received: 56

Hello,

I've coded a few indicators but this is my first strategy. Please excuse me if my question feels basic.

What I'm trying to achieve ...in picture.



If I use on "Initialise" :
 
Code
private int stp=10;
SetStopLoss("Entry1", CalculationMode.Ticks, stp, true);
That is not what I want since the stop stance will be impacted by the entry slippage from the market order, which is precisely what I want to avoid ...

Then I've tried to use on "OnBarUpdate" :
 
Code
if(BarsSinceEntry("Entry1")==0) SetStopLoss("Entry1", CalculationMode.Price, Close[0]-stp*TickSize, true);
This takes the Close from the signal bar (bar 1) which is about the Open price from the entry bar (bar 2) ..but not quite on every single trade Worse than that, it creates a random behavior on my stops.

Could you please help me to simply code : set stoploss to real Open price from entry bar (without slippage impact from market entry order) - 10 ticks ??
That stoploss needs to be set once (just after entry) and should not be moved afterwards.

Thank you très beaucoup

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
41 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)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,335


set the stoploss the same time you enter the market...forget the if(BarsSinceEntry...

 
Code
EnterLong("Entry1");
SetStopLoss("Entry1", CalculationMode.Price, Close[0]-stp*TickSize, true);
That should do the trick...

Reply With Quote
Thanked by:
  #4 (permalink)
 
mea109's Avatar
 mea109 
france
 
Experience: Beginner
Platform: nt
Posts: 201 since Oct 2009
Thanks Given: 1,776
Thanks Received: 56

Thanks MWinfrey

If I write this it takes into account the Close from the signal bar but not the Open from the entry bar (the next bar) which is what I want to achieve.

My goal is to set the stop from the Open of the entry bar because often in a 2 bar sequence Open[0] and Close[1] are not properly equal on minutes charts. Can it be done ? Thanks again

Started this thread Reply With Quote
  #5 (permalink)
 
mea109's Avatar
 mea109 
france
 
Experience: Beginner
Platform: nt
Posts: 201 since Oct 2009
Thanks Given: 1,776
Thanks Received: 56

Maybe I'm forced to set it to the Close of the signal bar beecause that's the best I can do ...and move it to the Open of the entry bar the bar after ?

I'm interested to make it work in a live situation. I don't care about running it as a backtest (I have a panel indicator planned for live backtest tracking).

Started this thread Reply With Quote
  #6 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,335


mea109 View Post
Thanks MWinfrey

If I write this it takes into account the Close from the signal bar but not the Open from the entry bar (the next bar) which is what I want to achieve.

My goal is to set the stop from the Open of the entry bar because often in a 2 bar sequence Open[0] and Close[1] are not properly equal on minutes charts. Can it be done ? Thanks again

Try this...haven't tested but it should work. The problem is when using COBC = true which is the default, all code is executed at the open of the next bar. However, as you know the entry price is the open of the next bar but the stoploss is the close of the signal bar. So, what you can do to overcome this is to set the stop at the same time as you enter the market and then reset it at the close of the next bar. The only problem that I can think of is if the first bar is long enough to hit your stop before you can reset the stop. Maybe others have a better idea than this. Again, I haven't tested this but believe it will work.

put this in your variable declarations area.
 
Code
private int longentrybar = 0;
put this in OnBarUpdate...also notice the parentheses I placed around (stp*TickSize). I notice you have the simulated parameter set to true. Be sure you know what that means before using it.
 
Code
if <long entry rules are met>
{
   EnterLong("Entry1");
   SetStopLoss("Entry1", CalculationMode.Price, Close[0]-(stp*TickSize), true);
   longentrybar = CurrentBar;
}

if (CurrentBar - longentrybar == 1)
   SetStopLoss("Entry1", CalculationMode.Price, Open[0]-(stp*TickSize), true);
You can also look at the BarsSinceEntry() method instead of using the CurrentBar - longentrybar calculation...

Reply With Quote
Thanked by:
  #7 (permalink)
 
mea109's Avatar
 mea109 
france
 
Experience: Beginner
Platform: nt
Posts: 201 since Oct 2009
Thanks Given: 1,776
Thanks Received: 56

Your code works as described! I believe it's the closest one can accomplish although it is in fact a handicap to keep the risk of the stoploss unproperly set on the signal bar while waiting for the next one. At the same time, I tried to play with COBC=False with no more success.

I used BarsSinceEntry since I manage too many separate orders that I can declare variables for. I build my position from multiple fractions of futures contracts via CFDs so I use a loop condition in OnBarUpdate instead.

I did read about the simulated parameter but it seems like I did not understand it right. Thanks for having put my attention on it ! That's part of education

Started this thread Reply With Quote
Thanked by:




Last Updated on May 2, 2012


© 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