Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not Executing Desired Stop Value

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

    Not Executing Desired Stop Value

    Hello NT,

    I'm trying to get my Ninjascript to execute a trade based on the following parameters:

    Code:
    if ((Times[0][0].Date >= new DateTime(2012, 5, 15))
    && (Times[0][0].Date <= new DateTime(2012, 9, 21)))
    {
    entry6_xr = 5;
    entry6_daysback = 9;
    Target = 3100;
    Stop = 3000;
    }
    However, during this time frame the script enters a trade on 6/12/2012 and exits the trade on 6/14/2012 using my default setting of Stop = 3100 instead of the Stop = 3000 I put in the above code.

    This is my default setting and the stop loss method that occurs earlier in the script:

    Code:
    entry6_xr = 5;
    entry6_daysback = 10;
    Target = 3100;
    Stop = 3100;
    }
    else if (State == State.Configure)
    {
    SetProfitTarget(@"Entry06Long", CalculationMode.Currency, Target);
    SetStopLoss(@"Entry06Long", CalculationMode.Currency, Stop, false);
    SetProfitTarget(@"Entry06Short", CalculationMode.Currency, Target);
    SetStopLoss(@"Entry06Short", CalculationMode.Currency, Stop, false);
    }
    I included a print command to list all the parameters and set order tracing to true. This is what's showing up on my output screen:

    6/11/2012 4:00:00 PM | entry6_daysback: 9 | entry6_xr: 5 | target: 3100 | stop: 3000
    6/11/2012 4:00:00 PM Strategy 'Entry06BigRangeBigMo2WF/-1': Entered internal SubmitOrderManaged() method at 6/11/2012 4:00:00 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Entry06Short' FromEntrySignal=''
    Strategy 'Entry06BigRangeBigMo2WF/-1': Stop/target handling set to 'By strategy position' since currency based stop order was placed.
    6/12/2012 4:00:00 PM | entry6_daysback: 9 | entry6_xr: 5 | target: 3100 | stop: 3000
    6/13/2012 4:00:00 PM | entry6_daysback: 9 | entry6_xr: 5 | target: 3100 | stop: 3000
    6/13/2012 4:00:00 PM Strategy 'Entry06BigRangeBigMo2WF/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-00002-54429' account='Backtest' name='Profit target' orderState=Working instrument='CL 10-21' orderAction=BuyToCover orderType='Limit' limitPrice=108.77 stopPrice=0 quantity=1 tif=Gtc oco='NT-00000-54429' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2012-06-11 16:00:00' gtd='2099-12-01' statementDate='2021-09-14'
    6/13/2012 4:00:00 PM Strategy 'Entry06BigRangeBigMo2WF/-1': Cancelled OCO paired order: BarsInProgress=0, orderId='NT-00002-54429' account='Backtest' name='Profit target' orderState=Cancelled instrument='CL 10-21' orderAction=BuyToCover orderType='Limit' limitPrice=108.77 stopPrice=0 quantity=1 tif=Gtc oco='NT-00000-54429' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2012-06-11 16:00:00' gtd='2099-12-01' statementDate='2021-09-14'
    6/14/2012 4:00:00 PM | entry6_daysback: 9 | entry6_xr: 5 | target: 3100 | stop: 3000

    How can I get the trades to execute according to my first set time based parameters shown above?

    Thanks,
    Ben

    #2
    Hello harr5754,

    Thank you for the post.

    From what I can see the print you added shows 3000 being used for the stop offset. If you are not calling the SetStopLoss again before the entry then it would still use what you had set in State.Configure.

    Make sure that in your OnBarUpdate code before your entries you have the lines:

    Code:
    SetProfitTarget(@"Entry06Long", CalculationMode.Currency, Target);
    SetStopLoss(@"Entry06Long", CalculationMode.Currency, Stop, false);
    SetProfitTarget(@"Entry06Short", CalculationMode.Currency, Target);
    SetStopLoss(@"Entry06Short", CalculationMode.Currency, Stop, false);

    I look forward to being of further assistance.

    Comment


      #3
      Thank you, Jesse. That solved the problem!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X