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

How to place the same SetStopLoss logic in ExitLongStop

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

    How to place the same SetStopLoss logic in ExitLongStop

    Hi. Thank you for your time. I'm a novice programmer and I'm trying to create a strategy with code that I'm copying and modifying. I have this input code

    EnterLongStop(Convert.ToInt32(DefaultQuantity),Hig h[0] + TickSize*2,"MyLongEntry"+ CurrentBar);

    and this one of exit

    SetStopLoss ("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[0]- 2*TickSize), false);

    I want to do the same thing this code does but with ExitLongStop

    I don't get it. Can you help me? Thank you

    #2
    Hello julifro,

    Thanks for your post.

    Can you clarify what specific code you are using and what specifically you don't get?

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi. Excuse my English. It's not my natural language.
      I'm using a code provided by ninjatrader support in another post and I have to use
      private IOrder stopOrder = null;
      but if I use this code

      stopOrder = EnterLongStop(Convert.ToInt32(DefaultQuantity),Low[0] -TickSize*2, "MyLongEntry "+ CurrentBar);

      gives me an error.
      This code is used in the example provided by ninjatrader support:
      stopOrder = ExitLongStop(0, true, stopOrder.Quantity, Position.AvgPrice, "MyStop", "MyLongEntry "+ CurrentBar);

      This code works but doesn't put the stop where I want it to be two ticks under the bar before the input bar. I have this code that if it does

      SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[0]-2*TickSize), false);

      but I can't use it with private IOrder stopOrder.

      I've explained? thank you.

      Comment


        #4
        Hello julifro,

        Thanks for your reply.

        Regarding the two codes of:
        stopOrder = EnterLongStop(Convert.ToInt32(DefaultQuantity),Low[0] -TickSize*2, "MyLongEntry "+ CurrentBar);
        stopOrder = ExitLongStop(0, true, stopOrder.Quantity, Position.AvgPrice, "MyStop", "MyLongEntry "+ CurrentBar);


        The first one is an entry method which generates a buy stop order to enter a long position. Typically, to enter a long position above the current price you would place this entry order above the current price so specifying it below the current price would generate an error.

        The second one is an exit long method that generates a sell stop order to exit a long position and places the order at the entry price (position.AvgPrice). If you change the price from Position.AvgPrice to Low[0] -TickSize*2 does that meet your needs? IE: stopOrder = ExitLongStop(0, true, stopOrder.Quantity, Low[0] -TickSize*2, "MyStop", "MyLongEntry "+ CurrentBar);
        Paul H.NinjaTrader Customer Service

        Comment


          #5

          Thank you very much. It works perfectly. You can explain the logic you followed to change
          execution.Order.AvgFillPrice - 10 * TickSize
          by
          Low[0] -TickSize*2 ?
          Thank you

          Comment


            #6
            Hello julifro,

            Thanks for your reply.

            I'm sorry I do not understand, I do not see where execution.Order.AvgFillPrice - 10 * TickSize is used in any of your posts.

            The parameters of the methods can be found in the help guide for each order type. Here is a link to all of the order types: https://ninjatrader.com/support/help...er_methods.htm
            Last edited by NinjaTrader_PaulH; 12-19-2018, 03:02 PM. Reason: Note: Replaced NT8 link with correct NT7 link.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            8 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            6 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X