//+------------------------------------------------------------------+ //| Fibo-for-Candle.mq4 | //| Copyright © 2010, Kharko | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Kharko" #property link "" #property indicator_chart_window extern int CheckBar=24, TimeFrame=60; extern bool Trend=true; extern color FiboClr= Blue, // Цвет Фибо-уровней OpenClr= Red; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators ObjectCreate("Fibo "+(string)CheckBar,OBJ_FIBO,0,0,0,0,0); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_LEVELSTYLE,STYLE_DOT); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_LEVELCOLOR,FiboClr); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_FIBOLEVELS,20); ObjectCreate("OpenCandle "+(string)CheckBar,OBJ_HLINE,0,0,0); ObjectSet("OpenCandle "+(string)CheckBar,OBJPROP_COLOR,OpenClr); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("Fibo "+(string)CheckBar); ObjectDelete("OpenCandle "+(string)CheckBar); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- Fibo_(); ObjectSet("OpenCandle "+(string)CheckBar,OBJPROP_PRICE1,iOpen(NULL,TimeFrame,CheckBar)); //---- return(0); } //+------------------------------------------------------------------+ int Fibo_() { int index_low, index_high; double price_low, price_high; datetime t1=2, t2=0; //--- index_low=iLowest(NULL,TimeFrame,MODE_LOW,CheckBar+1,0); price_low=iLow(NULL,TimeFrame,index_low); index_high=iHighest(NULL,TimeFrame,MODE_HIGH,CheckBar+1,0); price_high=iHigh(NULL,TimeFrame,index_high); // Подключение Фибо-уровней if(Trend) { if(index_low>index_high) { ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME1,t1); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE1,price_high); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME2,t2); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE2,price_low); fibo_patterns("Fibo "+(string)CheckBar,price_high,price_low," "); } else { ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME1,t1); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE1,price_low); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME2,t2); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE2,price_high); fibo_patterns("Fibo "+(string)CheckBar,price_high,price_low," "); } } else { if(index_low>index_high) { ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME1,t1); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE1,price_low); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME2,t2); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE2,price_high); fibo_patterns("Fibo "+(string)CheckBar,price_high,price_low," "); } else { ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME1,t1); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE1,price_high); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_TIME2,t2); ObjectSet("Fibo "+(string)CheckBar,OBJPROP_PRICE2,price_low); fibo_patterns("Fibo "+(string)CheckBar,price_high,price_low," "); } } //--- return(0); } //-------------------------------------------------------- void fibo_patterns(string nameObj,double fiboPrice,double fiboPrice1,string str) { // Функция построения Фибо уровней ObjectSet(nameObj,OBJPROP_FIRSTLEVEL,0); ObjectSetFiboDescription(nameObj, 0, "0.0 "+DoubleToStr(fiboPrice, Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+1,0.25); ObjectSetFiboDescription(nameObj, 1, "25.0 "+DoubleToStr(fiboPrice1*0.25+fiboPrice*(1-0.25), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+2,0.333); ObjectSetFiboDescription(nameObj, 2, "33.3 "+DoubleToStr(fiboPrice1*0.333+fiboPrice*(1-0.333), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+3,0.5); ObjectSetFiboDescription(nameObj, 3, "50.0 "+DoubleToStr(fiboPrice1*0.5+fiboPrice*(1-0.5), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+4,0.666); ObjectSetFiboDescription(nameObj, 4, "66.6 "+DoubleToStr(fiboPrice1*0.666+fiboPrice*(1-0.666), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+5,0.75); ObjectSetFiboDescription(nameObj, 5, "75.0 "+DoubleToStr(fiboPrice1*0.75+fiboPrice*(1-0.75), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+6,1.0); ObjectSetFiboDescription(nameObj, 6, "100.0 "+DoubleToStr(fiboPrice1, Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+7,1.25); ObjectSetFiboDescription(nameObj, 7, "125.0 "+DoubleToStr(fiboPrice1*1.25+fiboPrice*(1-1.25), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+8,1.333); ObjectSetFiboDescription(nameObj, 8, "133.3 "+DoubleToStr(fiboPrice1*1.333+fiboPrice*(1-1.333), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+9,1.5); ObjectSetFiboDescription(nameObj, 9, "150.0 "+DoubleToStr(fiboPrice1*1.5+fiboPrice*(1-1.5), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+10,1.666); ObjectSetFiboDescription(nameObj, 10, "166.6 "+DoubleToStr(fiboPrice1*1.666+fiboPrice*(1-1.666), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+11,1.75); ObjectSetFiboDescription(nameObj, 11, "175.0 "+DoubleToStr(fiboPrice1*1.75+fiboPrice*(1-1.75), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+12,2.0); ObjectSetFiboDescription(nameObj, 12, "200.0 "+DoubleToStr(fiboPrice1*2.0+fiboPrice*(1-2.0), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+13,2.25); ObjectSetFiboDescription(nameObj, 13, "225.0 "+DoubleToStr(fiboPrice1*2.25+fiboPrice*(1-2.25), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+14,2.333); ObjectSetFiboDescription(nameObj, 14, "233.3 "+DoubleToStr(fiboPrice1*2.333+fiboPrice*(1-2.333), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+15,2.5); ObjectSetFiboDescription(nameObj, 15, "250.0 "+DoubleToStr(fiboPrice1*2.5+fiboPrice*(1-2.5), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+16,2.666); ObjectSetFiboDescription(nameObj, 16, "266.6 "+DoubleToStr(fiboPrice1*2.666+fiboPrice*(1-2.666), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+17,2.75); ObjectSetFiboDescription(nameObj, 17, "275.0 "+DoubleToStr(fiboPrice1*2.75+fiboPrice*(1-2.75), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+18,3.0); ObjectSetFiboDescription(nameObj, 18, "300.0 "+DoubleToStr(fiboPrice1*3.0+fiboPrice*(1-3.0), Digits)+str); ObjectSet(nameObj,OBJPROP_FIRSTLEVEL+19,4.0); ObjectSetFiboDescription(nameObj, 19, "400.0 "+DoubleToStr(fiboPrice1*4.0+fiboPrice*(1-4.0), Digits)+str); //---- return; } //--------------------------------------------------------