double spread = 0;
double topClose = 0;
double secondClose = 0;
protected override void OnBarUpdate(){
if (BarsInProgress == 0) topClose = Close[0];
if (BarsInProgress == 1) secondClose = Close[0];
spread = topClose - secondClose;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Multiple symbol synchronicity
Collapse
X
-
Multiple symbol synchronicity
Is it correct that it's possible to trade several symbols on one chart, with the BarsInProgess field indicating which of the charts is being referenced in the OnBarUpdate() method? i.e.the OHLC all apply to the chart which is active (as defined by BarsInProgress), so that if I want to keep track of the spread between the close of the top chart and the close of the second chart the following might work:
Code:Last edited by kaydgee; 08-31-2012, 08:15 AM.Tags: None
-
Hello kaydgee,
The current code you are using wont work as either topClose or secondClose will be 0 (zero) at any point of time.
You can follow any of the below steps to calculate the spread.
Using BarsInProgress
Not using BarsInProgressCode:double spread = 0; if (BarsInProgress == 0) spread = Close[0] - Closes[1][0]; else if (BarsInProgress == 1) spread = Closes[0][0] - Close[0];
Code:double spread = Closes[0][0] - Closes[1][0];
JoydeepNinjaTrader Customer Service
-
Hello kaydgee,
Yes, it would work, but I would still make a check that both the fields have non-zero values.
Please let me know if I can assist you any further.Code:double spread = 0; double topClose = 0; double secondClose = 0; protected override void OnBarUpdate(){ { if (BarsInProgress == 0) topClose = Close[0]; if (BarsInProgress == 1) secondClose = Close[0]; if (topClose == 0 || secondClose == 0) return; // we do not have enough information to calculate the spread spread = topClose - secondClose; }JoydeepNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
646 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
367 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment