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

Time&Sales last trade

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

    Time&Sales last trade

    Hello!
    Want to write some script which will use T&S data.
    Which command I need to use if I want to know:
    - the size (volume) of last trade
    - was last trade on ask or on bid price
    - time of last trade

    Thanks!

    #2
    Hello YevhenShynkarenko,


    You could use MarketDataEventArgs to access those values.


    Here is the MarketDataEventArgs Help Guide to assist you further.



    Here is an example that prints the Last, Ask and Bid prices to the output window. The times and the volume for each are printed as well.


    Code:
    protected override void OnBarUpdate()    [COLOR=#000000][FONT=Tahoma][LEFT]              {}[LEFT][/LEFT][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT]             [/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT]protected override void OnMarketData(MarketDataEventArgs e)[/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT]             {
         if (e.MarketDataType == MarketDataType.Last)          
              Print("Last = " + e.Price + " " + e.Time + " " + e.Volume);
         else if (e.MarketDataType == MarketDataType.Ask)
             Print("Ask = " + e.Price  + e.Time + " " + e.Price + " " + e.Volume);
        else if (e.MarketDataType == MarketDataType.Bid)
             Print("Bid = "  + e.Price + " " + e.Time + " " + e.Volume);
                   }
    [/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [/LEFT][/FONT][/COLOR]
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ShawnB View Post
      Hello YevhenShynkarenko,


      You could use MarketDataEventArgs to access those values.


      Here is the MarketDataEventArgs Help Guide to assist you further.



      Here is an example that prints the Last, Ask and Bid prices to the output window. The times and the volume for each are printed as well.


      Code:
      protected override void OnBarUpdate()    [COLOR=#000000][FONT=Tahoma][LEFT]              {}[LEFT][/LEFT][LEFT][/LEFT]
      [COLOR=#000000][FONT=Tahoma][LEFT]             [/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
      [COLOR=#000000][FONT=Tahoma][LEFT]protected override void OnMarketData(MarketDataEventArgs e)[/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
      [COLOR=#000000][FONT=Tahoma][LEFT]             {
           if (e.MarketDataType == MarketDataType.Last)          
                Print("Last = " + e.Price + " " + e.Time + " " + e.Volume);
           else if (e.MarketDataType == MarketDataType.Ask)
               Print("Ask = " + e.Price  + e.Time + " " + e.Price + " " + e.Volume);
          else if (e.MarketDataType == MarketDataType.Bid)
               Print("Bid = "  + e.Price + " " + e.Time + " " + e.Volume);
                     }
      [/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
      [/LEFT][/FONT][/COLOR]
      Thanks for reply!
      And is MarketDataType.Bid is the last trade on bid price? Or it will show how many orders are standing on current bid price?
      Thanks!

      Comment


        #4
        Hello YevhenShynkarenko,


        Yes, MarketDataType.Bid will represent the current bid price. Using e.Volume will return the volume of the current bid price.


        I have included the sample Level II Data Book indicator to assist you further.
        Indicator Creating your own Level II data book - NinjaTrader Support Forum
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ShawnB View Post
          Hello YevhenShynkarenko,


          Yes, MarketDataType.Bid will represent the current bid price. Using e.Volume will return the volume of the current bid price.


          I have included the sample Level II Data Book indicator to assist you further.
          Indicator Creating your own Level II data book - NinjaTrader Support Forum
          Okay. But how can I wrote to Output was the Last trade on Bid or on Ask? Can I do it? Thanks!
          Want to create something like Time & Sales but in Output Window.
          For example if last trade was on Bid size i want to see that last trade was at Time X and with Volume Y.

          Comment


            #6
            Hello YevhenShynkarenko,

            Please use MarketDataEventArgs to access those values.
            Here is the MarketDataEventArgs Help Guide to assist you further.



            I have included the sample Level II Data Book indicator to assist you further.
            Indicator Creating your own Level II data book - NinjaTrader Support Forum


            Here is an example that prints the Last, Ask and Bid prices to the output window. The times and the volume for each are printed as well.


            Code:
            [LEFT][FONT=Consolas][SIZE=1][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Consolas][SIZE=1][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Consolas][SIZE=1][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Consolas][SIZE=1]OnBarUpdate()    [/SIZE][/FONT]
            [FONT=Consolas][SIZE=1]              {}[/SIZE][/FONT]
            [FONT=Consolas][SIZE=1]             [/SIZE][/FONT]
            protected override void OnMarketData(MarketDataEventArgs e)
                         {
                 if (e.MarketDataType == MarketDataType.Last)          
                      Print("Last = " + e.Price + " " + [FONT=Consolas]e.Time[/FONT] + " " + e.Volume);
                 else if (e.MarketDataType == MarketDataType.Ask)
                     Print("Ask = " + e.Price  + [FONT=Consolas]e.Time[/FONT] + " " + e.Price + " " + e.Volume);
                else if (e.MarketDataType == MarketDataType.Bid)
                     Print("Bid = "  + e.Price + " " + [FONT=Consolas]e.Time[/FONT] + " " + e.Volume);
                           }
            [/LEFT]
            Shawn B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,611 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            22 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X