NexusFi: Find Your Edge


Home Menu

 





can you help with code, would like to paint low volume bar black


Discussion in NinjaTrader

Updated
    1. trending_up 3,307 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 anniebee321 
london
 
Experience: Beginner
Platform: ninja
Trading: fgbl
Posts: 138 since Nov 2009
Thanks Given: 64
Thanks Received: 44

why is this not working??
would like to paint volume bar black if it is below a certain amount
protected override void Initialize()
{
Add(new Plot(new Pen(Color.Lime, 2), PlotStyle.Bar, "UpVolume"));
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Bar, "DownVolume"));
Add(new Plot(new Pen(Color.Black, 2), PlotStyle.Bar, "LowVol"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
DrawOnPricePanel = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Close[0] >= Open[0])
{
Values[0].Set(Volume[0]);
Values[1].Reset();

if (Volume[1]<x)
{ Values[2].Set(Volume[1]);
}
}
else
{
Values[1].Set(Volume[0]);
Values[0].Reset();
if (Volume[1]<x)
{ Values[2].Set(Volume[1]);

many thanks for your help/advise


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
$12M Ceasefire Contract Goes Disputed as Bandar Abbas St …
Prediction Markets & Event Contracts
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
April FOMC Minutes: Most Divided Fed Since 1992 -- Many …
Traders Hideout
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,117


Here are some changes that I suggest. Have not tested them. Also ou need to declare the Variable x via "double x = 0.0;" somewhere.

 
Code
 
protected override void Initialize()
{
Add(new Plot(new Pen(Color.Lime, 2), PlotStyle.Bar, "UpVolume"));
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Bar, "DownVolume"));
Add(new Plot(new Pen(Color.Black, 2), PlotStyle.Bar, "LowVol"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
Overlay = false;  // DrawOnPricePanel is needed for additional drawing features, you probably mean "Overlay = false;"
}
 
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Close[0] >= Open[0])
{
Values[0].Set(Volume[0]);
Values[1].Set(0.0);
} 
else // continue here for negative volume
{
Values[1].Set(Volume[0]);
Values[0].Set(0.0);
} 
// good idea to repaint the last bar after it became a low volume bar, but the first bar on the chart (index 0)does not have a last bar, so you may only start this with the second bar (index 1) -> CurrentBar > 0 is required
if (CurrentBar > 0 && Volume[1] < x)
{ 
Values[0].Set(1,0.0);
Values[1].Set(1,0.0);
Values[2].Set(1, Volume[1]); // you do not want to set the value for the current volume bar but for the prior bar
so you need to use the correct syntax Set( int barsAgo, double value)
}
Values[2].Set(0.0); // always, only affects the current incomplete bar
}
Further suggestions:

If you post code, you can use [Code] tags -> just highlight the code and select # on your task bar

The condition
 
Code
 
if (CurrentBar > 0 && Volume[1] < x)
will work but is annoying, because you have to change the value of x for every instrument. You could try
 
Code
 
if(CurrentBar > 10 && Volume[1] == MIN(Volume, 10)[1])
This would show the bar as a low volume bar, if it has the lowest volume of the last 20 bars - not including the current active bar, which is yet incomplete.


Reply With Quote
  #4 (permalink)
 anniebee321 
london
 
Experience: Beginner
Platform: ninja
Trading: fgbl
Posts: 138 since Nov 2009
Thanks Given: 64
Thanks Received: 44

thank you soooo much fat tails - i get the gist of yr code and will play around with it


Started this thread Reply With Quote
  #5 (permalink)
 anniebee321 
london
 
Experience: Beginner
Platform: ninja
Trading: fgbl
Posts: 138 since Nov 2009
Thanks Given: 64
Thanks Received: 44

yep, code is correct - just needed to declare variable as you said


Started this thread Reply With Quote




Last Updated on December 19, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts