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

Error in output time and date prints

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

  • NinjaTrader_Jesse
    replied
    Hello itrader46,

    Thank you for the reply and testing that.

    After further inspection of your code it looks like your print is within the ATM's callback however that is not a NinjaScript event driven callback so that won't relate to the context of your script.

    In your AtmStrategyCreate syntax you would need to surround any NinjaScript properties with a TriggerCustomEvent, this callback is not generally used to access NinjaScript properties but is used to set a boolean variable to denote the state of the ATM.

    Here is a way you can observe the difference between contexts, this is the same concept as the different context between OnBarUpdate and OnRender overrides.

    Code:
    AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Gtc, orderId, "AtmStrategyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => { 
                        //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                        if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId) 
                            isAtmStrategyCreated = true;
                        Print("Time from AtmStrategyCreate: " + Time[0]);
                        TriggerCustomEvent(new Action<Object>((o)=>{
                            Print("Time from TriggerCustomEvent: " + Time[0]);
    
                        }), null);
                    });




    In this test I was able to see the charts first bar date printed in addition to the current bars time:

    Time from AtmStrategyCreate: 10/27/2019 4:00:10 PM
    Time from TriggerCustomEvent: 10/29/2019 11:59:50 AM




    I look forward to being of further assistance.



    Leave a comment:


  • itrader46
    replied

    Unfortunately, " if(BarsInProgress != 1) return; " did nothing, as you can see from below prints

    S = 1 - Current Ask: 56.5 - 28/10/2019 12:15:28
    ++++++++++
    Long condition at: 56.5 @ 28/10/2019 12:15:28
    Long ATM triggered at: 56.5 - 22/10/2019 23:00:00 ###
    ##########
    Long ATM cancel price: 56.51 - 28/10/2019 12:15:28
    S = 1 - Current Ask: 56.51 - 28/10/2019 12:15:28
    >>> Long Order ID Reset Price: 56.5 - 28/10/2019 12:15:28
    >>## Long ATM ID Reset Price: 56.51 - 28/10/2019 12:15:29
    S = 1 - Current Ask: 56.51 - 28/10/2019 12:15:29
    ++++++++++
    Long condition at: 56.51 @ 28/10/2019 12:15:29
    'GetAtmStrategyEntryOrderStatus' method error: Order ID 'd93376136a7745fca080cd7c77197561' does not exist
    'GetAtmStrategyEntryOrderStatus' method error: Order ID 'd93376136a7745fca080cd7c77197561' does not exist
    'GetAtmStrategyEntryOrderStatus' method error: Order ID 'd93376136a7745fca080cd7c77197561' does not exist
    Long ATM triggered at: 56.51 - 22/10/2019 23:00:00 ###
    ##########
    Long ATM cancel price: 56.51 - 28/10/2019 12:16:01
    >>> Long Order ID Reset Price: 56.51 - 28/10/2019 12:16:01
    >>## Long ATM ID Reset Price: 56.51 - 28/10/2019 12:16:03

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello itrader46,

    Thank you for providing the file. I do see that you are using a secondary time frame and you are not filtering OnBarUpdate so we should see two sets of time stamps depending on what BarsInProgress called OnBarUpdate.

    What are the DataSeries settings being used when you apply the strategy?

    To clarify if you are seeing prints from different BarsInProgress you could change the print to the following:

    Code:
     
     Print("Short ATM created at: " + Convert.ToString(triggerPriceShort) [B]+ " - BarsInProgress: " + BarsInProgress[/B] + " - " + Time[0]);
    If that is what is happening in your test, a solution would be to use a BarsInProgress check:

    Code:
    protected override void OnBarUpdate()
    {    
       if(BarsInProgress != 1) return; // return for the primary series to execute logic on the tick series
    I look forward to being of further assistance.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello itrader46,

    Thank you for the reply.

    Unfortunately I cannot see what may have caused the prints to output in that way from this logic. As this is not the full script I cannot really see the full context to know what to expect. Are you using any secondary series in the script? Can you provide the script as an attachment and also details surrounding the test where you had seen the prints?

    I look forward to being of further assistance.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello itrader46,

    In that case I would need more information, can you provide a specific sample that shows the problem and what is required in code?


    I look forward to being of further assistance.

    Leave a comment:


  • itrader46
    replied
    Hello

    Both scripts are in OnBarUpdate

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello itrader46,

    Are you doing both prints from OnBarUpdate?

    The reason I ask is that there are different contexts in the script, if you are using OnBarUpdate I wouldn't necessarily expect that result but would need more info. If you are instead using OnRender or a custom action like a button click, the result would be expected based on the syntax used.

    Can you clarify that for me?


    I look forward to being of further assistance.

    Leave a comment:


  • itrader46
    replied
    I am loading 5 days, so yes, the older date is the start of the chart, but my OnBarUpdate starts with
    " if(State == State.Historical)
    return; "

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello itrader46,

    Thank you for the question.

    Where in your script are each of these prints? It appears the Long condition is working and the ATM condition is reporting an older date, is the older date by chance the start date of this chart/dataset?


    I look forward to being of further assistance.

    Leave a comment:


  • itrader46
    started a topic Error in output time and date prints

    Error in output time and date prints

    Hello

    I am coding a strategy and when I am printing the various stages into the output, some events don't print the right date and time, as below:

    Long condition at: 53.91 @ 18/10/2019 16:45:47
    Short ATM created at: 53.9 - 13/10/2019 23:00:00 HERE
    Long condition at: 53.92 @ 18/10/2019 16:46:00
    Long condition at: 53.92 @ 18/10/2019 16:45:48
    Long ATM created at: 53.92 - 13/10/2019 23:00:00 AND HERE
    Short Order ID Reset Price: 53.9 - 18/10/2019 16:46:00


    The syntax is identical:

    Print("Long ATM created at: " + Convert.ToString(stopPriceLong) + " - " + Time[0]);

    Print("Long condition at: " + Convert.ToString(currentAsk)/ + " @ " + Time[0]);

    Thank you

Latest Posts

Collapse

Topics Statistics Last Post
Started by Brevo, Today, 01:45 AM
0 responses
6 views
0 likes
Last Post Brevo
by Brevo
 
Started by aussugardefender, Today, 01:07 AM
0 responses
3 views
0 likes
Last Post aussugardefender  
Started by pvincent, 06-23-2022, 12:53 PM
14 responses
241 views
0 likes
Last Post Nyman
by Nyman
 
Started by TraderG23, 12-08-2023, 07:56 AM
9 responses
384 views
1 like
Last Post Gavini
by Gavini
 
Started by oviejo, Today, 12:28 AM
0 responses
6 views
0 likes
Last Post oviejo
by oviejo
 
Working...
X