Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Top of Book (Level 1)

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

    Top of Book (Level 1)

    Hello,

    how can I graphically put the bid and ask of Top of Book (Level 1) on a chart?

    For these values (Bid and Ask) Depth of Market (Level 2) I used this script but it doesn't work with Top of Book (Level 1):

    protected override void OnMarketDepth(MarketDepthEventArgs e)
    {
    if (e.MarketDataType==MarketDataType.Ask)
    {​
    string priceask=string.Format("{0}",e.MarketDepth.Ask[0].Price.ToString("F"+decimali));
    DrawText("PriceAsk",true,priceask,-100,e.MarketDepth.Ask[0].Price,0,Color.IndianRed,textfont2,StringAlignment .Center,Color.Transparent,Color.Transparent,0);

    string volumeask=string.Format("{0}",e.MarketDepth.Ask[0].Volume);
    DrawText("VolumeAsk",true,volumeask,-100,e.MarketDepth.Ask[0].Price+2*TickSize,0,Color.IndianRed,textfont1,Stri ngAlignment.Center,Color.Transparent,Color.Transpa rent,0);​​​
    }
    }

    Thanks for your help

    #2
    Hello merzo,

    You can use OnMarketData to get the ask and bid or also the GetCurrentAsk and GetCurrentBid methods.





    Comment


      #3
      Hi Jesse, thank you for your reply.

      I modified the script like this: ​

      protected override void OnMarketData(MarketDataEventArgs e)
      {​
      string priceask=string.Format("{0}",GetCurrentAsk().ToStr ing("F"+decimali));
      DrawText("PriceAsk",true,priceask,-101,GetCurrentAsk(),0,Color.IndianRed,textfont2,St ringAlignment.Center,Color.Transparent,Color.Trans parent,0);
      string volumeask=string.Format("{0}",GetCurrentAskVolume( ));
      DrawText("VolumeAsk",true,volumeask,-101,GetCurrentAsk()+2*TickSize,0,Color.IndianRed,t extfont1,StringAlignment.Center,Color.Transparent, Color.Transparent,0);

      It works but the data on the chart updates with a delay, sometimes not at all.

      I then added the last price which works perfectly:​

      string ultimoprezzo=string.Format("{0}",e.Price.ToString( "F"+decimali)); //Mirus/Continuum
      DrawText("UltimoPrezzo",true,ultimoprezzo,-61,e.Price,0,Color.FromArgb(255,255,255,255),textf ont2,StringAlignment.Center,Color.Transparent,Colo r.Transparent,0);​​

      Did I perhaps forget something?

      Best

      Comment


        #4
        Hello merzo,

        If you are using OnMarketData you would not need to use GetCurrentAsk or GetCurrentBid, OnMarketData has the incoming market data events for ask last and bid.

        You also need to add conditions to filter the events, not all last ask and bid events happen at the same time. There is a sample of how to filter the events in the help guide. You would make 3 if conditions and then place your drawing statements within each if condition.

        Comment


          #5
          Thanks Jesse,

          I think I understood how to setting the IF rules
          For example:

          if (e.MarketDataType == MarketDataType.Last)
          INSTRUCTIONS;
          else if (e.MarketDataType == MarketDataType.Ask)
          INSTRUCTIONS;
          else if (e.MarketDataType == MarketDataType.Bid)
          INSTRUCTIONS;

          But it is not clear to me how to recall ASK and BID and the volumes of ASK and BID

          price is == e.Price
          volumes == e.Volume
          ask == ?
          bid == ?
          ask volume == ?
          bid volume == ?

          Thanks for your patience

          Best​​​

          Comment


            #6
            Hello merzo,

            Yes that is correct, I always suggest to use curly braces with if conditions, in what you provided last with how you are building the string that equals 2 lines so you need curly braces in that case.

            if (e.MarketDataType == MarketDataType.Last)
            {
            INSTRUCTIONS;
            }
            else if (e.MarketDataType == MarketDataType.Ask)
            {
            INSTRUCTIONS;
            }
            else if (e.MarketDataType == MarketDataType.Bid)
            {
            INSTRUCTIONS;
            }


            All of the events use the same variables, as mentioned they do not all happen at the same time. If a last event is observed e.Price and e.Volume are the values for that specific event. The same happens with the other event types. ​

            Comment


              #7
              Thanks Jesse.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Hwop38, 05-04-2026, 07:02 PM
              0 responses
              133 views
              0 likes
              Last Post Hwop38
              by Hwop38
               
              Started by CaptainJack, 04-24-2026, 11:07 PM
              0 responses
              290 views
              0 likes
              Last Post CaptainJack  
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              237 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by M4ndoo, 04-20-2026, 05:21 PM
              0 responses
              331 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by M4ndoo, 04-19-2026, 05:54 PM
              0 responses
              170 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Working...
              X