Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Timestamp in NinjaScript Output Does Not Match Strategy Analyzer Report

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

    Timestamp in NinjaScript Output Does Not Match Strategy Analyzer Report

    Hi, all

    So, in my strategy I have long and short entries, I tried to implement solution which was provided above, but no luck.

    1. I attached screenshot of the trade in Trades section for backtesting
    2. I attached screenshot of Print function in Output
    3. Here is my code for tackling this task

    What I don't understand:
    1. Why in trades close time for the trade is 20.01.2022 0:56:20 but in Print output I see 2022-01-19 19:45:01
    2. Output stops at 19.01.2022 20:10:00, just again why?

    Thank you in advance.

    // If not flat and our unrealized PnL has gone above $100, set pnlAbove to true
    if (Position.MarketPosition != MarketPosition.Flat && Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]) < 0)
    {
    // double PnL = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
    // Print("Time PnL: " + Time[0].ToString () + " " + PnL);
    pnlDown = true;
    }

    // now check if long, if pnlAbove is true, and if the unrealized PnL is less than $100. if so, close the position
    if (Position.MarketPosition == MarketPosition.Long && pnlDown == true && Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]) < 0)
    {
    // put your exit long method here, such as ExitLong()
    double PnL = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
    ExitLong();
    Print("The trade profit is " + PnL);
    Print ("Closing Long " + Time[0].ToString ());
    pnlDown = false; // setting pnlAbove back to false so it is ready to be checked for the next position
    }
    // else if the position is short, pnlAbove is true, and unrealized PnL is less than $100, close the position
    else if (Position.MarketPosition == MarketPosition.Short && pnlDown == true && Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]) < 0)
    {
    // put your exit short method here, such as ExitShort()

    double PnL = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
    ExitShort();
    Print("The trade profit is " + PnL);
    Print ("Closing Short " + Time[0].ToString ());
    pnlDown = false; // setting pnlAbove back to false so it is ready to be checked for the next position
    }​

    Entering position:
    orderId='NT-00003-11294' account='Backtest' name='RegShort' orderState=Submitted instrument='ES 12-22' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00003-11294' account='Backtest' name='RegShort' orderState=Accepted instrument='ES 12-22' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00003-11294' account='Backtest' name='RegShort' orderState=Working instrument='ES 12-22' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00003-11294' account='Backtest' name='RegShort' orderState=Filled instrument='ES 12-22' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=4578.125 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00004-11294' account='Backtest' name='RegShortStop' orderState=Submitted instrument='ES 12-22' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=4614.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00004-11294' account='Backtest' name='RegShortStop' orderState=Accepted instrument='ES 12-22' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=4614.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00004-11294' account='Backtest' name='RegShortStop' orderState=Working instrument='ES 12-22' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=4614.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00005-11294' account='Backtest' name='RegShortTP' orderState=Submitted instrument='ES 12-22' orderAction=BuyToCover orderType='Limit' limitPrice=4538.5 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00005-11294' account='Backtest' name='RegShortTP' orderState=Accepted instrument='ES 12-22' orderAction=BuyToCover orderType='Limit' limitPrice=4538.5 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'
    orderId='NT-00005-11294' account='Backtest' name='RegShortTP' orderState=Working instrument='ES 12-22' orderAction=BuyToCover orderType='Limit' limitPrice=4538.5 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-19 19:45:01' gtd='2099-12-01' statementDate='2022-12-30'​
    Click image for larger version  Name:	Error1.png Views:	0 Size:	51.0 KB ID:	1229387Click image for larger version  Name:	Error2.png Views:	0 Size:	22.1 KB ID:	1229388
    Last edited by NinjaTrader_Emily; 12-30-2022, 09:27 AM.

    #2

    Hello mrboltuae,

    Thank you for your note.

    It does appear that your question is more focused on the timestamp discrepancy than the actual logic to have your strategy exit a position based on PnL, so I have moved it to its own thread. In the future, please start a new thread if you have a new, unrelated question. Feel free to include a link to other forum posts that you would like to mention/reference. This helps use to keep the forums organized and address the different users in a timely manner. Thank you for your understanding.

    (For reference, this is the thread the reply was originally posted to: https://ninjatrader.com/support/foru...certain-amount)

    So I may better assist you, please answer the following questions:
    • If you look at the Orders display rather than the Trades display, do the timestamps line up as expected?
    • What were the settings for the backtest (for example, the start date, end date, trading hours, Data Series settings, etc)?
    • What version of NinjaTrader 8 are you using? This may be found at Control Center > Help > About

    Thank you for your patience. I look forward to your reply.

    Comment


      #3
      Thanks, Emily. Noted. I found the problem, I restricted time in OnBarUpdate by myself that's why I've got such results.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      55 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      132 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X