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 michaelwilcox, Today, 01:02 PM
      0 responses
      1 view
      0 likes
      Last Post michaelwilcox  
      Started by grazz, 07-28-2017, 06:11 PM
      26 responses
      6,846 views
      0 likes
      Last Post SpockTrader  
      Started by frslvr, Today, 11:36 AM
      4 responses
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by tkaboris, 07-15-2024, 01:42 PM
      13 responses
      25 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by richard_w, Today, 12:33 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X