This script is designed to perform a systematic data analysis of currency pairs by calculating potential "Buy" and "Sell" combinations across multiple markets simultaneously. Instead of looking at real-time price movements, the logic focuses on creating an exhaustive mathematical map of possible trade balances.
Core Functionality
The program systematically evaluates five specific currency pairs: EURUSD, EURCHF, EURJPY, GBPUSD, and AUDUSD. It uses a multi-layered nested loop to iterate through every possible combination of these assets. For each iteration, it assigns a numerical value to represent "Buy" or "Sell" statuses across all five pairs.
The Logic Flow
- Combination Generation: The script cycles through every mathematical possibility for the five currencies. It treats each currency as a variable that can be categorized into two states.
- Balance Calculation: As it moves through these combinations, it keeps a running tally of how many "Buy" positions are active versus "Sell" positions.
- Filtering Criteria: Not every combination is saved. The script specifically looks for "balanced" scenarios. It only identifies and records combinations where:
- The number of Buys exactly equals the number of Sells.
- There is a difference of only one between the number of Buys and Sells (e.g., 3 Buys and 2 Sells, or 2 Buys and 3 Sells).
- Data Logging: Every time the script finds a combination that meets these specific balance requirements, it formats the data into a text string. This string includes the total count of buys and sells, the specific sequence of the combination, and the corresponding currency names.
Output
The final result is an organized log file saved to your local directory. This file serves as a comprehensive reference list of all mathematically viable "balanced" trade configurations across the five selected currency pairs. It essentially maps out every way you could theoretically hold these positions while keeping your overall market exposure nearly neutral.
//+------------------------------------------------------------------+
//| Class1.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
string fn1="Class3";
string s1="";
int max1=3;
int nrbuy=0;
int nrsell=0;
FileDelete(fn1);
for(int i=0;i<max1;i++)
{
for(int j=0;j<max1;j++)
{
for(int k=0;k<max1;k++)
{
for(int l=0;l<max1;l++)
{
for(int m=0;m<max1;m++)
{
if(i==0) nrbuy++;
if(i==1) nrsell++;
if(j==0) nrbuy++;
if(j==1) nrsell++;
if(k==0) nrbuy++;
if(k==1) nrsell++;
if(l==0) nrbuy++;
if(l==1) nrsell++;
if(m==0) nrbuy++;
if(m==1) nrsell++;
s1=""+nrbuy+" "+nrsell+" "+i+""+j+""+k+""+l+""+m+" "+i+"-EURUSD "+j+"-EURCHF "+k+"-EURJPY "+l+"-GBPUSD "+m+"-AUDUSD";
if((nrbuy==nrsell) || (nrbuy-1==nrsell) || (nrbuy==nrsell-1) )
Write2(fn1,s1);
s1="";
nrbuy=0;
nrsell=0;
}
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
int Write2(string filename,string str)
{
//Write log file
int handle;
handle = FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV,"/t");
FileSeek(handle, 0, SEEK_END);
//FileWrite(handle,"" + TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS) + ": " + str);
FileWrite(handle,str);
FileClose(handle);
//Print(str);
}
Comments