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 helpwanted, Today, 03:06 AM
      1 response
      5 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      7 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X