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 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