Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set multiple profit targets for order (runner)

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

    Set multiple profit targets for order (runner)

    So I have been trying to make s trategy which sets up an order of 4 with 3 of them having one profit target, and the 4th (the runner) having a different profit target.
    I have currently achieved this with the following code:
    Code:
    protected override void OnBarUpdate()
    {
      [...]
      order_scalp = EnterShort(3, "Scalper");
      order_runner = EnterShort(1, "Runner");
    }
    
    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
    int quantity, int filled, double averageFillPrice,
    Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
    {
      if (filled == quantity)
      {
        double profitTarget = 0;
        if (order.Name == "Runner")
        {
          profitTarget = averageFillPrice - 5;
        }
        else
        {
          profitTarget = averageFillPrice - 1;
        }
    
        SetProfitTarget(order.Name,CalculationMode.Price, profitTarget);
        SetStopLoss(order.Name,CalculationMode.Price, averageFillPrice + 1.0, false);
      }
    }
    And this is somewhat working, I am getting trades for all 4.
    But I want both short orders to happen on the same bar, right now the two orders are executed in consecutive bars.
    I have not found a way to set a ProfitTarget for 3 of the 4 differently.

    I am currently running backtesting in strategy analyzer.

    Any help would be appreciated, I have been googling and searching this forum as well as the reference doc but could not find a solution to my problem.

    #2
    Hello Sledge Hammer, thanks for your post.

    I made a test script of the same setup and my protective orders are submitting on the same bar. I attached my test script, all it does is wait for the first real time bar, then submits the order once. I also set my EntriesPerDirection to 2 to accommodate the two sequential EnterShort orders. To test my script, place the attached file within Documents\NinjaTrader 8\bin\Custom\Strategies then compile, then run the strategy on a 10 second chart to see it working.

    I look forward to hearing of your results.

    Attached Files

    Comment


      #3
      Ok, that entries per direction solved my problem, thank you so much for your quick help Chris!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      54 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      131 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X