//+------------------------------------------------------------------+ //| geFiboExpand.mq4 | //| Copyright © 2007, ver 1.0 | //| Forte928 | //+------------------------------------------------------------------+ #property copyright "Forte928" #property link "" #define IndicatorName "geFiboExpand" #property indicator_chart_window //#property indicator_minimum -100 //#property indicator_maximum 100 #property indicator_buffers 3 #property indicator_color1 Aqua //Goldenrod//LightSkyBlue #property indicator_color2 Khaki #property indicator_color3 DodgerBlue //PaleGreen extern int Alpha = 200; extern color ColorFibo = Plum; extern int Counter = 5000; //double FreqTOL =0.0001;//Tolerance of frequency calculation for Method 1 double FxView1[]; double FxView2[]; double FxView3[]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Work Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ datetime TimeCalc; double IndexBuf1[]; double IndexBuf2[]; double IndexBuf3[]; double TimeBuf1[]; double TimeBuf2[]; double TimeBuf3[]; double TimeBuf4[]; double TimeBuf5[]; double TimeBuf6[]; double TimeBuf7[]; double TimeBuf8[]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialization program Buffers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void InitBufferam(int iBufferSize) { ArrayResize(IndexBuf1,iBufferSize); ArrayResize(IndexBuf2,iBufferSize); ArrayResize(IndexBuf3,iBufferSize); ArrayResize(TimeBuf1,iBufferSize); ArrayResize(TimeBuf2,iBufferSize); ArrayResize(TimeBuf3,iBufferSize); ArrayResize(TimeBuf4,iBufferSize); ArrayResize(TimeBuf5,iBufferSize); ArrayResize(TimeBuf6,iBufferSize); ArrayResize(TimeBuf7,iBufferSize); ArrayResize(TimeBuf8,iBufferSize); // ------------------------ return; } void EmptyBufferam() { ArrayInitialize(IndexBuf1,EMPTY_VALUE); ArrayInitialize(IndexBuf2,EMPTY_VALUE); ArrayInitialize(IndexBuf3,EMPTY_VALUE); ArrayInitialize(TimeBuf1,EMPTY_VALUE); ArrayInitialize(TimeBuf2,EMPTY_VALUE); ArrayInitialize(TimeBuf3,EMPTY_VALUE); ArrayInitialize(TimeBuf4,EMPTY_VALUE); ArrayInitialize(TimeBuf5,EMPTY_VALUE); ArrayInitialize(TimeBuf6,EMPTY_VALUE); ArrayInitialize(TimeBuf7,EMPTY_VALUE); ArrayInitialize(TimeBuf8,EMPTY_VALUE); // --> InitChart(FxView1); // --> InitChart(FxView2); // --> InitChart(FxView3); // --> return; } void DoneBufferam() { ArrayResize(IndexBuf1,0); ArrayResize(IndexBuf2,0); ArrayResize(IndexBuf3,0); ArrayResize(TimeBuf1,0); ArrayResize(TimeBuf2,0); ArrayResize(TimeBuf3,0); ArrayResize(TimeBuf4,0); ArrayResize(TimeBuf5,0); ArrayResize(TimeBuf6,0); ArrayResize(TimeBuf7,0); ArrayResize(TimeBuf8,0); //--------------------------------- return; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Program Constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int MaxPeriod=0; int CalcCount=0; string FiboLeft="_FiboLeft"; string FiboRight="_FiboRight"; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator initialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int init() { FiboLeft=Symbol()+FiboLeft; FiboRight=Symbol()+FiboRight; //---- initialization program values -------------------------------- MaxPeriod=0;//MathMax(ELMAPrd,MathMax(SlowPrd,MathMax(SlowPrd,SlowPrd))); InitBufferam(MaxCounter(Counter,MaxPeriod)); CalcCount=InitCounter(Counter,MaxPeriod); TimeCalc=0; // Ticket индекса времени, начала обновления буфера хранения //---- initialization indicators ------------------------------------- SetupChartLine(0,FxView1,0,1,"Close "); SetupChartLine(1,FxView2,2,2,"Close "); SetupChartLine(2,FxView3,2,2,"Close "); //IndicatorShortName(IndicatorName); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); SetIndexStyle(0,DRAW_LINE,STYLE_DOT); TicketGo(0); //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~ TickGo ~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ datetime TickGo; // старое значение тикета времени bool TicketGo(int TickInit) { if (TickInit==0) TickGo=0; else { if (TickGo==Time[0]) return(false); TickGo=Time[0]; } return(true); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator deinitialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int deinit() { //---- ObjectDelete(FiboLeft); ObjectDelete(FiboRight); DoneBufferam(); //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start defination ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int start() { if (!TicketGo(1)) return(0); if (!StartCounter(IndicatorName,Counter,CalcCount,MaxPeriod)) return(-1); //------------------------------------------------------------------------------------ string iTools=Symbol(); int BaseFrame=Period(); int Shifter=0; CopySeriesTools(TimeBuf1,Symbol(),Period(),MODE_HIGH,Shifter); CopySeriesTools(TimeBuf2,Symbol(),Period(),MODE_CLOSE,Shifter); CopySeriesTools(TimeBuf3,Symbol(),Period(),MODE_LOW,Shifter); HPFilter(TimeBuf2,TimeBuf4,Alpha,CalcCount); int IxState=0; int SxState=0; if (TimeBuf4[CalcCount-1]>TimeBuf4[CalcCount]) SxState=1; if (TimeBuf4[CalcCount-1]=0;Rx--){ IxState=0; // обнуление направления кривой if (TimeBuf4[Rx]>TimeBuf4[Rx+1]) IxState=1; // Определено направление кривой вверх if (TimeBuf4[Rx]=0;Rx--) { if (IndexBuf2[Rx]!=EMPTY_VALUE) { IxLeft=IxMidle; IxMidle=IxRight; IxRight=IndexBuf2[Rx]; if (IxLeft!=EMPTY_VALUE) { if (IxMidle>0) { IxIndex=ArrayMaximum(TimeBuf1,MathAbs(IxLeft)-MathAbs(IxRight),MathAbs(IxRight)); TimeBuf5[IxIndex]=TimeBuf1[IxIndex]; FiboValue[2]=FiboValue[1];FiboValue[1]=FiboValue[0]; FiboIndex[2]=FiboIndex[1];FiboIndex[1]=FiboIndex[0]; FiboValue[0]=TimeBuf1[IxIndex]; FiboIndex[0]=Time[IxIndex]; } if (IxMidle<0) { IxIndex=ArrayMinimum(TimeBuf3,MathAbs(IxLeft)-MathAbs(IxRight),MathAbs(IxRight)); TimeBuf6[IxIndex]=TimeBuf3[IxIndex]; FiboValue[2]=FiboValue[1];FiboValue[1]=FiboValue[0]; FiboIndex[2]=FiboIndex[1];FiboIndex[1]=FiboIndex[0]; FiboValue[0]=TimeBuf3[IxIndex]; FiboIndex[0]=Time[IxIndex]; } } if ((IxLeft==EMPTY_VALUE)&&(IxMidle!=EMPTY_VALUE)) { if (IxMidle>0) { IxIndex=ArrayMaximum(TimeBuf1,CalcCount-MathAbs(IxRight),MathAbs(IxRight)); TimeBuf5[IxIndex]=TimeBuf1[IxIndex]; FiboValue[2]=FiboValue[1];FiboValue[1]=FiboValue[0]; FiboIndex[2]=FiboIndex[1];FiboIndex[1]=FiboIndex[0]; FiboValue[0]=TimeBuf1[IxIndex]; FiboIndex[0]=Time[IxIndex]; } if (IxMidle<0) { IxIndex=ArrayMinimum(TimeBuf3,CalcCount-MathAbs(IxRight),MathAbs(IxRight)); TimeBuf6[IxIndex]=TimeBuf3[IxIndex]; FiboValue[2]=FiboValue[1];FiboValue[1]=FiboValue[0]; FiboIndex[2]=FiboIndex[1];FiboIndex[1]=FiboIndex[0]; FiboValue[0]=TimeBuf3[IxIndex]; FiboIndex[0]=Time[IxIndex]; } } // if (Rx<50) Print(Rx,") ",IxRight," ",IxMidle," ",IxLeft,"> ",IxIndex); } if (Rx==0) { if (IxRight>0) { IxIndex=ArrayMaximum(TimeBuf1,MathAbs(IxMidle),0); TimeBuf5[IxIndex]=TimeBuf1[IxIndex]; FiboValue[2]=FiboValue[1];FiboValue[1]=FiboValue[0]; FiboIndex[2]=FiboIndex[1];FiboIndex[1]=FiboIndex[0]; FiboValue[0]=TimeBuf1[IxIndex]; FiboIndex[0]=Time[IxIndex]; } if (IxRight<0) { IxIndex=ArrayMinimum(TimeBuf3,MathAbs(IxMidle),0); TimeBuf6[IxIndex]=TimeBuf3[IxIndex]; FiboValue[2]=FiboValue[1];FiboValue[1]=FiboValue[0]; FiboIndex[2]=FiboIndex[1];FiboIndex[1]=FiboIndex[0]; FiboValue[0]=TimeBuf3[IxIndex]; FiboIndex[0]=Time[IxIndex]; // if (Rx<50) Print(Rx,") ",IxRight," ",IxMidle," ",IxLeft,"> ",IxIndex," Min "); } } } FiboExpand(FiboLeft,0,FiboIndex[2],FiboValue[2],FiboIndex[1],FiboValue[1],FiboIndex[0],FiboValue[0],ColorFibo); ArrayCopy(FxView1,TimeBuf4,Shifter,0,CalcCount); ArrayCopy(FxView2,TimeBuf5,Shifter,0,CalcCount); ArrayCopy(FxView3,TimeBuf6,Shifter,0,CalcCount); //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void FiboExpand(string FiboName,int iWindow,double iTime1,double iPrice1,double iTime2,double iPrice2,double iTime3,double iPrice3,color iColor) { if (ObjectFind(FiboName)<0) { ObjectCreate(FiboName,OBJ_EXPANSION,0,0,0,0,0,0,0); ObjectSet(FiboName,OBJPROP_FIBOLEVELS,6); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+0,0); ObjectSetFiboDescription(FiboName,0,"0"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+1,0.146); ObjectSetFiboDescription(FiboName,1,"14.6"); ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+0,0.236); ObjectSetFiboDescription(FiboName,0,"FE 23.6"); ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+1,0.382); ObjectSetFiboDescription(FiboName,1,"FE 38.2"); ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+2,0.618); ObjectSetFiboDescription(FiboName,2,"FE 61.8"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+5,0.50); ObjectSetFiboDescription(FiboName,5,"50.0"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+6,0.764); ObjectSetFiboDescription(FiboName,6,"76.4"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+7,0.809); ObjectSetFiboDescription(FiboName,7,"80.9"); ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+3,0.854); ObjectSetFiboDescription(FiboName,3,"FE 85.4"); ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+4,1.00); ObjectSetFiboDescription(FiboName,4,"FE 100.0"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+10,1.146); ObjectSetFiboDescription(FiboName,10,"114.6"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+5,1.236); ObjectSetFiboDescription(FiboName,5,"123.6"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+6,1.382); ObjectSetFiboDescription(FiboName,6,"138.2"); ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+5,1.618); ObjectSetFiboDescription(FiboName,5,"FE 161.8"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+14,1.50); ObjectSetFiboDescription(FiboName,14,"150.0"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+15,1.764); ObjectSetFiboDescription(FiboName,15,"176.4"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+16,1.809); ObjectSetFiboDescription(FiboName,16,"180.9"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+8,1.854); ObjectSetFiboDescription(FiboName,8,"185.4"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+9,2.00); ObjectSetFiboDescription(FiboName,9,"200.0"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+19,2.146); ObjectSetFiboDescription(FiboName,19,"214.6"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+10,2.236); ObjectSetFiboDescription(FiboName,10,"223.6"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+11,2.382); ObjectSetFiboDescription(FiboName,11,"238.2"); // ObjectSet(FiboName,OBJPROP_FIRSTLEVEL+12,2.618); ObjectSetFiboDescription(FiboName,12,"261.8"); ObjectSet(FiboName,OBJPROP_LEVELCOLOR,iColor); ObjectSet(FiboName,OBJPROP_LEVELSTYLE,STYLE_DOT); ObjectSet(FiboName,OBJPROP_RAY,false); } ObjectSet(FiboName,OBJPROP_TIME1,iTime1);ObjectSet(FiboName,OBJPROP_PRICE1,iPrice1); ObjectSet(FiboName,OBJPROP_TIME2,iTime2);ObjectSet(FiboName,OBJPROP_PRICE2,iPrice2); ObjectSet(FiboName,OBJPROP_TIME3,iTime3);ObjectSet(FiboName,OBJPROP_PRICE3,iPrice3); return; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void InitChart(double& ayShift[]) // Смещение { if (ArraySize(ayShift)>0) ArrayInitialize(ayShift,EMPTY_VALUE); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~ InitCounter ~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int InitCounter(int iPreCount,int iMaxPeriod) { // Rule 1 //if ((Result==0)||(Result>Bars)) Result=Bars; int Result=MaxCounter(iPreCount,iMaxPeriod); // Rule 2 if ((Result+iMaxPeriod)>Bars) Result=Bars-iMaxPeriod; // Rule 3 if (ResultiCalcCount)||(iPreCount==0)) iCalcCount=InitCounter(iPreCount,iMaxPeriod); if (iCalcCount==0) { Alert(WindowName+" "+Symbol()+"("+Period()+") - Limited Calculate Period"); return(false); } return(true); //int iBarCount=IndicatorCounted(); //if (iBarCount>0) return(true); //Print("StartCounter"); return(false); } //------------------------------------------ StartCounter -------------------------- int MaxCounter(int iPreCount,int iMaxPeriod) { int Result=iPreCount; // Rule 1 //if ((Result==0)||(Result>Bars)) Result=Bars; if (Result==0) Result=Bars-1; if (Result=0;Hx--) { ayResult[Hx]=Ak[Hx]-Bk[Hx]*H1-Ck[Hx]*H2; H2=H1; H1=ayResult[Hx]; } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~