swapping
Download scriptThis script is designed to work as a background utility within the MetaTrader platform. Its primary purpose is to automatically scan and gather specific data points from multiple open charts simultaneously.
How it works
The tool operates on a scheduled heartbeat, refreshing its internal data every 60 seconds. Rather than reacting to every tiny price movement (ticks), it performs a systematic check at regular intervals to ensure the information being gathered is current.
Key Functionalities
- Multi-Chart Scanning: The script is capable of "looking" across your workspace. It identifies open charts and iterates through them one by one, up to a limit of 100 different windows.
- Automated Price Retrieval: For every chart it encounters during its scan, the script automatically retrieves the closing prices from a predefined set of timeframes. This includes various intervals such as 1-minute, 5-minute, 15-minute, 30-minute, 1-hour, 4-hour, daily, and several longer-term periods (up to several days in length).
- Background Execution: Because the script runs on a timer rather than just reacting to price changes, it remains active in the background. It continuously cycles through your open assets to capture these snapshot prices without requiring manual intervention from the user.
In short, this tool acts as a data collector that periodically sweeps through all your active trading windows to identify and record closing prices across a wide variety of timeframes instantly.
//+------------------------------------------------------------------+
//| Swapping |
//| https://www.mql5.com/ru/users/Sommersy/seller |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnInit()
{
EventSetTimer(60);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
EventKillTimer();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTimer()
{
double f;
long id=ChartFirst();
int i=0;
while(i<100)
{
f=iClose(ChartSymbol(id),1,0);
f=iClose(ChartSymbol(id),5,0);
f=iClose(ChartSymbol(id),15,0);
f=iClose(ChartSymbol(id),30,0);
f=iClose(ChartSymbol(id),60,0);
f=iClose(ChartSymbol(id),240,0);
f=iClose(ChartSymbol(id),1440,0);
f=iClose(ChartSymbol(id),10080,0);
f=iClose(ChartSymbol(id),43200,0);
id=ChartNext(id);
if(id<0){break;}
i++;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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[])
{
return(rates_total);
}
//+------------------------------------------------------------------+
Comments