protected override void Initialize()
{
CalculateOnBarClose = true;
Add("SPY",PeriodType.Minute,5);
}
protected override void OnBarUpdate()
{
if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired){return;}
else
{
if(BarsInProgress==0)
{
if(((ToTime(Time[0])>= 100000) && (ToTime(Time[0])<= 140000)) &&
(Closes[1][0]>Closes[1][Bars.BarsSinceSession-1])) //is market up?
{
if((Close[0]>EMA(50)[0])&&
(Close[0]>EMA(10)[0])&&
(Open[0]<EMA(50)[0])&&
((High[0]-Close[0])/(High[0]-Low[0])<=.25)&&
(CountIf(delegate{return High[1]<=EMA(20)[1];},30)>=28)&&
(CountIf(delegate{return EMA(20)[0]<EMA(50)[0];},30)==30)&&
(Volume[0]>=SMA(Volume,15)[2]*4))
{
EnterLong(0,100,"Signal");
}
}
if(Position.MarketPosition==MarketPosition.Long)
{
if(Close[0]<EMA(20)[0])
ExitLong(0,100,"Exit","Signal");
}
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Multi- instument strategy giving results I'm not expecting
Collapse
X
-
Multi- instument strategy giving results I'm not expecting
Hi... I thought I had the basics down of multi-instrument strategies but apparently not. The strategy below is returning trades that have no similarities to the conditions coded. For example, entries at 9:35am and 4:00pm (I have coded only between 10-2), no moving average conditions present as specified, etc. Any ideas?
Code:Tags: None
-
Where are you testing this? Market Replay? Strategy Analyzer? Sim? Live?
What is the time frame of the main series?
The code looks right glancing at it, but your setup might be incorrect.
Originally posted by CSharpTrader View PostHi... I thought I had the basics down of multi-instrument strategies but apparently not. The strategy below is returning trades that have no similarities to the conditions coded. For example, entries at 9:35am and 4:00pm (I have coded only between 10-2), no moving average conditions present as specified, etc. Any ideas?
Code:protected override void Initialize() { CalculateOnBarClose = true; Add("SPY",PeriodType.Minute,5); } protected override void OnBarUpdate() { if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired){return;} else { if(BarsInProgress==0) { if(((ToTime(Time[0])>= 100000) && (ToTime(Time[0])<= 140000)) && (Closes[1][0]>Closes[1][Bars.BarsSinceSession-1])) //is market up? { if((Close[0]>EMA(50)[0])&& (Close[0]>EMA(10)[0])&& (Open[0]<EMA(50)[0])&& ((High[0]-Close[0])/(High[0]-Low[0])<=.25)&& (CountIf(delegate{return High[1]<=EMA(20)[1];},30)>=28)&& (CountIf(delegate{return EMA(20)[0]<EMA(50)[0];},30)==30)&& (Volume[0]>=SMA(Volume,15)[2]*4)) { EnterLong(0,100,"Signal"); } } if(Position.MarketPosition==MarketPosition.Long) { if(Close[0]<EMA(20)[0]) ExitLong(0,100,"Exit","Signal"); } } } }
-
Thank you sledge. I was running it on 5 min bars in strategy analyzer. I had been backtesting a different strategy from the same analyzer before, and, going out on a limb here, I wonder if this had something to do with it. I say this since after restarting NT and rerunning the strategy (and removing the other instrument) it performed as expected..
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
67 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
36 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
60 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
62 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment