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

Search for a bar by its time

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

  • Stanfillirenfro
    replied
    Many thanks Paul for all your help.
    I proceed with the code and will revert to you soon.

    Tx again!

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    200 would likely be 2 minutes after midnight, 300 = 3 minutes, etc.

    The indicator TestforStan will print the integer value of time from the bar, this is from your use of ToTime() which converts the datetime of the bar to an integer value representing time

    The indicator TesforStan2 will print the date and time of the bar in a date-time format.

    You may want to review this educational sample on working date time: https://ninjatrader.com/support/help...me_objects.htm


    Leave a comment:


  • Stanfillirenfro
    replied
    Hi Paul!

    I have the two indicators on the chart.
    On the output1, I have on the bottom line the following:"16.04.2021 22:01:00" Other numbers are integers starding with 200, than 300, than 400... up to 220100.
    Does this 200 represent the time of a bar? I think no, otherwise it should have six digits. Right?
    Why is the bottom line different from othe rest?

    Leave a comment:


  • Stanfillirenfro
    replied
    Hi Paul,

    I could not carry out the last test with both indicators on the chart as you have specified above. My platfom stops working since app. 1 hour. I have just sent a massage to the support center.

    I will revert to you as soon as the issue will have been resolved.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    Good questions.

    The code if(State == State.Historical) return; is used to skip over historical bars. The reason I used that was that I wanted to be sure that for the purposes of your for loop that enough bars were present before your code was run. Also it looked like if your code ran on every historical bar and it may take some time so using the historical check was just a quick way to get the prints going.

    You do not need to use that code.

    Leave a comment:


  • Stanfillirenfro
    replied
    Hi Paul!
    Let's imagine that I have a long code, not just few linnes, let's say with loops etc... Would I have any problem printing something if the condition in the code in #8 in place not direct a the beginning of protected override void OnBarUpdate()? Where should I place " if(State == State.Historical)" in "protected override void OnBarUpdate()"in order to print properly?

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    I can only surmise that it was just a matter of waiting for a bar close to occur.

    It is critical though that you be able to send prints to the output window because using prints is a key part of debugging and should be your first step when the code is not working as expected.

    Leave a comment:


  • Stanfillirenfro
    replied
    Paul, many thanks one more time. But what happened in between? I have just repeated the procedure this time with the file you posted in #8 and it is working also now? WHat happened in betwen?

    Many thanks fir your help.
    I will revert to you after improving my entire code.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    Whew, glad that is working!

    The difference is that the script you just ran print on every historical bar and TestforStan waits for a real time bar to close before it will print. So on the 1 minute chart of NQ 06-21, please add the indicator bar timer and then add the indicator TestforStan, when you see the time gets to zero you should expect to see prints.

    Leave a comment:


  • Stanfillirenfro
    replied
    Thanks Paul for your help.

    It is printing now every minute on output 1.

    What was happening with TestForStan?

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    Sorry, you are having such difficulty!

    No setting would be needed.

    Here is another script to import that should just print the time of every bar, please import, test and advise. It should print immediately.

    TestsforStan2.zip

    If this script does not print then please advise what version of NinjaTrader8 you are using (found under help>about).
    Also please make sure you are checking the "Log" tab of the control center for any related error messages.

    Leave a comment:


  • Stanfillirenfro
    replied
    Thanks Paul for your help.
    I failed again to have something printed on output tab.
    It really does not work in my case.
    Is there any setting I should look for before proceeding?

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    To test on my end I delete the indicator, download and imported the indicator I posted in Post#8. I created a chart of NQ 06-21 1 minute bars connected to Real time data and applied the indicator to the chart. After the first real time bar close, the new>Ninjascript output window, on Output 1 tab showed the prints.

    I think it is important that you be able to replicate this. Please delete the indicator TestForStan and use Tools>ImportNinjascript add-on.. and import the zipped folder. Create the same chart and test again.

    Leave a comment:


  • Stanfillirenfro
    replied
    Thanks Paul for your reply.

    Yes, I have applied the indicator t a chart cinnnected to real tiime data.
    Yes, the output window was observed after a bar has closed on the chart.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    Something is not correct here. The example I provided in the zipped file will print the bar times.

    Did you apply the indicator to a chart that is connected to real time (or playback) data?

    Did you observe the output window after a bar has closed on the chart?

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by rocketman7, Today, 02:12 AM
4 responses
21 views
0 likes
Last Post q0t6p5
by q0t6p5
 
Started by trilliantrader, 04-18-2024, 08:16 AM
7 responses
27 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by samish18, 04-17-2024, 08:57 AM
17 responses
65 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by briansaul, Today, 05:31 AM
1 response
13 views
0 likes
Last Post NinjaTrader_Jesse  
Started by PaulMohn, Today, 03:49 AM
1 response
12 views
0 likes
Last Post NinjaTrader_BrandonH  
Working...
X