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 zstheorist, Today, 07:52 PM
        0 responses
        5 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        150 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post tkaboris  
        Working...
        X