View Full Version : Stopping Trending strategy on chop days
DinoSchu
01-26-2010, 02:54 PM
I was looking at reference samples for stopping astretegy on chop days . I want to be able to shut down system after 2 or 3 losers in a row. There was a post in the ref samples that stated just that , I couldnt gather how to impliment it into my strategy can you explain further?
NinjaTrader_Austin
01-26-2010, 03:15 PM
DinoSchu, we can't program strategies for customers, but we can help you get started. This code snippet identifies when the last three trades have all been losers:
if (Performance.RealtimeTrades.Count >= 3)
{
if (Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1].ProfitPoints < 0 &&
Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 2].ProfitPoints < 0 &&
Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 3].ProfitPoints < 0)
{
// the last three realtime trades have all been losers. do something, like halt the strategy.
}
}
There are quite a few helpful samples (complete with code) here (http://www.ninjatrader-support2.com/vb/showthread.php?t=3220).
DinoSchu
02-05-2010, 11:38 AM
Thank you . COuld you show a full page so I can see where to input this .
NinjaTrader_Bertrand
02-05-2010, 12:54 PM
You could for example check into this specific sample here Dino working with the Performance class - http://www.ninjatrader-support2.com/vb/showthread.php?t=4084
DinoSchu
02-08-2010, 07:22 AM
This is what I I put in to the onbar update section .
// After two straight losers stop strategy
if (Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1].ProfitPoints < 0 &&
Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 2].ProfitPoints < 0)
{
/* A custom method designed to close all open positions and cancel all working orders will be called.
This will ensure we do not have an unmanaged position left after we halt our strategy. */
StopStrategy();
// Halt further processing of our strategy
return;
To halt strategy after two straight losers.. The sample you gave me was the halt basic strategy and when I compile my strategy or tghe sample strategy I get the same error message. StopStrategy does not exist in the current context CS0103 . I get it for both mien and sample . is there something I am missing?
NinjaTrader_Bertrand
02-08-2010, 07:30 AM
Dino, unfortunately wouldn't know how your custom method is programmed and what issues it may cause - lets try to simplify - did you test the SamplePnl strategy and does it work as you would expect, i.e. stopping trading for the day if either one of the following are happening -
profit exceeds 1000
losses exceed 400
more than 10 trades done
DinoSchu
02-08-2010, 08:27 AM
You are correct when running I believe the sample sorked fine. Instead of having dollar amounts as the trugger to turn stategy off . I am looking for consecutive losers . I put in the code below .
http://www.ninjatrader-support2.com/vb/showthread.php?t=25129 and made my adjustments to fit my stategy . the codign to actually turn the system off I cant figure out.
when the last two trades are losers do something like halt trading.
That part i can't seem to write corretly in the system. I know you cant write anything for me . I just want to be able to turn my system off after 2 traight losers no matter what my conditions on the strategy are . If you need more infromation from me just tell my what to copy and paste
NinjaTrader_Bertrand
02-08-2010, 08:39 AM
Dino, here's a sample also working with the Performance class not entering new trades after 3 consecutive loosers...you just need to weave this into your trade entry conditions (so they don't trigger anymore) and reset the count each day / session.
http://www.ninjatrader-support2.com/vb/showthread.php?t=19289
DinoSchu
02-08-2010, 09:01 AM
I copied the sampl portion and pasted directly into my strategy . Wiht the 1000 and 400 dollar limits and it still wont compile . It does on the sample but not On mine . same error StopStrategy(); ... does not exist in its currecnt context . CS0103 error . just can t figure our what i am missing
DinoSchu
02-08-2010, 09:02 AM
Thank you I will try that
NinjaTrader_Bertrand
02-08-2010, 09:08 AM
Ok, please let me know if you can get it going, or otherwise I'll need the script including the StopStrategy() to check into, if you don't want to post it just send via email to support at ninjatrader dot com Attn Bertrand
DinoSchu
02-08-2010, 10:00 AM
it seems to me its something simple . I sent you the strategy attn to you . le me know
NinjaTrader_Bertrand
02-08-2010, 10:07 AM
Got it, will check into shortly.