0

I would like to get the optimization period (when use data is checked)

At first I tried like this.

datetime dtFrom;
datetime dtTo;
void OnInit(){
  dtFrom = Time[0]; //from date
}
double OnTester(){
  dtTo = Time[0]; // to date
}

However, it has problem, even if I set 2005/01/01 - 2005/01/29 by strategy tester UI dropbox.

dtFrom will be 2005/01/09, dtTo will be 2005/01/28 in Script.

Because, 01-08 is holiday and 29 is saturday, so there is no data calculation.

And also if it has shortage of budget, run stops and dtTo is the date when shortage happens.

Is there simple good way to get the date that User set in strategy tester box??

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

1

Is there simple good way to get the date that User set in strategy tester box??

Yes, there is, but not pulling data from GUI-form field(s):

MetaTrader Terminal's "flow-of-time" has other mechanics ( in StrategyTester the more complex if [x] optimisation is on ). The platform simply emulates the time and the only "internally visible" date-times are those carried by the emulated QUOTE-stream.

While there were some complex tricks to inject start/end limits for sliding window testing and similar use-cases via parameters, still the OnTester(){...} will never "see" into the GUI-form fields.

This "internal" datetime-self-sniffer works great:

datetime aGloballyAccessibleSessionFirstVisibleDATETIME,
         aGloballyAccessibleSessionLast_VisibleDATETIME;

int OnTick(){

static bool is1stQUOTE = True;
       if ( is1stQUOTE ){                                             // .TEST
            is1stQUOTE = False;                                       // .LOCK
            aGloballyAccessibleSessionFirstVisibleDATETIME = Time[0]; // .SET
       }
       /**/ aGloballyAccessibleSessionLast_VisibleDATETIME = Time[0]; // .UPD

       ...

}

double OnTester() {
       ...
       Print( "First QUOTE was on (",
               aGloballyAccessibleSessionFirstVisibleDATETIME,
              ")",
              "Last QUOTE was on (",
               aGloballyAccessibleSessionLast_VisibleDATETIME
              ")"
               );
}
user3666197
  • 1
  • 6
  • 50
  • 92