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 your help.
    I have compiled the code/indicator you posted in #8.went to the platform and attached it. After opening the output, the window ffliped very fast between white and came back to it setting color. Nothing was printed unfortunatly.

    Following up my code, could you please have a look on the lines 80 and 82? Is the line 82 enough to get the time of a given bar?

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    It looks like you incorporated my example incorrectly into your existing code.

    I've attached a complete example you can test with. Please note that to use it you must be connected to realtime (or playback) data and wait until the first live bar closes before you will see an output.

    TestForStan.zip

    As far as your code, I would suggest debugging with print statements to find out where your code is not working as you expect it to.

    Leave a comment:


  • Stanfillirenfro
    replied
    Many thanks Paul!
    I have attached the code.
    Attached Files

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    The code in Post#4 should only be inside OnBarUpdate.

    You would have to be connected to real time data.

    If that does not resolve the question, please attach your code file.

    Leave a comment:


  • Stanfillirenfro
    replied
    Many thanks Paul for your reply.

    Regarding the output,
    I have placed the code you gave me just above protected override void OnBarUpdate() and compiled. Nothing appeared on the output.
    I brought it in protected override void OnBarUpdate() and after compilation, still nothing. Either the emplacement is wrong or my code is wrong. Right?
    I am checking other issues.

    Thanks in advance.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your reply.

    If you mean how many bars are in the data series, you could use Bars.Count.

    If you mean how many bars are displayed on the chart, you would have to work in OnRender() to determine that using these properties:



    CurrentBar is used when there is no additional data series. If you have added a data series then you would need to use CurrentBars[] where [] would specify the bars array \(added data series) to use.
    Reference:



    To get a print of the bar times, try this:

    if (State == State.Historical) // waits until real time data!
    return;

    for (int i = CurrentBar; i > 0; i--)
    {
    Print (ToTime(Time[CurrentBar-i]));
    }

    Leave a comment:


  • Stanfillirenfro
    replied
    Many tanks Paul for your valable reply.
    OK which function should return the total number of the bars? I though I could use "CurrentBars" (with 's"), but what is the didéférence with CurrentBar (without s)?
    ​​​I also though I could us Bars.getBars(), but I muss give as argument a defined time. In my case I am in a loop and I do not want to restrict thé code to this time.
    I also failed to get anything printed on output. I do not know how to fix this problem. The window is displayed wothout anything printed on it.
    I would appreciate any help.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello Stanfillirenfro,

    Thanks for your post.

    CurrentBar is the systems bar number that is being processed. When your script is loaded the first bar which is zero-based, would be 0, the next bar loaded would 1, then 2, etc, etc. Eventually, as all of the historical bars are processed CurrentBar would point to either the just completed bar or the currently forming bar (this is based on which Calculate setting the script is running in and if the chart is connected to real time data).

    The ToTime() method will return an integer value representing time.

    You may want to add a Print statement inside your for loop to help see what values are being returned.

    Print (ToTime(Time[CurrentBar-i]));

    A method you may want to review is Bars.GetBar(): https://ninjatrader.com/support/help...t8/?getbar.htm

    Leave a comment:


  • Stanfillirenfro
    started a topic Search for a bar by its time

    Search for a bar by its time

    Hello!


    I am looking at a bar by its time. So I go through a loop as followed:

    int timme = 0;

    for (int i = CurrentBar; i > 0; i--)
    {
    time = ToTime(Time[CurrentBar-i]);
    }

    I assume that CurrentBar represents the total number of the bars on the chart.
    I am failling to get the time of a given bar at the time "i". What am I making wrong?

    Best regrads.

Latest Posts

Collapse

Topics Statistics Last Post
Started by GussJ, 03-04-2020, 03:11 PM
11 responses
3,229 views
0 likes
Last Post xiinteractive  
Started by andrewtrades, Today, 04:57 PM
1 response
14 views
0 likes
Last Post NinjaTrader_Manfred  
Started by chbruno, Today, 04:10 PM
0 responses
7 views
0 likes
Last Post chbruno
by chbruno
 
Started by josh18955, 03-25-2023, 11:16 AM
6 responses
441 views
0 likes
Last Post Delerium  
Started by FAQtrader, Today, 03:35 PM
0 responses
12 views
0 likes
Last Post FAQtrader  
Working...
X