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

isLiveUntilCancelled with LongLimit order.... keep long limit order alive for x bars

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

    isLiveUntilCancelled with LongLimit order.... keep long limit order alive for x bars

    Hi there, I am not a programmer and could use some help please! I have my set of conditions and would like a LONG LIMIT ORDER (adjusted by minus 2 points) to stay alive for 5 bars.


    Code:
    // Set 1
                if ()
                {
                    EnterLongLimit(Convert.ToInt32(DefaultQuantity), (GetCurrentAsk(0) - 2) , @"");
                }
    How do I do that? My strategy is recalculating on price change, so the limits obviously move..
    I saw the "LiveUntilCancelled" and while it's not exactly what I am looking for, I'd also be happy with that for now..

    Thanks for your help guys (and girls!)

    #2
    Hello Oracletrades,

    Thank you for your post.

    Actually, yes, you'd want to use IsLiveUntilCancelled here.

    If you don't, it'll cancel the order when the conditions for entry are no longer true. You'd just have to submit the order cancellation after 5 bars have passed if it hasn't filled.

    Here's an example of how to use this from our help guide:


    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      gees, I've been searching for the keyword in the forum for half an hour now and couldn't find the link you referenced! Just out of curiosity, how would I accomplish a "lifespan" of 5 bars for an order? Would that be a lot more complicated? I'm super happy with the good til canceled which works for my slow-pattern trading, just curious and hoping to learn a bit more..

      Comment


        #4
        Hello Oracletrades,

        Thank you for your reply.

        No, not terrifically more complicated. I'd use BarsSinceEntryExecution to help control your exit:



        So, you could do something like:

        Code:
        if (BarsSinceEntryExecution() > 5)
        {
             //your order cancellation logic goes here
        }
        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Team Support, following up on this old thread as I cannot seem to get my codes to work.

          I followed the code from this thread and downloaded the samplecancelorder strategy, used the (BarsSinceEntryExecution()​ code as well but still the bar cancel after 5 bars doesn't work.
          The samplecancel order strategy was working fine, until I added in the indicators to the script. Not sure where it went wrong as my script without the bar cancellation works fine.

          Will be very happy if you can assist me on this as well as how to add in the short limit entry for this strategy of super trend.

          See attached script strategy that I tried to code myself. I apologise if some codes are wrong as I have very limited programming knowledge as I tried self learning here and there.
          I tried the Strategy Builder, but it is limited to what I needed the script to perform.

          Thanks!
          Peter
          Attached Files

          Comment


            #6
            Hi, thanks for writing in.

            All of your code is wrapped into this statement:

            if ((Position.MarketPosition == MarketPosition.Flat)
            && (ADX1[0] > Twenty)
            && (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) < 150000)
            && (TSSuperTrend1.UpTrend[0] > Zero)
            && (TSSuperTrend1.DownTrend[1] > Zero))
            {​
            //all of the order submission and cancelation occurs in this code block
            }

            This is likely why its not working to cancel out the order.

            Kind regards,
            -ChrisL​
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              I see. I got the codes from the Strategy builder unlock. It was working fine without the cancel order add on script.
              In this case, can you give me a sample entry so I can expand from there?
              Thanks!
              Last edited by siberfutures; 11-30-2022, 09:14 AM.

              Comment


                #8
                Hi, thanks for the follow up. You will need to add your condition into the existing entry condition. See the screenshot here:


                Kind regards,
                -ChrisL​
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jclose, Today, 09:37 PM
                0 responses
                5 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,414 views
                0 likes
                Last Post Traderontheroad  
                Started by firefoxforum12, Today, 08:53 PM
                0 responses
                11 views
                0 likes
                Last Post firefoxforum12  
                Started by stafe, Today, 08:34 PM
                0 responses
                11 views
                0 likes
                Last Post stafe
                by stafe
                 
                Started by sastrades, 01-31-2024, 10:19 PM
                11 responses
                169 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X