Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsInProgress - SetStopLoss - SetProfitTarget

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

    BarsInProgress - SetStopLoss - SetProfitTarget

    I have programmed a strategy which works as expected :
    for Entry I use:
    EnterLongStop & EnterShortStop

    for Exit I use in Initialize:
    SetStopLoss
    SetProfitTarget


    The main data series is a 6 Tick Range Bars. The issue I have is that I want to back test with Tick data but I cannot use BarsInProgress with SetStopLoss and SetProfitTarget

    I know I should be able to use :

    ExitLongStop - ExitShortStop
    ExitLongLimit - ExitShortLimit

    My attempts are giving me errors that shows I am not processing the orders right.
    How can I write my own SetStopLoss and SetProfitTarget with BarsInProgress?

    #2
    Hello afshinmoshrefi,
    Thanks for your post.

    Unfortunately you cannot use the Set() methods with the secondary bar series and there are no native workarounds.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      If I use
      ExitLongStop
      ExitLongLimit


      for managing profit and stop,
      Let say, stop is reached. How do I manage the other order? can do OCO?

      thanks,

      Afshin

      Comment


        #4
        Hello Afshin,
        Yes, in managed approach it will be automatically OCO'ed.

        Say, you have 2 orders one placed via the ExitLongStop and the other via the ExitLongLimit, then if one gets filled the other order will be automatically cancelled. You do not have to write any code for the OCO.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Then I must be doing something wrong. This is the code I use after the entry order is filled:

          stopOrder=ExitLongStop(1,false,1,sPrice,"targetLon gStopLoss","target1"); // stop loss
          profitOrder=ExitLongLimit(1,false,1,pPrice,"target LongProfit","target1"); //profit target
          In my traces, it looks like one order is not canceling the other. I'm getting the following error:

          **NT** A SellShort stop order placed at '12/30/2012 6:00:01 PM' has been ignored since the stop price is greater than or equal to close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

          and then nothing works.

          Comment


            #6
            Hello Afshin,
            The stop price for the sell stop order must be below the current market price. If you try placing it above the current market price then it will be rejected (reverse for long stops).

            For example if the current market price is $1450, then a sell stop price should be placed below $1450. If you try placing it at say $1455 then the order will get rejected.

            Please use the Print function and see where exactly the strategy is trying to place the stop order.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              I get this error after an order is filled. It seems to be dangling and not getting canceled as OCO should cancel it.

              Comment


                #8
                Hello Afshin,
                The order will get rejected if you try to place the sell stop above the current market price.

                Whether the strategy will be disabled or not will depend on what error handling you have set.

                To assist you further may I know did you set the error hardling to "TakeNoAction"
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                650 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                577 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X