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 nightstalker, Today, 02:05 PM
        0 responses
        5 views
        0 likes
        Last Post nightstalker  
        Started by llanqui, Yesterday, 09:59 AM
        8 responses
        28 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by quicksandatl, Today, 01:39 PM
        1 response
        3 views
        0 likes
        Last Post quicksandatl  
        Started by md4866, 05-01-2024, 08:15 PM
        2 responses
        18 views
        0 likes
        Last Post md4866
        by md4866
         
        Started by samish18, Today, 12:20 PM
        0 responses
        7 views
        0 likes
        Last Post samish18  
        Working...
        X