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

OnBarUpdate & OnMarketDepth

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

    OnBarUpdate & OnMarketDepth

    My code has OnBarUpdate followed by OnMarketDepth. I print from OnBarUpdate. Is there a way to grab a parameter from OnMarketDepth, like e.Price, and print from OnBarUpdate?

    Thanks.

    #2
    Originally posted by dsraider View Post
    My code has OnBarUpdate followed by OnMarketDepth. I print from OnBarUpdate. Is there a way to grab a parameter from OnMarketDepth, like e.Price, and print from OnBarUpdate?

    Thanks.
    dsraider,

    You can Print from OnMarketDepth.

    RJay
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      rt6176,

      Thanks but my If ---> Print statement is in OnBarUpdate. I have no problem moving Print down to Depth but I'm not sure if that's possible, as I don't know how to make one communicate with the other. Maybe a bool in OnBar following by an If (bool = true) Print in Depth?

      Comment


        #4
        Originally posted by dsraider View Post
        rt6176,

        Thanks but my If ---> Print statement is in OnBarUpdate. I have no problem moving Print down to Depth but I'm not sure if that's possible, as I don't know how to make one communicate with the other. Maybe a bool in OnBar following by an If (bool = true) Print in Depth?
        Hi dsraider,

        If you define the variable you want to print in the Initialize area, you can call it from any method.

        You can assign a value to the variable in OnMarketDepth and you can print it from OnBarUpdate.

        RJay
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment


          #5
          Hey RJay,

          That sounds perfect but I can't seem to compile:

          PHP Code:
          protected override void Initialize()
          {
               
          double lastPrice 0;
          }

          protected 
          override void OnBarUpdate()
          {
               Print(
          lastPrice);
          }

          protected 
          override void OnMarketDepth(MarketDepthEventArgs e)
          {
               
          double lastPrice e.Price;

          I'm sure I did something stupid. Do you see it?

          Comment


            #6
            Originally posted by dsraider View Post
            Hey RJay,

            That sounds perfect but I can't seem to compile:

            PHP Code:
            protected override void Initialize()
            {
                 
            double lastPrice 0;
            }

            protected 
            override void OnBarUpdate()
            {
                 Print(
            lastPrice);
            }

            protected 
            override void OnMarketDepth(MarketDepthEventArgs e)
            {
                 
            double lastPrice e.Price;

            I'm sure I did something stupid. Do you see it?
            Your lastPrice variables are completely different and independent variables because of the way that you have defined them. They are each local to the scope where they are defined and so totally unrelated, despite the identity of name.

            Instead define the lastPrice in the "Variables" section, so that it is a class variable. Then access the variable from any event, by direct query.

            Comment


              #7
              Hey koganam,

              I hear you loud and clear and that is what I normally do. The problem here, though, is that I'm trying to print OnMarketDepth data from OnBarUpdate because I need the OnBarUpdate logic to decide whether or not to print.

              Defining lastPrice in Variables and then printing in OnBarUpdate just throws me a "0."

              Maybe there's another way to print MarketDepth data from OnBar?

              Comment


                #8
                Originally posted by dsraider View Post
                Hey koganam,

                I hear you loud and clear and that is what I normally do. The problem here, though, is that I'm trying to print OnMarketDepth data from OnBarUpdate because I need the OnBarUpdate logic to decide whether or not to print.

                Defining lastPrice in Variables and then printing in OnBarUpdate just throws me a "0."

                Maybe there's another way to print MarketDepth data from OnBar?
                1. You declare/define lastPrice as a class variable.
                2. You assign lastPrice in OnMarketDepth().
                3. You print/output lastPrice in OnBarUpdate().

                You must assign a variable a value before you can see what value you assigned it.

                Comment


                  #9
                  I believe I understand you correctly but I'm still getting 0s with this:

                  PHP Code:
                  #region Variables
                  double lastPrice 0;
                  #endregion

                  protected override void OnBarUpdate()
                  {
                       Print(
                  lastPrice);
                  }

                  protected 
                  override void OnMarketData(MarketDepthEventArgs e)
                  {
                       
                  double lastPrice e.Price;

                  Comment


                    #10
                    Originally posted by dsraider View Post
                    I believe I understand you correctly but I'm still getting 0s with this:

                    PHP Code:
                    #region Variables
                    double lastPrice 0;
                    #endregion

                    protected override void OnBarUpdate()
                    {
                         Print(
                    lastPrice);
                    }

                    protected 
                    override void OnMarketData(MarketDepthEventArgs e)
                    {
                         
                    double lastPrice e.Price;


                    You need live market data or replay data running for this to work.
                    Last edited by RJay; 01-29-2012, 03:38 PM.
                    RJay
                    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                    Comment


                      #11
                      I've been trying this on reply all day and have very little hair left on my head

                      Comment


                        #12
                        Originally posted by dsraider View Post
                        I've been trying this on reply all day and have very little hair left on my head
                        in OnMarketData, remove "double" so it just looks like this

                        lastPrice = e.Price;
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          That did it.

                          Thanks, Ray!

                          Comment


                            #14
                            Originally posted by dsraider View Post
                            I believe I understand you correctly but I'm still getting 0s with this:

                            PHP Code:
                            #region Variables
                            double lastPrice 0;
                            #endregion

                            protected override void OnBarUpdate()
                            {
                                 Print(
                            lastPrice);
                            }

                            protected 
                            override void OnMarketData(MarketDepthEventArgs e)
                            {
                                 
                            double lastPrice e.Price;

                            I believe that I strongly advised you to access the value, without redeclaring it for local scope? OK, I know I did not put it in quite those words.

                            Comment


                              #15
                              Hahaha you have way too much faith in my ability to comprehend coherent English but I did click the "Thanks" button for getting me into "Variables."

                              I'm not a programmer so plenty of this talk goes right over my head

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              6 responses
                              27 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by frankthearm, Today, 09:08 AM
                              10 responses
                              35 views
                              0 likes
                              Last Post frankthearm  
                              Started by GwFutures1988, Today, 02:48 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post GwFutures1988  
                              Started by mmenigma, Today, 02:22 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by NRITV, Today, 01:15 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post NRITV
                              by NRITV
                               
                              Working...
                              X