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

EnterLongMIT help

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

    EnterLongMIT help

    Hello,

    The goal is to move from a simple EnterLong() where my trade gets jammed into the market mid-bar to a more elegant EnterLongMIT() where my order could be perched one tick over the signal bar where it will wait for the market to trigger it, subsequently triggering my target and stop-loss protection orders.

    I have read the docs and it seems that EnterLongMIT() from the managed approach is the right choice for this. However, I'm not seeing it work as intended. Also, while the method accepts up to 5 arguments there is only one example of its usage in the docs which does no meet my needs. I'm double confused.

    Can I simply replace:

    EnterLong(1, "My Trade");

    with

    EnterLongMIT(1, High[0] + (10 * TickSize), "My Trade");

    Now, I thought would place my order 10 ticks above the signal bar (for testing I'm doing 10 ticks just so I can clearly see it's working). However, when I try the strategy in the historical playback, even at 1x, it places the order right above the signal and it immediately triggers.

    What do you think I'm doing wrong?

    Thanks,

    Coop
    Last edited by coopgrafik; 03-15-2021, 07:49 PM.

    #2
    No.

    It appears you may have a fundamental misunderstanding of MIT orders.

    A buy MIT order must be submitted below current market price.

    Comment


      #3
      Oh I see. Would it be EnterLongStopMarket(); then?

      EnterLongStopMarket(1, High[0] + (10 * TickSize), "My Trade");

      Would this drop a market order 10 ticks above the signal?

      Comment


        #4
        Hello Coop,

        Yes, a buy Stop Market would be placed above the current ask, a buy Market If Touched would be below the current ask.

        As a heads up, if the order is submitted on every bar to keep it alive, the price you are submitting will also be updating, and pushing the order higher on each call.
        You may want to save the price to a variable, set the variable price once, and use this for every call to the order method.

        If you are not submitting the order on every bar, the order will automatically expire when the bar closes, as the isLiveUntilCancelled bool is not submitted as true. Use the overload that includes this and set this to true to keep the order alive.
        EnterShortStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          EnterLongStopMarket(1, Low[0] - TickSize, "ShortTrade);

          This works but it gets canceled on the next bar of the trade does not get triggered.

          The docs talk about adding a true argument for isLiveUntilCancelled. I added that but it won't compile. I honestly, even after reading the docs, I don't understand the purpose or meaning of barsInProgressIndex or what number it wants. Also, the docs, *and* all the docs do this, only provides one of the simplest version of example code but that line does not show how all five arguments are used together. I really wish the docs, if they are going to cite a method with 5 arguments would then show the usages in the different forms. That I'm sure would be very helpful to people who are trying to learn the methods.

          Would it be possible to simply revise that top line of code for me please to simply remain open?

          Thank you
          Last edited by coopgrafik; 03-15-2021, 07:13 PM.

          Comment


            #6
            Originally posted by coopgrafik View Post
            EnterLongStopMarket(1, Low[0] - TickSize, "ShortTrade");

            This works but it gets canceled on the next bar of the trade does not get triggered.

            Would it be possible to simply revise that top line of code for me please to simply remain open?
            Try this,

            Code:
            EnterLongStopMarket([B][COLOR=#e74c3c]0[/COLOR][/B], [B][COLOR=#e74c3c]true[/COLOR][/B], 1, Low[0] - TickSize, "ShortTrade");
            Let me explain in simple terms what you're missing.

            The barsInProgressIndex represents an advanced concept called "bars".
            (don't laugh -- but yeah, it's that simple)

            You already know about "bars", because they exist on your chart. You see
            them visually (and work with them in code) all the time.

            So, for whatever type of bars on your chart, whatever interval, such as a 1-min,
            or 6-Range, or 4-Renko, etc, the bars on the chart are always called the "primary
            bar series" and they always have an index of '0'.

            Huh? Index? What index?
            Ah-hah, this is where it goes deeper. Additional bar series can be added to the
            chart (they stay invisible), but all bar series are stored in an array.

            What? An array? What array?
            I told you it gets deeper.
            And, guess what, this array I'm talking about -- it's called "BarsArray".
            (Yeah, I know, he-heh, real clever name. doh!)

            Well, this array is always populated with at least 1 element, which is always
            stored at index '0' -- ta-dah! Arrays start at index '0', remember? Well, those
            bars at index '0' are always the primary bar series (ya know, the visual bars
            from your chart).

            Still with me?

            Ok, so why would anyone want additional bar series?
            You'd want to do that if you want to look at Google and Apple inside the same
            script, or look at ES and YM together, or compare a 1-min ES vs a 10-min ES.
            Well, the additional bar series have to be added programmatically, by you,
            using AddDataSeries.

            What is AddDataSeries really doing?
            It's expanding the array called "BarsArray", by adding elements to it.

            The 1st call to AddDataSeries creates the 2nd element in BarsArray.
            The 2nd call to AddDataSeries creates the 3rd element in BarsArray.
            ... and so on.

            Remember, the 1st element in BarsArray is your primary bar series (ya know,
            the visual bars on your chart) and is always automatically added as the
            first element of BarsArray. If you want more bars for some reason, then
            you add them via AddDataSeries.

            So, fast forward, barsInProgressIndex in the order methods is actually
            selecting the instrument you wish to trade. If no barsInProgressIndex is given
            in the argument list, it is assumed to be '0', which is, ya know, just the visual
            bars on your chart, and the instrument for index '0' is just your chart instrument.

            [EDIT: Technically, it's not assumed to be '0'. If not specified, this value is taken
            from the active "bars context", which is just another way of saying the value is
            taken from the BarsInProgress internal variable. But, if you don't add any
            additional bar series, well then, yes, BarsInProgress will always be '0'.]

            The barsInProgressIndex argument is just an index into BarsArray. which you
            previously populated (or not) via AddDataSeries. But, remember, index '0' is
            always in there.

            If you give a value of '1' for barsInProgressIndex, then this means you have
            previously called AddDataSeries (at least once) to add a secondary data series,
            which are invisible on the chart but accessible programmatically.

            And now, finally, we've arrived at The Grand Masterful Executive Summary.
            Let's put all the pieces together.

            Ready?

            If you're not calling AddDataSeries, then just use '0' for barsInProgressIndex.
            (yes, it's that simple)

            The last piece is, in order to use isLiveUntilCancelled (which is what you're
            really after
            ) you also gotta specify that pesky barsInProgressIndex argument,
            but that argument is a minor player in your case -- you really need that 2nd
            argument, so use '0' (a safe default, probably) for barsInProgressIndex.

            [EDIT: I added "probably" because until you get into some really advanced
            stuff like Multi-Instrument and Multi-TimeFrame scripts, most people have no
            use for AddDataSeries. Which means for most scripts, BarsInProgress is
            always '0', and yeah, for those scripts, specifying '0' is the safe and (only)
            appropriate value for barsInProgressIndex.]
            Last edited by bltdavid; 03-15-2021, 10:53 PM.

            Comment


              #7
              Hello coopgrafik,

              If you have a compile error, we are happy to assist. Please provide the full error.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                bltdavid,

                Thank you sooooo much for your detailed answer! The documentation is just so dry it almost passive-aggressive. I really appreciate the leg up and if there was some kind of Reddit Gold award here I would give it to you. I was able to get over the hump with this advice.

                You rock!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                4 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                40 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Kaledus, Today, 01:29 PM
                5 responses
                15 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X