Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData question

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

    OnMarketData question

    Hi,

    I've got the following code within a strategy:

    protectedoverridevoid OnMarketData(MarketDataEventArgs e)
    {

    if(e.MarketDataType == MarketDataType.Last)
    {

    if(Low[0] <= EnterPlace - (4 * TickSize))
    {TRAILPlace = EnterPlace - (4 * TickSize);}
    }

    }

    It is intended to simply compare the current Low with a value 4 pips below the entryprice, and set a variable if lower. It should be calculated on each tick. It doesn't seem to be recognized when the strategy runs...is there an obvious code error here?

    #2
    If the conditions evaluate to true, TRAILPlace will be set to the same value over and over again (unless EnterPlace changes.)

    Comment


      #3
      Thanks, but what are those conditions...in other words this command:

      if(e.MarketDataType == MarketDataType.Last){...}

      I assume that will evaluate to "true" upon each change of price...that's how I understand it--is that correct?

      Comment


        #4
        It will evaluate to true when OnMarketData() method is called due to a change in the last traded price.
        RayNinjaTrader Customer Service

        Comment


          #5
          Thanks for your reply. I've actually moved my code into the "OnBarUpdate" method because my strategy is evaluated tick-by-tick (on bar close is false). The code is simple:

          if(Low[0] <= EnterPlace - (4 * TickSize))
          {TRAILPlace = EnterPlace - (
          4 * TickSize);}


          However it seems not to be evaluating, it DOES seem to work out fine when I change the "on bar calculate" to TRUE and figure at the end of a bar...any idea why it may not be triggering and/or the easiest way to accomplish this?

          Comment


            #6
            The easiest way to figure out what's going on is to add Print statements to your code (before the "if" and within the bracketed code) and then you'll get some indication of what is going on. Or have you already tried that?

            Comment


              #7
              Yea, I've tried that. That's part of the reason I know it doesn't seem to be called...

              Comment


                #8
                It's hard to tell what might be going on with just the few lines of code that you've posted.

                Comment


                  #9
                  What you want to do is monitor your EnterPrice variable then. See what the value is and do it manually to see if your if-statement was suppose to evalute to true.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  607 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  353 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  560 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  561 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X