Announcement

Collapse
No announcement yet.

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 tonynt, Today, 09:33 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post tonynt
                              by tonynt
                               
                              Started by minotti1, Today, 08:31 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by SmartArtsStudio, 05-15-2021, 10:46 AM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Airwave, Today, 06:02 AM
                              2 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by bottakemoney, Today, 12:10 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Working...
                              X