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 carnitron, Today, 08:42 PM
        0 responses
        5 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Today, 07:51 PM
        0 responses
        6 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,974 views
        3 likes
        Last Post jhudas88  
        Started by rbeckmann05, Today, 06:48 PM
        0 responses
        8 views
        0 likes
        Last Post rbeckmann05  
        Started by rhyminkevin, Today, 04:58 PM
        4 responses
        58 views
        0 likes
        Last Post dp8282
        by dp8282
         
        Working...
        X