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

Did the last price trade on bid/ask?

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

    Did the last price trade on bid/ask?

    Hello,

    Is it possible to print if the last price traded was on bid/ask (including the volume)?


    the following script is missing if the last price was on bid/ask
    if (e.MarketDataType == MarketDataType.Last)
    Print("Last = " + e.Price + " " + e.Volume);

    ---
    note: I do not want the bid and ask prices, i want print out if the last traded price was at the bid or ask

    thanks for your help in advance!

    #2
    Hello Dawdler,

    Thank you for your note.

    Yes, however, you will need to get the Ask and Bid prices, store them in a variable and then compare that to the last price.
    Code:
    if(e.MarketDataType == MarketDataType.Bid)
    bidPrice = e.Price;
    bidVolume = e.Volume;
    
    if(e.MarketDataType == MarketDataType.Last)
    {
        if(e.Price == bidPrice)
          Print("Last price was at the bid. Volume: " + bidVolume);
    }
    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal, thank you for your answer but nothing prints at this point: {Print("Last price was at the bid. Volume: " + bidVolume);}

      what am i doing wrong? fyi my programming skills are basic

      thanks

      protected override void OnMarketData(MarketDataEventArgs e)
      {

      if (e.MarketDataType == MarketDataType.Bid)
      {
      bidPrice = e.Price;
      bidVolume = e.Volume;


      if (e.MarketDataType == MarketDataType.Last)
      {
      if(e.Price == bidPrice)
      {Print("Last price was at the bid. Volume: " + bidVolume);}
      }
      }


      }

      Comment


        #4
        Also I think my question was misunderstood, sorry but...

        I want the print out of the "trade volume @ bid" not the bid quotes

        Comment


          #5
          Dawdler,

          This is because you have the Last price check nested inside the Bid price check.
          Try this -
          Code:
          protected override void OnMarketData(MarketDataEventArgs e)
          {
          
               if (e.MarketDataType == MarketDataType.Bid)
               {
                   bidPrice = e.Price;
                   bidVolume = e.Volume;
               }
          
               if (e.MarketDataType == MarketDataType.Last) 
               {
                  if(e.Price == bidPrice)
                   {Print("Last price was at the bid. Volume: " + bidVolume);}
               }
          }
          The bidVolume is what's being printed out
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            thanks a lot Cal!

            Comment


              #7
              Cal,


              Is there a way to only print the volume of the last transaction?

              Comment


                #8
                Hello mattage86,

                Thank you for your post.

                dawdler's original post shows how to pull the last price traded and it's volume.
                if (e.MarketDataType == MarketDataType.Last)
                Print("Last = " + e.Price + " " + e.Volume);
                Please let me know if you have any questions.

                Comment


                  #9
                  Great. Thanks for the clarification!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by DJ888, 04-16-2024, 06:09 PM
                  4 responses
                  11 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by terofs, Today, 04:18 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post terofs
                  by terofs
                   
                  Started by nandhumca, Today, 03:41 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post nandhumca  
                  Started by The_Sec, Today, 03:37 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post The_Sec
                  by The_Sec
                   
                  Started by GwFutures1988, Today, 02:48 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X