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 NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X