Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.





    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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. ​
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,404 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              95 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              7 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              159 views
              0 likes
              Last Post loganjarosz123  
              Started by Belfortbucks, Yesterday, 09:29 PM
              0 responses
              8 views
              0 likes
              Last Post Belfortbucks  
              Working...
              X