Class4_AUDUSD_buy
Download scriptThis script is designed to systematically generate and log specific combinations of trading signals across five different currency pairs: EURUSD, EURCHF, EURJPY, GBPUSD, and AUDUSD. Instead of executing trades directly, the program acts as a data generator that maps out balanced "Buy" and "Sell" scenarios to create a structured log file.
Core Logic Overview
The script operates by running through a multi-dimensional nested loop. It systematically evaluates every possible numerical combination for five different variables (representing our five currency pairs). For each iteration, it assigns a "Buy" point or a "Sell" point based on the value of the current step:
- A value of 0 is categorized as a Buy signal.
- A value of 1 is categorized as a Sell signal.
Filtering and Selection Criteria
Not every combination generated by the loops is recorded. The script applies a specific set of "balanced" filters to decide which combinations are relevant enough to be saved. It only logs the data if the following conditions are met simultaneously:
- Balance Requirement: The total number of Buy signals and Sell signals in a combination must be nearly equal. Specifically, it looks for instances where the counts are perfectly balanced, or differ by only one (e.g., 3 Buys vs 2 Sells).
- Activity Check: The combination must contain at least one Buy signal and at least one Sell signal to ensure it is not a "one-sided" result.
- Specific Target: The script specifically filters for combinations where the fifth currency pair (AUDUSD) is active in the sequence.
Output and Logging
When a combination meets all the criteria above, the script compiles a descriptive string. This string includes:
- The total count of Buy signals vs. Sell signals.
- The raw numerical code of the combination.
- A readable summary showing which currency pairs are associated with which signal type.
Finally, the script handles the "Data Export" by creating a dedicated text file (CSV format). It automatically opens this file, navigates to the end of the existing content, and appends the new valid combinations. This allows you to review a pre-calculated list of balanced trading configurations without having to manually calculate them.
//+------------------------------------------------------------------+
//| 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_AUDUSD_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(m==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