//+------------------------------------------------------------------+ //| eNstrdms //+------------------------------------------------------------------+ //| исследователь паттернов //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ #property copyright "© valenok2003@mail.ru" //----------------- #define NAME_EXPERT "eNstrdms" #define RELIZE "20120606" //----------------- #define MAXBARS 5 //----------------- //----------------- int PreviosTime = 0; double Cnt[100]; double TopBar[100]; double BootBar[100]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- PreviosTime = 0; Cnt[100] = {0,,0}; TopBar[100] = {0,,0}; BootBar[100] = {0,,0}; //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- Comment(""); ObjectDelete("High"); ObjectDelete("Low"); ObjectDelete("Info"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- if(Time[0] == PreviosTime) return(0); PreviosTime = Time[0]; for(int i=0;i<100;i++){ Cnt[i] = 0; TopBar[i] = 0; BootBar[i] = 0; } bool FLAGSTOP = false; // начинаем проверку начиная из-за иследуемого паттерна и не доводим до конца на паттерн for(int BarsInPattern=MAXBARS; BarsInPattern>0; BarsInPattern--){ for(int Deviation = 0; Deviation < 100; Deviation++) { for(int StartBar = BarsInPattern+1; StartBar < Bars-BarsInPattern-1; StartBar++){ // проверка паттерна на совпадение if(check_pattern(StartBar, BarsInPattern, Deviation)){ Cnt[Deviation] = Cnt[Deviation]+1; TopBar[Deviation] = TopBar[Deviation] + (High[StartBar-1] - Open[StartBar-1]); BootBar[Deviation] = BootBar[Deviation] + (Open[StartBar-1] - Low[StartBar-1]); } } //Print(Deviation+" -> "+DoubleToStr(Cnt[Deviation],0)); if(Cnt[Deviation]>0){ TopBar[Deviation] = TopBar[Deviation]/Cnt[Deviation]; BootBar[Deviation] = BootBar[Deviation]/Cnt[Deviation]; FLAGSTOP = true; break; } } if(FLAGSTOP) break; } if(Cnt[Deviation] != 0) { double Top = Open[0] + TopBar[Deviation]; double Boot = Open[0] - BootBar[Deviation]; drow_line("High",Top, Yellow); drow_line("Low", Boot, Yellow); double Probability = (Cnt[Deviation]*BarsInPattern*100)/(100+Deviation*3); //-------------- ObjectDelete ("Info"); ObjectCreate ("Info", OBJ_LABEL, 0, 0, 0); ObjectSet ("Info", OBJPROP_CORNER, 2); ObjectSet ("Info", OBJPROP_XDISTANCE, 5); ObjectSet ("Info", OBJPROP_YDISTANCE, 5); ObjectSetText("Info", "Вероятность "+DoubleToStr(Probability,2)+"%", 10, "Arial", Yellow); //-------------- Comment( "Паттерн "+DoubleToStr(BarsInPattern,0)+ " бар" + "\nДопуск "+DoubleToStr(Deviation,0)+ "% на бар" + "\nСовпадений "+DoubleToStr(Cnt[Deviation],0) ); } else { ObjectDelete ("Info"); ObjectCreate ("Info", OBJ_LABEL, 0, 0, 0); ObjectSet ("Info", OBJPROP_CORNER, 2); ObjectSet ("Info", OBJPROP_XDISTANCE, 5); ObjectSet ("Info", OBJPROP_YDISTANCE, 5); ObjectSetText("Info", "Аналогов не обнаружено", 10, "Arial", Yellow); } //---- return(0); } //+------------------------------------------------------------------+ //+------- //+------- //+------------------------------------------------------------------+ //| valenok2003@mail.ru 26.04.2012 //+------------------------------------------------------------------+ //| check_pattern() //| проверка текущего паттерна на совпадение с паттерном от заданного бара //| возвращает true в случае совпадения //+------------------------------------------------------------------+ bool check_pattern(int _StartBar, int _BarInPattern, int _Deviation) { string _Function = "check_pattern():"; //----------------- bool RET = true; for(int i=0; i<_BarInPattern; i++){ if(!check_bar(_StartBar, i, _Deviation)){ RET = false; } } //----------------- return(RET); } //+------------------------------------------------------------------+ //+------- //+------- //+------------------------------------------------------------------+ //| valenok2003@mail.ru 26.04.2012 //+------------------------------------------------------------------+ //| check_bar() //| проверка текущего бара на совпадение с заданным баром //| возвращает true в случае совпадения //+------------------------------------------------------------------+ bool check_bar(int _StartBar, int _Shift, int _Deviation) { string _Function = "check_bar():"; //----------------- bool RET = true; int _CurBar = _StartBar+_Shift+1; //----------------- if(High[_CurBar]-Open[_CurBar-1] > max_limit(High[_Shift+1]-Open[_Shift], _Deviation) || High[_CurBar]-Open[_CurBar-1] < min_limit(High[_Shift+1]-Open[_Shift], _Deviation) ) { RET = false; } if(High[_CurBar]-Close[_CurBar] > max_limit(High[_Shift+1]-Close[_Shift+1], _Deviation) && High[_CurBar]-Close[_CurBar] < min_limit(High[_Shift+1]-Close[_Shift+1], _Deviation) ) { RET = false; } if(High[_CurBar]-Low[_CurBar] > max_limit(High[_Shift+1]-Low[_Shift+1], _Deviation) && High[_CurBar]-Low[_CurBar] < min_limit(High[_Shift+1]-Low[_Shift+1], _Deviation) ) { RET = false; } //----------------- return(RET); } //+------- //+------------------------------------------------------------------+ //| valenok2003@mail.ru 26.04.2012 //+------------------------------------------------------------------+ //| max_limit() //| //+------------------------------------------------------------------+ double max_limit(double _Value, int _Precision){ string _Function = "max_limit():"; //----------------- double _Ret = (_Value*_Precision)/100; _Value = _Value + _Ret; //----------------- return(_Value); } //+------------------------------------------------------------------+ //+------- //+------- //+------------------------------------------------------------------+ //| valenok2003@mail.ru 26.04.2012 //+------------------------------------------------------------------+ //| min_limit() //| //+------------------------------------------------------------------+ double min_limit(double _Value, int _Precision){ string _Function = "min_limit():"; //----------------- double _Ret = (_Value*_Precision)/100; _Value = _Value - _Ret; //----------------- return(_Value); } //+------------------------------------------------------------------+ //+------- //+------- //+------------------------------------------------------------------+ //| valenok2003@mail.ru 26.04.2012 //+------------------------------------------------------------------+ //| drow_line() //| рисует горизонтальную линию //+------------------------------------------------------------------+ void drow_line(string _Name, double _Price, color _Color) { ObjectDelete(_Name); ObjectCreate(_Name,OBJ_HLINE,0,0,_Price); ObjectSet (_Name,OBJPROP_COLOR,_Color); return; } //+------------------------------------------------------------------+ //+-------