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

Multiple Series Immediately Closes after Opening Position

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

    Multiple Series Immediately Closes after Opening Position

    I am running a strategy on the NQ futures chart and placing the trades on the MNQ(chart).

    I would like to be able to adjust the Profit Target and Stop Loss similar to entering an ATM order from the chart trader where you can drag the profit and stop on the chart.

    I was able to accomplish this if I run a strategy on the primary chart by following the example from a previous post on exit methods and the ExitMethodsSample strategy (attached).


    When I try to use the same exit method using MNQ as the secondary the position immediately closes after opening. Aside from referencing the secondary series the code is the same.

    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    AddDataSeries("MNQ 03-21", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);

    If (Entry Logic True)

    EnterLong(2,Convert.ToInt32(Contracts), Convert.ToString(EntryNameTrevDtv));
    PositionOpen = true;

    **

    Exit Logic

    if (Positions[2].MarketPosition == MarketPosition.Long && PositionOpen == true)
    {
    ExitLongStopMarket(2, true, Position.Quantity, Position.AveragePrice - StopLoss * TickSize, "Stop Loss","");
    ExitLongLimit(2, true, Position.Quantity, Position.AveragePrice + ProfitTarget * TickSize, "Profit Target", "");
    PositionOpen = false;
    }

    However if I use SetProfitTarget and SetStopLoss the position does not close immediately and the target and stop appear on the MNQ (secondary) chart.

    //SetProfitTarget(Convert.ToString(""), CalculationMode.Ticks, ProfitTarget);
    //SetStopLoss(Convert.ToString(""), CalculationMode.Ticks, StopLoss, false);


    Any help with this is appreciated.


    Attached Files

    #2
    Hello sdauteuil, thanks for writing in.

    Could you please post your modification of the original script so I can test on my end? The IsLiveUntilCanceled parameter is true, so I would expect the orders to stay alive after subsequent bars.

    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks

      I got it to work. I was missing the reference to the MNQ series in the exit code.

      ExitLongLimit(2, true, Positions[2].Quantity, Positions[2].AveragePrice + ProfitTarget * TickSize, "Profit Target", "");

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Segwin, 05-07-2018, 02:15 PM
      14 responses
      1,788 views
      0 likes
      Last Post aligator  
      Started by Jimmyk, 01-26-2018, 05:19 AM
      6 responses
      837 views
      0 likes
      Last Post emuns
      by emuns
       
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,292 views
      1 like
      Last Post jgualdronc  
      Started by Touch-Ups, Today, 10:36 AM
      0 responses
      12 views
      0 likes
      Last Post Touch-Ups  
      Started by geddyisodin, 04-25-2024, 05:20 AM
      11 responses
      62 views
      0 likes
      Last Post halgo_boulder  
      Working...
      X