Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

{Ninjascript} NT8 - create stop orders and SL, TP

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

    {Ninjascript} NT8 - create stop orders and SL, TP

    Dear all, hope you are fine,
    I need to create Stop and Limit Orders and set (for each orders) StopLoss and ProfitTarget
    Please, could you give me some code sample?

    #2
    Hello fscabrera03,

    Thanks for your post.

    Here is an example of a long limit entry:

    if (some entry conditions)
    {
    SetProfitTarget(CalculationMode.Ticks, 20); // set profit before entry
    SetStopLoss(CalculationMode.Ticks, 20); // ste stop before entry
    EnterLongLimit(0, true, 1, entryPrice, ""); // using the Advanced order handling overload.
    }

    Here is an example of stop limit entry:

    if (some entry conditions)
    {
    SetProfitTarget(CalculationMode.Ticks, 20); // set profit before entry
    SetStopLoss(CalculationMode.Ticks, 20); // ste stop before entry
    EnterStopLongLimit(0, true, 1, entryPrice, entryPrice ""); // using the Advanced order handling overload.
    }

    I would suggest spending some time reviewing the Managed Approach section that lists all of the entry methods and provides an example of each: https://ninjatrader.com/support/help...d_approach.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much, i did it!
      Here is my code:

      else if (State == State.Configure)
      {
      SetProfitTarget("", CalculationMode.Pips, 20);
      SetStopLoss("", CalculationMode.Pips, 20, false);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 2)
      return;

      // Set 1
      if ((Close[0] > Open[0])
      && (Close[1] > Open[1])
      && (Close[2] > Open[2]))
      {
      EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), 1.0845 , "");
      }

      }

      Now, Im having one more question, how can I create this EnterLongStopMarket with expiration date?
      I need that this order (if is not filled) exist 1 week and if is not filled cancell it.

      Can you help me with some sample code please?

      Comment


        #4
        Hello fscabrera03,

        Thanks for your reply.

        In your first post you have a tag that says Ninjascript editor. In your Post #3 you have posted code that appears to be generated by the strategy builder.

        So that I can provide an appropriate reply, please advise if you are using the Ninjascript editor or the Strategy Builder. The reason for asking is that the Strategy Builder has certain limitations.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I have created the strateg on the strategy builder but unlocked the code to see in ninjascript editor

          Comment


            #6
            Hello fscabrera03,

            Thanks for your reply.

            If I understand correctly you have unlocked the Strategy Builder strategy and are now working with it in the Ninjascript editor.

            Regarding, "how can I create this EnterLongStopMarket with expiration date?" In a Ninjascript strategy, you cannot provide an order with an expiration date. What you can do is to place an order what will remain live until you cancel it and you can create logic in your Ninjascript to check if the market position is flat on that date and then cancel the order. You cannot do this in the Strategy Builder.

            Here is a link to the help guide on the Managed Approach which will provide an overview of Ninjascriopt strategies: https://ninjatrader.com/support/help...d_approach.htm In that section you will find links to all of the order methods and in each order method you will find the "advance Order handling" overload that includes the bool "IsLiveUntilCanceled" that you would need to use to keep the order in place (otherwise it is automatically cancled if not filled on the same bar it is submitted).

            Here is a link to the Cancel order method and an example strategy:



            Here is a link to working with date/time: https://ninjatrader.com/support/help...me_objects.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello, I came across this post and clicked the links that Paul H posted. They seemed to no longer work. Would anyone be able to send the right links?

              These links are no longer work:

              https://ninjatrader.com/support/help...d_approach.htm
              https://ninjatrader.com/support/help...ancelorder.htm​​
              Last edited by Brevo; 12-05-2023, 05:08 AM.

              Comment


                #8
                Hello Brevo,

                Thank you for your post.

                Here are the links below:

                Managed Approach - https://ninjatrader.com/support/help...d_approach.htm
                CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm

                Please let us know if we can assist further.
                Gaby V.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by kulwinder73, Today, 10:31 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by RookieTrader, Today, 09:37 AM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by terofs, Yesterday, 04:18 PM
                1 response
                24 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by CommonWhale, Today, 09:55 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Gerik, Today, 09:40 AM
                2 responses
                8 views
                0 likes
                Last Post Gerik
                by Gerik
                 
                Working...
                X