protected override void OnBarUpdate() { pvsra_volume = Volume[0]; pvsra_high = High[0]; pvsra_low = Low[0]; pvsra_close = Close[0]; pvsra_open = Open[0]; //label.new(overridesym ? 0 : na, low, text = "PVSRA Override: " + pvsra_sym, xloc = xloc.bar_index, yloc=yloc.belowbar,style=label.style_label_down, size=size.huge) // The below math matches MT4 PVSRA indicator source // average volume from last 10 candles //if (CurrentBars[0] == 0) return; sumVolume = SUM(Volume, 10)[0]; av = sumVolume / 10; //climax volume on the previous candle value2 = Volume[0]*(High[0]-Low[0]); // highest climax volume of the last 10 candles // Add the current value to the list value2List.Add(value2); // Remove the oldest value if there are more than 10 if (value2List.Count > 10) { value2List.RemoveAt(0); } // Compute the maximum value over the last 10 (or fewer) bars if (value2List.Count >= 10) { hivalue2 = value2List.Max(); } // VA value determines the bar color. va = 0: normal. va = 1: climax. va = 2: rising va = (Volume[0] >= (av * 2) || value2 >= hivalue2) ? 1 : Volume[0] >= av * 1.5 ? 2 : 0; // Bullish or bearish coloring isBull = Close[0] > Open[0]; // candleColor = iff(climax,iff(isBull,CUColor,CDColor),iff(aboveA, iff(isBull,AUColor,ADColor),iff(isBull,NUColor,NDC olor))) CUColor = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0)); CDColor = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)); AUColor = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)); ADColor = new SolidColorBrush(Color.FromArgb(255, 255, 0, 255)); NUColor = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153)); NDColor = new SolidColorBrush(Color.FromArgb(255, 77, 77, 77)); candleColor = isBull ? NUColor : NDColor; if (va == 1) { candleColor = isBull ? CUColor : CDColor; } else if (va == 2) { candleColor = isBull ? AUColor : ADColor; } BarBrushes[0] = candleColor; CandleOutlineBrushes[0] = candleColor; }
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
PVSRA candles, last candle doesn't get correct color.
Collapse
X
-
PVSRA candles, last candle doesn't get correct color.
I am trying to code PVSRA candles. It work well for all past candles but not for the last current candle. The last candle is always red or green. I need help.
Code:Tags: None
- Likes 1
-
Hello supremeMarshall,
Are you running the script OnBarClose? If so the last bar is not included in OnBarUpdate calls.
If that is the situation you can use OnPriceChange or OnEachTick instead which includes the building bar. If you need your logic to run OnBarClose still you can surround that logic with a condition checking for the first tick of the bar. https://ninjatrader.com/support/help...ghtsub=isfirstJesseNinjaTrader Customer Service
-
I have tried using on each tick and all calculations aren't working correctly. I tried with `if (IsFirstTickOfBar)` and still doesn't work. All candles are gray for a couple of times and then all candles are always red or green. All past candles does have the correct color but not on every bar created.Last edited by supremeMarshall; 10-03-2023, 11:21 AM.
Comment
-
Hello supremeMarshall,
To clarify you see that when the script is applied all the historical bars up to the current bar are correct and then in Realtime the building bar is being colored sometimes and other times not?
I am not sure based on the description what the problem is, you mentioned that all bars are gray sometimes and then other times they are red or green, did you mean the right most building bar? The next statement leads me to believe there is not a problem with historical because you mentioned all past candles have correct color.
JesseNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jesse View PostHello supremeMarshall,
To clarify you see that when the script is applied all the historical bars up to the current bar are correct and then in Realtime the building bar is being colored sometimes and other times not?
I am not sure based on the description what the problem is, you mentioned that all bars are gray sometimes and then other times they are red or green, did you mean the right most building bar? The next statement leads me to believe there is not a problem with historical because you mentioned all past candles have correct color.
Comment
-
-
Hello supremeMarshall,
You may want to try the logic without surrounding it with a first tick of bar condition, the condition in realtime is going to be executed for the first tick of the bar so only the opening values of the bar would be known. You would have to update the bar for each tick if you wanted to color the building bar continuously until it closes.JesseNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jesse View PostHello supremeMarshall,
You may want to try the logic without surrounding it with a first tick of bar condition, the condition in realtime is going to be executed for the first tick of the bar so only the opening values of the bar would be known. You would have to update the bar for each tick if you wanted to color the building bar continuously until it closes.
Comment
-
-
Hello supremeMarshall,
That means the logic is working differently in those two use cases. To test what is different you would need to add prints into your logic to check that it is working identically in both use cases while using OnBarClose calculation mode. Historical processing always uses OnBarClose so if you use that in realtime the general expectation is that your logic is going to be executed in the same way.
JesseNinjaTrader Customer Service
Comment
-
supremeMarshall that's looks very promising!
Could you fix the problem with last bar finally?
I was trying to find vector candles or PVSRA indicators for NT. Are you planning to share the indicator with the community? That would be awesome!
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
14 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
||
Started by strategist007, Yesterday, 07:51 PM
|
0 responses
13 views
0 likes
|
Last Post Yesterday, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,982 views
3 likes
|
Last Post
by jhudas88
Yesterday, 06:59 PM
|
Comment