Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Delta Bid/ask vol

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

    Delta Bid/ask vol

    Hi,

    I want to calculate the "net" volume of a bar by adding all the ticks that were on the ask minus all ticks on the bid. I think I did it ok just want someone to look at it and tell me if he sees something wrong...
    Here is the relevant methods, also attaching the zip.
    Thx.

    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]   if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Historical) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]   if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (CurrentBar < activeBar) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]   else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (CurrentBar != activeBar)[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]     {[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2]
    [SIZE=2][FONT=Courier New]         activeBar = CurrentBar;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]         netVol = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]     }[/FONT][/SIZE]
    [/SIZE][/FONT]}
     
    protected override void OnMarketData(MarketDataEventArgs e)
    { 
        double theAsk = 0, theBid = 0;
     
        if (e.MarketDataType != MarketDataType.Last)
        {
            return;
        }
     
        // Get the ask.
        if (e.MarketData.Ask != null) 
        {
            theAsk = e.MarketData.Ask.Price;
        }
     
        // get the bid.
        if (e.MarketData.Bid != null) 
        {
            theBid = e.MarketData.Bid.Price;
        }
     
        if(theBid <= 0 || theAsk <= 0) return;
     
        if (e.Price >= theAsk)
        {
            netVol += e.Volume; 
        }
        else if (e.Price <= theBid)
        {
            netVol -= e.Volume; 
        }
     
        Delta.Set(netVol);
    }
    Attached Files

    #2
    the code looks right but why not use GomCD which has this functionality and much more

    Comment


      #3
      GomCD is great, but I wanted something very simple, so I took Gom indicator and stripped it from all the stuff I don't need, that way I know and understand what is inside, feels more comfy for me...
      thx.

      Comment


        #4
        Me too, I use GomCD code for recording with the volume calculation style of jtRealStats =)

        (big thanks to authors of both of those indicators by the way, they are great examples of how to use OnMarketData effectively)

        Originally posted by yuvalw View Post
        GomCD is great, but I wanted something very simple, so I took Gom indicator and stripped it from all the stuff I don't need, that way I know and understand what is inside, feels more comfy for me...
        thx.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Johnny Santiago, 10-11-2019, 09:21 AM
        95 responses
        6,193 views
        0 likes
        Last Post xiinteractive  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        2 responses
        11 views
        0 likes
        Last Post xiinteractive  
        Started by Irukandji, Today, 09:34 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by RubenCazorla, Today, 09:07 AM
        1 response
        5 views
        0 likes
        Last Post RubenCazorla  
        Started by TraderBCL, Today, 04:38 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X