Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Indicator based on an earlier period, rather than current period.
Collapse
X
-
Hello jasonbradh,
Thank you for writing in.
I have created an example below that will plot the SMA of volume over the first 10 bars of a new session. It will continue to plot that last value until the next session occurs again.
Code:private int startBar = 0; private int endBar = 0; private double lastSMAValue = 0; protected override void OnBarUpdate() { // check if the current bar the indicator is evaluating over the first bar of a new session if (Bars.FirstBarOfSession) { // set startBar to CurrentBar and set endBar to CurrentBar + 9, which would be nine bars ahead // CurrentBar is the index of the bar the script is evaluating over startBar = CurrentBar; endBar = CurrentBar + 9; } // plot the volume SMA if CurrentBar is more than or equal to startBar and CurrentBar is less than or equal to endBar if (CurrentBar >= startBar && CurrentBar <= endBar) { Value.Set(SMA(Volume, 14)[0]); // set lastSMAValue to the current value of the volume SMA lastSMAValue = SMA(Volume, 14)[0]; } // if CurrentBar is more than endBar, this means the script is evaluating a bar outside of our range we have set // we'll set our plot to lastSMAValue while outside of this range if (CurrentBar > endBar) Value.Set(lastSMAValue); }
Leave a comment:
-
Indicator based on an earlier period, rather than current period.
I am trying to create an indicator that averages the volume of the first few bars of the day.
So even though it's 11 AM or 2PM, I want this indicator to still display what the SMA of volume was from the first 10 or so bars, using tick charting.
Can anyone help?
Thanks!Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
8 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
6 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Leave a comment: