This script is designed as a statistical research tool for traders who want to analyze historical market behavior over a specific timeframe. Rather than automatically executing trades, it performs a deep "look-back" analysis of price action to calculate the probabilities of various market patterns and price movements.
Core Functionality
The logic operates by scanning a defined number of past candles (based on a user-specified timeframe) and performing three main types of data extraction:
1. Candle Classification and Frequency The script categorizes every candle in the selected period into three types:
- Bullish: Prices closed higher than they opened.
- Bearish: Prices closed lower than they opened.
- Doji: Prices where the opening and closing values are virtually identical.
It then calculates the percentage of occurrence for each type, helping a trader understand the "personality" of the current market (e.g., whether it is currently trending strongly in one direction or oscillating).
2. Pattern Recognition and Probability The script looks for specific sequences between two consecutive candles to identify transitions. It specifically tracks:
- Consecutive Patterns: How often you see two bearish candles in a row, two bullish candles in a row, or two Dojis side-by-side.
- Color Transitions: It identifies "color changes" (e.g., moving from a bearish candle to a bullish one) and measures the "shadows" (the distance between the candle body and its highest/lowest point).
- Success Probability: One of the most unique features is that it attempts to calculate the probability of reaching a specific profit target (Take Profit) following these color changes. It checks if the candle's shadows are large enough to cover both the desired profit goal and the current market spread.
3. Structural Averages To provide a complete mathematical picture of the volatility, the script calculates several averages across the entire period:
- The average length of the candle bodies.
- The average distance between the absolute high and low points (total range).
- The average size of the upper shadows vs. lower shadows.
Summary of Output
Once the analysis is complete, the script provides a comprehensive report through a series of alerts. This report gives the user a "cheat sheet" of the market's statistics, including:
- The probability of specific candle combinations appearing.
- The frequency of Dojis versus directional candles.
- The calculated percentage chance of hitting a profit target during price reversals.
- Detailed average measurements of volatility and shadow lengths.
In short, this is a data-mining tool used to determine the mathematical likelihood of certain market behaviors occurring before a trader decides to enter a position.
//+------------------------------------------------------------------+
//| DailyResearch.mq4 |
//| Copyright © 2007, DRKNN |
//| drknn@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, DRKNN"
#property link "drknn@mail.ru"
#property show_inputs
extern int TakeProfit=10;
extern int TaimFame=1440;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start(){
string SMB;
double SPR;
int Bar=iBars(SMB,TaimFame);
double Dlina=0,Dodzh=0,Bych=0,Medv=0,MezhduTenjami=0;
double TenUp=0,TenDown=0;
double Up=0,Down=0;
double O,C,H,L,O1,C1,H1,L1;
double TwooBych=0,TwooMedw=0,TwooDodzh=0;
double Nesovpadenie=0;
double Profit=0;
// ---- Ïîäãîòîâêà äàííûõ -----------
SMB=Symbol();
SPR=MarketInfo(SMB,MODE_SPREAD);
for(int i=Bar;i>0;i--){
O=iOpen(SMB,TaimFame,i);
C=iClose(SMB,TaimFame,i);
H=iHigh(SMB,TaimFame,i);
L=iLow(SMB,TaimFame,i);
//------ âñòðå÷è ñâå÷ îäíîãî öâåòà --------
if(i<Bar){
O1=iOpen(SMB,TaimFame,i+1);
C1=iClose(SMB,TaimFame,i+1);
H1=iHigh(SMB,TaimFame,i+1);
L1=iLow(SMB,TaimFame,i+1);
if((O1-C1)>0 && (O-C)>0){// äâå ìåäâåæüèõ âïîäðÿä
TwooMedw++;
}
if((C1-O1)>0 && (C-O)>0){// äâå áû÷üèõ âïîäðÿä
TwooBych++;
}
if((C1==O1)&&(C==O)){ // äâà äîäæà âïîäðÿä
TwooDodzh++;
}
if (
((O1-C1)>0 && (O-C)<0) || ((C1-O1)>0 && (C-O)<0) || ((C1==O1)&&(C<O)) || ((C1==O1)&&(C>O)) || ((C1<O1)&&(C==O))
|| ((C1>O1)&&(C==O))
){//íåñîâïàäåíèå öâåòà äâóõ ñîñåäíèõ ñâå÷
Nesovpadenie++;
if((O1-C1)>0 && (O-C)<0){ // Êîìáèíàöèÿ "÷åðíàÿ-áåëàÿ"
if((O-L)>=(TakeProfit+SPR)*Point){//áåð¸ì íèæíþþ òåíü, òàê êàê îòêðûâàåì øîðò
Profit++;
}
}
if((O1-C1)<0 && (O-C)>0){// Êîìáèíàöèÿ "áåëàÿ-÷¸ðíàÿ"
if((H-O)>=(TakeProfit+SPR)*Point){// èçìåðÿåì âåðõíþþ òåíü, òàê êàê îòêðûâàåì ëîíã
Profit++;
}
}
if((O1-C1)>0 && O==C){ // Êîìáèíàöèÿ "÷åðíàÿ-äîäæ"
if((O-L)>=(TakeProfit+SPR)*Point){//áåð¸ì íèæíþþ òåíü, òàê êàê îòêðûâàåì øîðò
Profit++;
}
}
if((O1-C1)<0 && O==C){// Êîìáèíàöèÿ "áåëàÿ-Äîäæ"
if((H-O)>=(10+SPR)*Point){// èçìåðÿåì âåðõíþþ òåíü, òàê êàê îòêðûâàåì ëîíã
Profit++;
}
}
}
}
//----- òåëà ñâå÷ ---------
if(O>C){
Dlina=Dlina+(O-C)/Point;
Medv++;
TenUp=TenUp+(H-O)/Point;
Up++;
TenDown=TenDown+(C-L)/Point;
Down++;
}
if(O<C){
Dlina=Dlina+(C-O)/Point;
Bych++;
TenUp=TenUp+(H-C)/Point;
Up++;
TenDown=TenDown+(O-L)/Point;
Down++;
}
if(O==C){
Dodzh++;
TenUp=TenUp+(H-C)/Point;
Up++;
TenDown=TenDown+(O-L)/Point;
Down++;
}
// ------ òåíè ñâå÷ -------
MezhduTenjami=MezhduTenjami+(H-L)/Point;
}
// --------- Ìàíèïóëèðîâàíèå äàííûìè ---------
Dlina=Dlina/(Bar);//ñðåäíÿÿ äëèíà ñâå÷è
MezhduTenjami=MezhduTenjami/(Bar);//ñðåäíåå ðàññòîÿíèå ìåæäó õàé è ëîó ñâå÷è
TenUp=TenUp/Up;
TenDown=TenDown/Down;
Alert("Äàííûì àíàëèçîì ïðîèãíîðèðîâàíà ïîñòàíîâêà ñòîï-ëîññà!!!!!");
Alert("Åñëè ïðåäûäóùàÿ ñâå÷à - Äîäæ, òî íå òîðãóåì!");
Alert("Ïðè íåñîâïàäåíèè öâåòà âåðîÿòíîñòü âçÿòèÿ ",TakeProfit," pt ïðîôèòà = ",Profit/Nesovpadenie*100," % (ñ ó÷¸òîì ñïðåäà)");
Alert("Íåñîâïàäåíèå öâåòà äâóõ ñîñåäíèõ ñâå÷ âûïàëî ",Nesovpadenie," ðàç. Âåðîÿòíîñòü ïîÿâëåíèÿ = ",Nesovpadenie/Bar*100," %");
Alert("Êîìáèíàöèÿ *Äâà Äîäæà* âûïàëà ",TwooDodzh," ðàç. Âåðîÿòíîñòü ïîÿâëåíèÿ = ",TwooDodzh/Bar*100," %");
Alert("Êîìáèíàöèÿ *Äâå ìåäâåæüè* âûïàëà ",TwooMedw," ðàç. Âåðîÿòíîñòü ïîÿâëåíèÿ = ",TwooMedw/Bar*100," %");
Alert("Êîìáèíàöèÿ *Äâå áû÷üè* âûïàëà ",TwooBych," ðàç. Âåðîÿòíîñòü ïîÿâëåíèÿ = ",TwooBych/Bar*100," %");
Alert("Ñðåäíÿÿ íèæíÿÿ òåíü = ",TenDown," pt");
Alert("Ñðåäíÿÿ âåðõíÿÿ òåíü = ",TenUp," pt");
Alert("Ñðåäíåå ðàññòîÿíèå ìåæäó xàé è ëîó ñâå÷è = ",MezhduTenjami," pt");
Alert("Ñðåäíÿÿ äëèíà òåëà ñâå÷è = ",Dlina," pt");
Alert("Äîäæåé = ",Dodzh,". Âåðîÿòíîñòü ïîÿâëåíèÿ = ",Dodzh/Bar*100," %");
Alert("Ìåäâåæüèõ ñâå÷ = ",Medv,". Âåðîÿòíîñòü ïîÿâëåíèÿ = ",Medv/Bar*100," %");
Alert("Áû÷üèõ ñâå÷ = ",Bych,". Âåðîÿòíîñòü ïîÿâëåíèÿ = ",Bych/Bar*100," %");
Alert("Íà èíòåðâàëå ",TaimFame," ìèíóò ïðîàíàëèçèðîâàíî ",Bar," ñâå÷. Èç íèõ :");
Alert("============ ",SMB," ============");
return(0);
}
//+------------------------------------------------------------------+
Comments