Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy/Sell Volume

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Buy/Sell Volume

    I don't know exactly why but the sum of buy & sell volumes is never equal to the entire volume of a bar

    if someone knows what's going wrong with this code....


    #region Variables
    privateint activeBar = -1;
    private System.Collections.ArrayList alBuys = new System.Collections.ArrayList();
    private System.Collections.ArrayList alSells = new System.Collections.ArrayList();
    privatedouble lastPrice = 0.0;
    privateint buys = 0;
    privateint sells = 0;
    #endregion
    protectedoverridevoid Initialize()
    {
    Add(new Plot(new Pen(Color.Lime, 6), PlotStyle.Bar, "Buys"));
    Add(new Plot(new Pen(Color.Red, 6), PlotStyle.Bar, "Sells"));
    Add(new Line(Color.Gold, 0, "Zero Line"));

    CalculateOnBarClose = false;
    DisplayInDataBox = true;
    Overlay = false;
    PriceTypeSupported = false;
    PlotsConfigurable = true;
    }

    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar < activeBar)
    {
    Values[0].Set((double)alBuys[CurrentBar]);
    Values[1].Set(-(double)alSells[CurrentBar]);
    return;
    }
    elseif (CurrentBar != activeBar)
    {
    alBuys.Insert(Math.Max(activeBar, 0), Historical ? 0 : buys);
    alSells.Insert(Math.Max(activeBar, 0), Historical ? 0 : sells);
    buys = 0;
    sells = 0;
    activeBar = CurrentBar;
    }
    else
    {
    Values[0].Set(buys);
    Values[1].Set(-sells);
    }
    }

    protectedoverridevoid OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketDataType == MarketDataType.Last)
    {
    lastPrice = e.Price;

    // Buys : >= Ask
    if (lastPrice >= e.MarketData.Ask.Price)
    {buys += e.Volume;}
    // Sells : <= Bid
    elseif (lastPrice <= e.MarketData.Bid.Price)
    {sells += e.Volume;}
    }
    }
    }
    }
    Last edited by jerome; 12-29-2009, 08:26 AM.

    #2
    Jerome, when faced with a situation in which something is not working as you expect it to, it is best to start with a clean slate where everything works fine, then adding complexity (and functionality) one layer at a time.

    You can also use Print() statements to print out variable states, which helps verify how everything works.
    AustinNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    580 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    335 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    102 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X