Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy problems with enters, stops & exits

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

    Strategy problems with enters, stops & exits

    I have a strategy where I want to enter the market with 2 contracts, place 2 stoploss at a variable price (private double stop) as the candles are drawn, and place a single profit target (private double target). The other contract remains free.
    In code, it would be the following:

    if (State == State.SetDefaults)
    {
    EntriesPerDirection = 2;
    EntryHandling = EntryHandling.UniqueEntries;
    }
    ************************************************** ****
    protected override void OnBarUpdate()
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    {

    EnterShort("Venta");

    EnterShort("Salketa");
    SetStopLoss("Venta",CalculationMode.Ticks, stop, false);
    SetStopLoss("Salketa",CalculationMode.Ticks, stop, false );
    SetProfitTarget("Salketa",CalculationMode.Ticks, target);
    }
    }

    What is going wrong?

    Thanks in advance for your help.​

    #2
    Hello BIOK.NT,

    Call Set methods before calling the entry order method.


    What is going wrong?

    Is there something going wrong?

    What is the behavior you expect?
    What is the behavior you are observing?

    What output is being shown when enabling TraceOrders?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Answering your questions:

      - Call Set methods before calling the entry order method.: I´ve tried doing so in this way:

      if (Position.MarketPosition == MarketPosition.Flat)
      {

      SetStopLoss("Venta",CalculationMode.Ticks, stop, false);
      SetStopLoss("Salketa",CalculationMode.Ticks, stop, false );
      SetProfitTarget("Salketa",CalculationMode.Ticks, target);
      EnterShort("Venta");
      EnterShort("Salketa");


      }​

      - ​What is going wrong?

      The strategy only sends me two orders but does not place any Stop or target. Then it only executes two entries.


      -What is the behavior you expect?

      I expect that when the entry logic is fulfilled, the strategy will send two sell orders, place two SL at the price that I have storedin the "stop" variable and take one of the two positions at the price calculated in the "target" variable.


      - What output is being shown when enabling TraceOrders?

      I don´t know how to do that. I´ll search in the Help Guide to do so.


      Thank you for your time.

      Comment


        #4
        Hello BIOK.NT,

        To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Print the order.ToString() at the top of the OnOrderUpdate() override, as this will show us when orders become working and are being filled.​

        Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
        After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

        I am happy to assist you with analyzing the output from the output window.

        Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

        Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
        https://support.ninjatrader.com/s/ar...nd-TraceOrders
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello again Chelsea!

          I really appreciate your help.

          Here I send you attached the Output info as you indicated.
          Attached Files

          Comment


            #6
            Hello BIOK.NT,

            The output you have provided is showing stop loss and profit targets are being submitted. These are being submitted a extremely far distance from the entry price.

            orderId='NT-00000-117' account='Sim101' name='Venta' orderState=Filled instrument='YM 12-24' orderAction=SellShort orderType='Mercado' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=43091 onBehalfOf='' id=-1 time='2024-10-11 16:18:00' gtd='2099-12-01' statementDate='2024-12-04'

            orderId='NT-00002-117' account='Sim101' name='Stop loss' orderState=Submitted instrument='YM 12-24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=86194 quantity=1 tif=Gtc oco='NT-00000-117' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-10-11 16:18:00' gtd='2099-12-01' statementDate='2024-12-04'

            orderId='NT-00001-117' account='Sim101' name='Salketa' orderState=Filled instrument='YM 12-24' orderAction=SellShort orderType='Mercado' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=43091 onBehalfOf='' id=-1 time='2024-10-11 16:18:00' gtd='2099-12-01' statementDate='2024-12-04'

            orderId='NT-00003-117' account='Sim101' name='Stop loss' orderState=Submitted instrument='YM 12-24' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=86194 quantity=1 tif=Gtc oco='NT-00001-117' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-10-11 16:18:00' gtd='2099-12-01' statementDate='2024-12-04'

            orderId='NT-00004-117' account='Sim101' name='Profit target' orderState=Submitted instrument='YM 12-24' orderAction=BuyToCover orderType='Limit' limitPrice=22 stopPrice=0 quantity=1 tif=Gtc oco='NT-00001-117' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-10-11 16:18:00' gtd='2099-12-01' statementDate='2024-12-04'


            The Venta order filled at 43091. The stop loss was submitted 43103 ticks from the entry with a stop price of 86194.
            ​The Salketa order filled at 43091. The stop loss was submitted 43103 ticks from the entry with a stop price of 86194. The Profit Target was submitted 43069 ticks from the entry at a price of 22.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              I see.

              Thank you so much for your help!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              111 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              59 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              38 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              41 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              78 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X