protected override void Initialize()
{
//SPY is Primary series 0
Add("DIA", PeriodType.Minute, 5); //series 1 primary for DIA
Add(PeriodType.Minute, 1); //series 2 secondary for SPY
Add("DIA", PeriodType.Minute, 1); //series 3 secondary for DIA
}
protected override void OnBarUpdate()
{
if ((BarsInProgress == 2) && //sma cross conditions here//)
{
EnterLong(200, "SPY");
}
if ((BarsInProgress == 3) && //sma cross conditions here//)
{
EnterLong(200, "DIA");
}
if ((BarsInProgress == 0) && (Position.MarketPosition == MarketPosition.Flat))
{
SetStopLoss("SPY", CalculationMode.Percent, stoppercent, true);
}
if ((BarsInProgress == 1) && (Position.MarketPosition == MarketPosition.Flat))
{
SetStopLoss("DIA", CalculationMode.Percent, stoppercent, true);
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
2 instruments in one script
Collapse
X
-
2 instruments in one script
This is for backtesting purposes. I made an attempt at having 2 instruments in one script below but when I compare it to running a single script against the same 2 instruments seperately I get different net profit results. I tried using "else if" as well. Is there anything else I'm doing incorrectly or is it not even possible to do what I'm attempting here?
Code:Tags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
62 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
33 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
44 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
58 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
47 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment