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

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
    Chris L.NinjaTrader Customer Service

    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 ruudawakening, Today, 12:58 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by i019945nj, 12-14-2023, 06:41 AM
      4 responses
      64 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by thread, Yesterday, 11:58 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by stafe, Yesterday, 08:34 PM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by jclose, Yesterday, 09:37 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X