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 lightsun47, Today, 03:51 PM
      0 responses
      5 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      9 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      45 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      9 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X