//+------------------------------------------------------------------+ //| Square-of-Nine v1.mq4 | //| Copyright © 2009-11, Kharko | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009-11, Kharko" #property link "" #property indicator_chart_window //---- extern int komplekt =0; // Номер комплекта extern int number.of.lines =3; // Количество промежуточных линий за 1 оборот extern int multiply.point =0; // Сдвиг десятичной запятой влево extern bool time.interval =false; // Выбираем границы временного промежутка extern int shift.txt =35; // Смещение текста, в барах extern color hhline.color =Blue; // Цвет оборотной линии, угол равен 0 или 360 градусов extern color hline.color =Blue; // Цвет промежуточной линии extern int hhline.width =2; // Толщина оборотной линии, угол равен 0 или 360 градусов extern int hline.width =1; // Толщина промежуточной линии extern color txt.color =Blue; // Цвет текста extern color marker.color =Blue; // Цвет маркера extern int marker.number =217; // Значок маркера //---- int new.period; double point; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators new.period=0; point=Point*MathPow(10,multiply.point); fDelete(); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here fDelete(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int count=0,count.line=0,count.turn=0,index=0,end.bar=0; int i.high.price=0,i.low.price=0; datetime time1=0,time2=0,t.high.price=0,t.low.price=0; double high.price=0,low.price=0; double sq.cell=0; double price=0; double degrees=0; double sq.step=NormalizeDouble(2.0/(number.of.lines+1),Digits); // шаг double deg.step=NormalizeDouble(360.0/(number.of.lines+1),Digits); // шаг string buff_str1=""; //---- TODO: add your code here string buff_str="Sq9_StartBar"+" Komplekt"+komplekt; if(ObjectFind(buff_str)==-1) { ObjectCreate(buff_str, OBJ_ARROW,0, Time[16], Low[16]-2*Point ); ObjectSet(buff_str, OBJPROP_ARROWCODE, marker.number); ObjectSet(buff_str, OBJPROP_COLOR, marker.color); new.period=16; time1=Time[16]; } else { time1=ObjectGet(buff_str,OBJPROP_TIME1); new.period=iBarShift(NULL,0,time1,false); } if(time.interval) { buff_str="Sq9_EndBar"+" Komplekt"+komplekt; if(ObjectFind(buff_str)==-1) { ObjectCreate(buff_str, OBJ_ARROW,0, Time[1], Low[1]-2*Point); ObjectSet(buff_str, OBJPROP_ARROWCODE, marker.number); ObjectSet(buff_str, OBJPROP_COLOR, marker.color); time2=Time[1]; new.period=MathAbs(iBarShift(NULL,0,time2,false)-iBarShift(NULL,0,time1,false)); end.bar=1; } else { time2=ObjectGet(buff_str,OBJPROP_TIME1); new.period=MathAbs(iBarShift(NULL,0,time2,false)-iBarShift(NULL,0,time1,false)); if(time2>time1) end.bar=iBarShift(NULL,0,time2,false); else end.bar=iBarShift(NULL,0,time1,false); } } else if(ObjectFind("Sq9_EndBar"+" Komplekt"+komplekt)!=-1) ObjectDelete("Sq9_EndBar"+" Komplekt"+komplekt); fDelete(); //price i.low.price=iLowest(NULL,0,MODE_LOW,new.period,end.bar); // индекс минимальной цены i.high.price=iHighest(NULL,0,MODE_HIGH,new.period,end.bar); // индекс максимальной цены low.price=Low[i.low.price]; // минимальная цена high.price=High[i.high.price]; // максимальная цена t.low.price=Time[i.low.price]; // время минимальной цены t.high.price=Time[i.high.price]; // время максимальной цены //determine double low.cell=NormalizeDouble(low.price/point,0); // ячейка минимальной цены double high.cell=NormalizeDouble(high.price/point,0); // ячейка максимальной цены double max.cell=0;// максимальная ячейка квадрата double min.cell=0; // миимальная ячейка квадрата double sq.max.cell=0; // квадратный корень максимальной ячейки double sq.min.cell=0; // квадратный корень минимальной ячейки count=0; count.line=0; if(t.high.price=sq.min.cell) { buff_str=StringConcatenate("Sq9_Hline",count," Komplekt",komplekt); price=NormalizeDouble(MathPow(sq.cell,2)*point,Digits); ObjectCreate(buff_str, OBJ_HLINE , 0,Time[0], price); ObjectSet(buff_str, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(buff_str, OBJPROP_COLOR, hline.color); ObjectSet(buff_str, OBJPROP_WIDTH, hline.width); ObjectMove(buff_str, 0, Time[0], price); degrees=NormalizeDouble(deg.step*count.line,0); buff_str1=StringConcatenate("Sq9_txt",count," Komplekt",komplekt); ObjectCreate(buff_str1, OBJ_TEXT, 0, Time[shift.txt], price); ObjectSetText(buff_str1, DoubleToStr(degrees,0)+" dg", 8, "Arial", txt.color); ObjectMove(buff_str1, 0, Time[shift.txt], price); if(count.line>number.of.lines || count.line==0) { ObjectSet(buff_str, OBJPROP_COLOR, hhline.color); ObjectSet(buff_str, OBJPROP_WIDTH, hhline.width); ObjectSetText(buff_str1, DoubleToStr(count.turn,0)+" turn", 8, "Arial", txt.color); count.line=0; count.turn--; } sq.cell=sq.cell-sq.step; count.line++; count++; } } else { max.cell=NormalizeDouble(MathPow(MathSqrt(high.cell)+2,2),0); min.cell=NormalizeDouble(MathPow(MathSqrt(low.cell),2),0); sq.max.cell=MathSqrt(max.cell); sq.min.cell=MathSqrt(min.cell); sq.cell=sq.min.cell; count.turn=0; while(sq.cell<=sq.max.cell) { buff_str=StringConcatenate("Sq9_Hline",count," Komplekt",komplekt); price=NormalizeDouble(MathPow(sq.cell,2)*point,Digits); ObjectCreate(buff_str, OBJ_HLINE , 0,Time[0], price); ObjectSet(buff_str, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(buff_str, OBJPROP_COLOR, hline.color); ObjectSet(buff_str, OBJPROP_WIDTH, hline.width); ObjectMove(buff_str, 0, Time[0], price); degrees=NormalizeDouble(deg.step*count.line,0); buff_str1=StringConcatenate("Sq9_txt",count," Komplekt",komplekt); ObjectCreate(buff_str1, OBJ_TEXT, 0, Time[shift.txt], price); ObjectSetText(buff_str1, DoubleToStr(degrees,0)+" dg", 8, "Arial", txt.color); ObjectMove(buff_str1, 0, Time[shift.txt], price); if(count.line>number.of.lines || count.line==0) { ObjectSet(buff_str, OBJPROP_COLOR, hhline.color); ObjectSet(buff_str, OBJPROP_WIDTH, hhline.width); ObjectSetText(buff_str1, DoubleToStr(count.turn,0)+" turn", 8, "Arial", txt.color); count.line=0; count.turn++; } sq.cell+=sq.step; count.line++; count++; } } //---- End Of Program return(0); } //+------------------------------------------------------------------+ int fDelete() { int i=0; while(ObjectFind(StringConcatenate("Sq9_Hline",i," Komplekt",komplekt))!=-1) { ObjectDelete(StringConcatenate("Sq9_Hline",i," Komplekt",komplekt)); ObjectDelete(StringConcatenate("Sq9_txt",i," Komplekt",komplekt)); i++; } //---- return(0); } //+------------------------------------------------------------------+