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

NS equivalent to "IndicatorCounted()" ?

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

    NS equivalent to "IndicatorCounted()" ?

    I'm trying to convert some indicators from MetaTrader (MQL4) to NinjaScript but there are a few functions I'm unsure of...

    In MQL there is a function called IndicatorCounted(), which is described as follows:

    int IndicatorCounted( )The function returns the amount of bars not changed after the indicator had been launched last. The most calculated bars do not need any recalculation. In most cases, same count of index values do not need for recalculation. The function is used to optimize calculating.

    Note: The latest bar is not considered to be calculated and, in the most cases, it is necessary to recalculate only this bar. However, there occur some boundary cases where custom indicator is called from the expert at the first tick of the new bar. It is possible that the last tick of the previous bar had not been processed (because the last-but-one tick was being processed when this last tick came), the custom indicator was not called and it was not calculated because of this. To avoid indicator calculation errors in such situations, the IndicatorCounted() function returns the count of bars minus one. Sample:
    int start()
    {
    int limit;
    int counted_bars=IndicatorCounted();
    //---- check for possible errors
    if(counted_bars<0) return(-1);
    //---- the last counted bar will be recounted
    if(counted_bars>0) counted_bars--;
    limit=Bars-counted_bars;
    //---- main loop
    It seems to be being used in the same way as CurrentBar in NS, but there is already a function called 'Bars' that does that and they are both being used. What should I replace it with?

    There's also a constant called "EMPTY_VALUE" (different from NULL) being used which is described as:

    Value: 0x7FFFFFFF
    Description: Default custom indicator empty value.
    Example
    if (trend[shift+ColorBarBack]<0) UpTrend[shift+ColorBarBack]=Filter[shift+ColorBarBack];
    DnTrend[i] = EMPTY_VALUE;
    And I'm not sure what to use for that either.
    Any help would be appreciated.

    Last edited by Elliott Wave; 06-23-2008, 01:22 AM.

    #2
    Unfortunately we are no MT experts but I would think that there is no equivalent.

    Comment


      #3
      Ok thanks, unfortunately I'm neither a NinjaScript nor an MQL expert.

      But from what I understand MQL is VERY close to C++ and therefore its not too difficult to port it to C#.

      The IndicatorCounted() function seems to be used in almost every indicator so hopefully someone with experience converting indicators will be able to chime in. In the meantime I'll keep working at it.

      Comment


        #4
        I believe IndicatorCounted() in MT is the same as CurrentBar in NT.

        Normally you see something like this in MQL

        int start()
        {
        int limit;
        int counted_bars=IndicatorCounted();
        //---- check for possible errors
        if(counted_bars<0) return(-1);
        //---- last counted bar will be recounted
        if(counted_bars>0) counted_bars--;
        limit=Bars-counted_bars;
        //---- main loop
        for(int i=0; i<limit; i++)
        {
        //some logic from current bar to limit (first bar on chart).
        }

        Bars is the number of bars on the chart (should be the same as CurrentBar).

        I haven't tried to convert any MQL indicators yet so I can't be of too much assistance.

        I have a reference MQL pdf document that describes all of the MQL functions but its too large to attach. If you want me to send it please PM me or respond with an address.

        Anthony
        mrlogik
        NinjaTrader Ecosystem Vendor - Purelogik Trading

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        4 responses
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Brevo, Today, 01:45 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by rjbtrade1, 11-30-2023, 04:38 PM
        2 responses
        74 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Started by suroot, 04-10-2017, 02:18 AM
        5 responses
        3,021 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Stanfillirenfro, Today, 07:23 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X