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 charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
52 views
0 likes
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
142 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
160 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
96 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
276 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|

Comment