//+------------------------------------------------------------------+ //| ExportBars.mq5 | //| Astralys LLC | //| | //| Exports the full bar history of the chart it is dropped on to a | //| CSV in MQL5\Files. One purpose: feed the article figures (equity | //| curve of the selected pass, and the period x threshold heat maps) | //| which are drawn outside the terminal from this data. | //| | //| Drop it on US500 D1. Output: PBO_bars__.csv | //+------------------------------------------------------------------+ #property copyright "Astralys LLC" #property link "https://pulsar-terminal.com" #property version "1.00" #property script_show_inputs input int InpMaxBars = 0; // 0 = everything the broker provides void OnStart(void) { MqlRates rates[]; ArraySetAsSeries(rates, false); // index 0 = oldest const int want = (InpMaxBars <= 0) ? Bars(_Symbol, _Period) : InpMaxBars; const int got = CopyRates(_Symbol, _Period, 0, want, rates); if(got <= 0) { Print("ExportBars: CopyRates failed, error ", GetLastError()); return; } const string name = StringFormat("PBO_bars_%s_%s.csv", _Symbol, EnumToString(_Period)); const int h = FileOpen(name, FILE_WRITE | FILE_CSV | FILE_ANSI, ','); if(h == INVALID_HANDLE) { Print("ExportBars: cannot open ", name, ", error ", GetLastError()); return; } FileWrite(h, "time", "open", "high", "low", "close"); for(int i = 0; i < got; i++) FileWrite(h, TimeToString(rates[i].time, TIME_DATE), DoubleToString(rates[i].open, _Digits), DoubleToString(rates[i].high, _Digits), DoubleToString(rates[i].low, _Digits), DoubleToString(rates[i].close, _Digits)); FileClose(h); PrintFormat("ExportBars: %d bars written to MQL5\\Files\\%s (%s to %s)", got, name, TimeToString(rates[0].time, TIME_DATE), TimeToString(rates[got - 1].time, TIME_DATE)); } //+------------------------------------------------------------------+