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 2,731 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

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

  #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?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
 
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103


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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts