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

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.
    JesseNinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Ousher, Yesterday, 11:12 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by You4Life, Yesterday, 08:20 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by focus333, Yesterday, 05:56 PM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by itsthefriz, Yesterday, 04:19 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by johnMoss, Yesterday, 04:06 PM
      0 responses
      8 views
      0 likes
      Last Post johnMoss  
      Working...
      X