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

OnMarketData - Price and Volume as a variable

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

    OnMarketData - Price and Volume as a variable

    Hi,

    I am experimenting with OnMarketData using the following code;

    Code:
    protected override void OnMarketData(MarketDataEventArgs e)
            {
    
                if (e.MarketDataType == MarketDataType.Ask) 
                    askPrice = e.Price;
                   [COLOR=Red][B] askVol = e.Volume;[/B][/COLOR]
    
                    else if (e.MarketDataType == MarketDataType.Bid)
                        bidPrice = e.Price;
    
    
                else if (e.MarketDataType == MarketDataType.Last)
                {
                    if (e.Price == askPrice)
                        Print("Last price traded at ask");
    
                    else if (e.Price == bidPrice)
                        Print("Last price traded at bid");
    
                    else
                    Print("Last price occurred at neither bid/ask");
                    }
            }
    I would like to ask what is the best way to get the e.Volume (in red) as well, which as is above does not compile? I have tried to use simply askVolume = e.Volume; and whilst this works if I change the above to this line of code I want to get this information and store it as a variable. What am I doing wrong here?

    suprsnipes

    #2
    Hello suprsnipes,
    Can you send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

    Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

    I look forward to assisting you further.

    *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      The code below is what I have working but I would like to get e.Volume in a variable in addition to the below and I would like to know how to go about it?

      Code:
      protected override void OnMarketData(MarketDataEventArgs e)
              {
      
                  if (e.MarketDataType == MarketDataType.Ask) 
                      askPrice = e.Price;
      
                      else if (e.MarketDataType == MarketDataType.Bid)
                          bidPrice = e.Price;
      
      
                  else if (e.MarketDataType == MarketDataType.Last)
                  {
                      if (e.Price == askPrice)
                          Print("Last price traded at ask");
      
                      else if (e.Price == bidPrice)
                          Print("Last price traded at bid");
      
                      else
                      Print("Last price occurred at neither bid/ask");
                      }
              }

      Comment


        #4
        Hello suprsnipes,
        From the given code, you have to use proper parenthesis in your if else statement.

        Also please make sure askVolume is a long and not an integer.
        Code:
        private long askVol = 0;
        
        protected override void OnMarketData(MarketDataEventArgs e)
                {
        
                    if (e.MarketDataType == MarketDataType.Ask) 
                  [B][COLOR="Blue"] {[/COLOR][/B]
                        askPrice = e.Price;
                        askVol = e.Volume;
                    [B][COLOR="blue"]}[/COLOR][/B]
                        else if (e.MarketDataType == MarketDataType.Bid)
                            bidPrice = e.Price;
        
        
                    else if (e.MarketDataType == MarketDataType.Last)
                    {
                        if (e.Price == askPrice)
                            Print("Last price traded at ask");
        
                        else if (e.Price == bidPrice)
                            Print("Last price traded at bid");
        
                        else
                        Print("Last price occurred at neither bid/ask");
                        }
                }
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thank you very much

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Gerik, Today, 09:40 AM
          2 responses
          7 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Started by RookieTrader, Today, 09:37 AM
          2 responses
          11 views
          0 likes
          Last Post RookieTrader  
          Started by alifarahani, Today, 09:40 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by KennyK, 05-29-2017, 02:02 AM
          3 responses
          1,285 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by AttiM, 02-14-2024, 05:20 PM
          11 responses
          186 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X