Initial commit: MQL5 Scripts Collection (MetaTrader 5)
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
@@ -0,0 +1,22 @@
|
||||
# 🚀 Unlock the Power of Trading!
|
||||
|
||||
Welcome to this open-source trading project. Here you will find powerful tools to enhance your trading journey. If you find this project useful, please consider starring ⭐, sharing, or donating to support further development!
|
||||
|
||||
---
|
||||
|
||||
**Support the project:**
|
||||
- Star this repository on GitHub
|
||||
- Share it with your trading friends
|
||||
- [Donate here](https://www.paypal.com/donate/?hosted_button_id=YOUR_BUTTON_ID) to help us grow!
|
||||
|
||||
---
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Source Files
|
||||
- `savehistorytohst.mq5`
|
||||
|
||||
---
|
||||
> Made with ❤️ for the trading community.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,113 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SaveHistoryToHST.mq5 |
|
||||
//| avoitenko |
|
||||
//| https://login.mql5.com/ru/users/avoitenko |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "avoitenko"
|
||||
#property link "https://login.mql5.com/ru/users/avoitenko"
|
||||
#property version "1.00"
|
||||
|
||||
#property script_show_inputs
|
||||
|
||||
#define OFFLINE_HEADER_SIZE 148 // LONG_VALUE + 64 + 12 + 4 * LONG_VALUE + 13 * LONG_VALUE
|
||||
#define OFFLINE_RECORD_SIZE 44 // 5 * DOUBLE_VALUE + LONG_VALUE
|
||||
|
||||
input uint DATA_COUNT=5000;// Ãëóáèíà èñòîðèè â áàðàõ
|
||||
|
||||
MqlRates rates[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| OnStart() |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
//--- ïðîâåðêà ïàðàìåòðà DATA_COUNT
|
||||
if(DATA_COUNT==0)
|
||||
{
|
||||
printf("Îøèáêà, íåâåðíî çàäàí ïàðàìåòð DATA_COUNT (%d), äîïóñòèìûå çíà÷åíèÿ: >0",DATA_COUNT);
|
||||
return;
|
||||
}
|
||||
//--- ïðîâåðêà äîñòóïíûõ äàííûõ
|
||||
uint count=CopyRates(_Symbol,_Period,0,DATA_COUNT,rates);
|
||||
if(count<DATA_COUNT)
|
||||
{
|
||||
printf("Íåäîñòàòî÷íî äàííûõ â èñòîðèè (%d), íåîáõîäèìî %d áàðîâ",count,DATA_COUNT);
|
||||
return;
|
||||
}
|
||||
|
||||
int period=PeriodSeconds(_Period)/60;
|
||||
|
||||
//--- ñîõðàíåíèå øàïêè HST ôàéëà
|
||||
if(!WriteOfflineHeader("!"+_Symbol,period,_Digits)) return;
|
||||
|
||||
//--- ñîõðàíåíèå äàííûõ HST ôàéëà
|
||||
for(uint i=0;i<DATA_COUNT;i++)
|
||||
{
|
||||
if(!WriteOfflineBar("!"+_Symbol,period,0,rates[i]))return;
|
||||
}
|
||||
//--- âûâîä ïóòè ê ñîõðàíåííîìó ôàéëó
|
||||
Print("Ïóòü ê ñîõðàíåííîìó ôàéëó: ",TerminalInfoString(TERMINAL_DATA_PATH),"MQL5\\Files\\",OfflineFileName("!"+_Symbol,period));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
bool WriteOfflineHeader(string symbol,int period,int digits)
|
||||
//+------------------------------------------------------------------+
|
||||
{
|
||||
int version=400;
|
||||
string c_copyright="(C)opyright 2011, Andrey Voytenko";
|
||||
int i_unused[13];
|
||||
|
||||
ResetLastError();
|
||||
int F=FileOpen(OfflineFileName(symbol,period),FILE_BIN|FILE_ANSI|FILE_WRITE);
|
||||
if(F==INVALID_HANDLE)
|
||||
{
|
||||
Print(__FUNCTION__," Îïåðàöèÿ FileOpen íåóäà÷íà, îøèáêà ",GetLastError());
|
||||
return(false);
|
||||
}
|
||||
|
||||
FileSeek(F,0,SEEK_SET);
|
||||
FileWriteInteger(F,version,INT_VALUE);
|
||||
FileWriteString(F,c_copyright,64);
|
||||
FileWriteString(F,symbol,12);
|
||||
FileWriteInteger(F,period,INT_VALUE);
|
||||
FileWriteInteger(F,digits,INT_VALUE);
|
||||
FileWriteInteger(F,(int)TimeCurrent(),INT_VALUE); // timesign
|
||||
FileWriteInteger(F,(int)TimeCurrent(),INT_VALUE); // last_sync
|
||||
FileWriteArray(F,i_unused,0,13);
|
||||
|
||||
FileClose(F);
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
bool WriteOfflineBar(string symbol,int period,int bars_back,MqlRates &data)
|
||||
//+------------------------------------------------------------------+
|
||||
{
|
||||
ResetLastError();
|
||||
int F=FileOpen(OfflineFileName(symbol,period),FILE_BIN|FILE_ANSI|FILE_READ|FILE_WRITE);
|
||||
if(F==INVALID_HANDLE)
|
||||
{
|
||||
Print(__FUNCTION__," Îïåðàöèÿ FileOpen íåóäà÷íà, îøèáêà ",GetLastError());
|
||||
return(false);
|
||||
}
|
||||
|
||||
int position=bars_back*OFFLINE_RECORD_SIZE;
|
||||
FileSeek(F,-position,SEEK_END);
|
||||
|
||||
if(FileTell(F)>=OFFLINE_HEADER_SIZE)
|
||||
{
|
||||
FileWriteInteger(F,(int)data.time,INT_VALUE);
|
||||
FileWriteDouble(F, data.open);
|
||||
FileWriteDouble(F, data.low);
|
||||
FileWriteDouble(F, data.high);
|
||||
FileWriteDouble(F, data.close);
|
||||
FileWriteDouble(F, data.tick_volume);
|
||||
}
|
||||
|
||||
FileClose(F);
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
string OfflineFileName(string symbol,int period)
|
||||
//+------------------------------------------------------------------+
|
||||
{
|
||||
return(StringSubstr(symbol,0,12)+IntegerToString(period)+".hst");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Reference in New Issue
Block a user