Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Custom indicator
Collapse
X
-
Hi U0000999, thanks for your question.
The general logic in OnBarUpdate would go something like this:
There are many different ways you can do this though. Take the SMA as a more complex example that sets up things that would be used on a regular basis like plots/inputs.Code:int period = 20; protected override void OnBarUpdate() { if(CurrentBars[0] < period) return; double sum = 0; for(int i = 0; i < period; i++) { sum += High[i] - Low[i] / 2; } Print(sum); }
Please let me know if I can assist any further.
-
Hi Chris,
Congrats to your post no. 3000 :-) .
I just added the average and some prints.
int period = 20;
protected override void OnBarUpdate()
{
if(CurrentBars[0] < period) return;
double sum = 0;
double average = 0;
for(int i = 0; i < period; i++)
{
sum += High[i] - Low[i] / 2;
average = sum / (i+1);
}
Print("Sum: " + sum.ToString("N2"));
Print ("Period: " + period.ToString());
Print("Average: " + average.ToString("N2"));
}
Thx.
NT-Roland
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
75 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
43 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|
||
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
167 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
101 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
165 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|

Comment