Class4_EURUSD_buy
Download scriptThis script functions as an automated data generator designed to map out various combinations of trading signals across five different currency pairs. Instead of executing live trades, the script performs a systematic calculation to identify balanced scenarios between "Buy" and "Sell" actions and records these results into a structured log file.
Core Logic Overview
The script operates by exploring every possible combination of binary states (represented as 0 or 1) across five specific currency pairs: EURUSD, EURCHF, EURJPY, GBPUSD, and AUDUSD.
For each currency pair in the list, the logic evaluates two primary possibilities:
- State 0: Categorized as a "Buy" signal.
- State 1: Categorized as a "Sell" signal.
How the Process Works
-
Exhaustive Permutation Scanning: The program uses a nested series of loops to iterate through every possible mathematical combination for the five currencies. Because there are five pairs and two states for each, it evaluates a vast array of potential market configurations simultaneously.
-
Signal Counting and Filtering: As the script runs through these combinations, it keeps a running tally of how many "Buy" signals and how many "Sell" signals exist within a specific set. It then applies a set of strict criteria to determine which combinations are worth recording:
- The combination must contain at least one Buy signal and at least one Sell signal (it ignores completely one-sided scenarios).
- The ratio between Buys and Sells must be nearly equal (specifically, the counts must be equal, or differ by only one). This ensures the script only captures "balanced" market states.
-
Data Recording: Whenever a combination meets the balance criteria, the script generates a unique identification code and a descriptive string. This string includes the total count of buys/sells, the specific numerical state for each currency pair, and the corresponding currency names.
-
Output Generation: The final results are automatically saved to an external CSV file named
Class4_EURUSD_buy.txt. This allows for a permanent record of all balanced configurations that can be reviewed outside of the trading platform.
Summary of Purpose
Essentially, this script acts as a configuration scanner. It mathematically identifies every possible way to balance "Buy" and "Sell" positions across five major currency pairs and writes those specific blueprints into a file for later analysis or use in other workflows.
//+------------------------------------------------------------------+
//| 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="Class4_EURUSD_buy.txt";
string s1="";
string cod1="";
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++;
cod1=""+i+""+j+""+k+""+l+""+m;
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))
if((nrbuy!=0))
if((nrsell!=0))
if(i==0)
Write2(fn1,s1);
s1="";
cod1="";
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