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
No announcement yet.
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=isfirst
-
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.
Comment
-
All historical bars are fine. All new bars aren't being calculated properly. All new bars are all the bars since I applied the indicator.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.
Comment
-
In my last image I am not surrounding my code with "first tick of bar condition", all of the codes run on each tick and the color aren't the same as historical bars.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.
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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
624 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
359 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
562 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
567 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment