How to compare dates?

llaabbss
79
llaabbss  

Hi,

I'd like to use limitation of styding the candles in history. For this reason I'm going to have two inputs:

input datetime start_date = D'2020.10.26';
input datetime end_date = D'2020.12.31';

But I do not know how to make a comparison between the current date of each bar in a for loop and input values.

input datetime start_date = D'2020.10.26';
input datetime end_date = D'2020.12.31';

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{

        int limit = rates_total - prev_calculated;

        if (prev_calculated > 0) limit++;
        
        for (int i = limit - 2; i >= 0; i--){

                // How to compare two dates here?
                // ...

        }

}

Could someone please help me with this?

William Roeder
24208
William Roeder  
  1. llaabbss: But I do not know how to make a comparison between the current date of each bar in a for loop and input values.

    Perhaps you should read the manual.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    bool isValidDate = start_date <= time[i] && time[i] <= end_date;


  2.         int limit = rates_total - prev_calculated;
    
            if (prev_calculated > 0) limit++;
            
            for (int i = limit - 2; i >= 0; i--){

    Assuming you return rates_total, your loop will do nothing after the first run.
              How to do your lookbacks correctly #9 - #14 & #19

llaabbss
79
llaabbss  
William Roeder:
  1. Perhaps you should read the manual.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.


  2. Assuming you return rates_total, your loop will do nothing after the first run.
              How to do your lookbacks correctly #9 - #14 & #19

Dear William,

Thanks a lot for your help.