Skip to content

Instantly share code, notes, and snippets.

@flameoftheforest
Created December 2, 2022 04:14
Show Gist options
  • Save flameoftheforest/f55296e1249053db01715074f9adb558 to your computer and use it in GitHub Desktop.
Save flameoftheforest/f55296e1249053db01715074f9adb558 to your computer and use it in GitHub Desktop.
save_bars.script.02.mq4
//+------------------------------------------------------------------+
//| save_bars.script.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
int sample_size = 6; // NOTE: exporting 6 bars only.
string filename = "bars.csv"; // NOTE: we are passing this into the DLL
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
// Get the filepath to this script
string ex4_filepath = MQLInfoString(MQL_PROGRAM_PATH);
string ohlcvt = "";
for (int i = sample_size - 1; i >= 0; i--)
{
// Delimit between values with '_'
string str =
DoubleToString(Open[i]) + "_" +
DoubleToString(High[i]) + "_" +
DoubleToString(Low[i]) + "_" +
DoubleToString(Close[i]) + "_" +
IntegerToString(Volume[i]) + "_" +
IntegerToString(Time[i]);
if (ohlcvt == "")
{
ohlcvt = str;
}
else
{
ohlcvt = ohlcvt + " " + str;
}
}
// convert filepath to char-array
uchar ex4_filepath_arr[];
StringToCharArray(ex4_filepath, ex4_filepath_arr);
// convert export filename to char-array
uchar filepath_arr[];
StringToCharArray(filename, filepath_arr);
// convert collected data to char-array
uchar ohlcvt_arr[];
StringToCharArray(ohlcvt, ohlcvt_arr);
// Call a function called 'export_ohlcvt'
export_ohlcvt(ex4_filepath_arr, filepath_arr, ohlcvt_arr);
}
//+------------------------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment