fibopivotcandlebar

Author: Copyright 2015 - By 3RJ ~ Roy Philips-Jacobs ~ 15/01/2015
fibopivotcandlebar
Price Data Components
Series array that contains open prices of each barSeries array that contains the lowest prices of each barSeries array that contains the highest prices of each barSeries array that contains close prices for each bar
Indicators Used
Moving average indicatorMoving average indicatorMACD Histogram
Miscellaneous
It plays sound alertsIt sends emails
0 Views
0 Downloads
0 Favorites
fibopivotcandlebar
//+------------------------------------------------------------------+
//|                                           FiboPivotCandleBar.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015 - By 3RJ ~ Roy Philips-Jacobs ~ 15/01/2015"
#property link      "http://www.mql5.com"
#property link      "http://www.gol2you.com ~ Forex Videos"
#property version   "1.00"
//--
#property description "This indicator is a composite of several forex indicators, Fibonacci, Pivot Point,"
#property description "ZigZag and MACD, which are combined in this indicator."
#property description "This indicator gives advice to buy and sell with the direction of the arrow."
/* Update_01 (22/03/2015): Reduce false signals, simplifying the formula, 
   and replace the formula of the Stochastic indicator with MACD indicator.
   //--
   Update_02 (26/04/2015): Fix code for Price Retracement FiboCandleBar.
   //--
   Update_03 (18/05/2015): 
   ~ Added Alerts (Messages, Email dan Sound) to the indicator.
   ~ Improve the performance of the Indicator.
   //--
   Update_04 (16/06/2015):
   ~ Add Color Option, so that the user can change the color bar and font colors
   //--
   //--
   Update_05 (30/07/2015):
   ~ Make minor changes to the Pivot formula.
   ~ Remove unused variables.
   //--
   Update_06 (16/09/2015):
   ~ Add a formula to improve the accuracy of the signal.
   //--
*/
//---
#property indicator_chart_window
//--
input string FiboPivotCandleBar="Copyright © 2015 By 2RJ ~ Roberto Rosano Philips-Jacobs";
extern bool      SoundAlerts = true;
extern bool      MsgAlerts   = true;
extern bool      eMailAlerts = false;
extern string SoundAlertFile = "alert2.wav";
extern color      FontColors= clrSnow;; // colors for font
extern color           BarUp = clrSnow; // color for Bar_Up and Bull Candle
extern color         BarDown=clrRed; // color for Bar_Down and Bear Candle
extern color       LineGraph=clrYellow; // color for Line Graph (if Price Close == Price Open)
extern color        EmptyBar=clrLightSlateGray; // If the bar has not been passed by the price movement
                                                //--
int corner=3; //0-for top-left corner,1-top-right,2-bottom-left,3-bottom-right
int distance_x=113;
int distance_y=29;
int prztick=200;
int digit;
int arrpvt=20;
int font_size=8;
int font_size_OHLC=7;
color font_color=FontColors;
string font_face="Arial";
string font_ohlc="Arial Black";
//--
double Pl20,Pl40,Pl60,Pl80,PSR1,PSS1,R1S1;
double PvtO,PvtL,PvtH,PvtC,PvtO1,PvtL1,PvtH1,PvtC1;
double Pvt,PR1,PS1,PR2,PS2,PR3,PS3,PR4,PS4,PR5,PS5,PR6,PS6;
//-
double ema02m[];
double sma20m[];
double maon10[];
double maon62[];
//-
double pivot[];
double fibolvl[]={0.0,23.6,38.2,50.0,61.8};
string label[]={"S7","S6","S5","S4","S3","S2","SS1","S1","L20","L40","L60","L80","R1","SR1","R2","R3","R4","R5","R6","R7"};
//  0    1    2    3    4     5    6     7     8     9    10    11   12    13   14   15   16   17   18   19
//--
int per;
int cral;
int pral;
int crmnt;
int prmnt;
//--
string CopyRight;
string alBase,alSubj,alMsg;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicators
   CopyRight="Copyright © 2015 By 2RJ ~ Roberto Rosano Philips-Jacobs";
//-- Checking the Digits Point
   if(Digits==3 || Digits==5)
     {digit=Digits;}
   else {digit=Digits+1;}
//--
   EventSetTimer(60);
//---
   IndicatorShortName("FiboPivotCandleBar ("+_Symbol+")");
//--
   IndicatorDigits(digit);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//----
   ObjectsDeleteAll();
//--
   EventKillTimer();
   GlobalVariablesDeleteAll();
//----
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(FiboPivotCandleBar!=CopyRight) return(0);
//--
   int counted_bars=IndicatorCounted();
//-
   if(counted_bars<0) return(-1);
//-
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0)
      limit=WindowBarsPerChart();
   int HiLo=WindowFirstVisibleBar();
//--- Set Last error value to Zero
   ResetLastError();
   RefreshRates();
//--
   cral=0;
   int prdp;
   int prfb;
   int pstep;
   int cprz=5;
   int dlvl=5;
   int fstp=4;
   int bhl=19;
   int prhh=30;
   int prh1=60;
   int zzh1,zzl1;
   int zhm1,zlm1;
//-
   color clrmove;
   color fbarup=BarUp;
   color fbardn=BarDown;
   color fbarnt=LineGraph;
   color color_fbar=EmptyBar;
//-
   double dfl=61.8;
   double barlvl[],przlvl[];
//--
   RefreshRates();
//--
   if(_Period==43200) {prdp=43200; prfb=1440;}
   if(_Period==10080) {prdp=10080; prfb=240;}
   if(_Period<=1440) {prdp=1440; prfb=60;}
//--
   ArrayResize(barlvl,dlvl);
   ArrayResize(fibolvl,dlvl);
   ArrayResize(przlvl,dlvl);
   ArrayResize(pivot,arrpvt);
   ArrayResize(label,arrpvt);
//- Set the arrays as a series
   ArraySetAsSeries(barlvl,false);
   ArraySetAsSeries(przlvl,false);
   ArraySetAsSeries(fibolvl,false);
   ArraySetAsSeries(pivot,false);
   ArraySetAsSeries(label,false);
//-
   RefreshRates();
//--
   for(int p=per; p>=0; p--) //- for(p)
     {
      //--
      PvtO=iOpen(_Symbol,prdp,p);
      PvtL=iLow(_Symbol,prdp,p);
      PvtH=iHigh(_Symbol,prdp,p);
      PvtC=Close[p];
      PvtL1=iLow(_Symbol,prdp,p+1);
      PvtH1=iHigh(_Symbol,prdp,p+1);
      PvtC1=iClose(_Symbol,prdp,p+1);
      PvtO1=iOpen(_Symbol,prdp,p+1);
      //--
      if(p==0)
        {
         //--
         Pvt=(PvtH1+PvtL1+PvtC1)/3;
         //-
         pivot[0]=(Pvt*6)-((PvtH1*6)-(PvtL1));
         pivot[1]=(Pvt*5)-((PvtH1*5)-(PvtL1));
         pivot[2]=(Pvt*4)-((PvtH1*4)-(PvtL1));
         pivot[3]=(Pvt*3)-((PvtH1*3)-(PvtL1));
         pivot[4]=(Pvt*2)-((PvtH1*2)-(PvtL1));
         pivot[5]=(Pvt-PvtH1+PvtL1);
         pivot[7]=((Pvt*2)-PvtH1);
         pivot[12]=((Pvt*2)-PvtL1);
         R1S1=pivot[12]-pivot[7];
         pivot[8]=(pivot[7]+(R1S1*0.2));
         pivot[9]=(pivot[7]+(R1S1*0.4));
         pivot[10]=(pivot[7]+(R1S1*0.6));
         pivot[11]=(pivot[7]+(R1S1*0.8));
         pivot[14]=(Pvt+PvtH1-PvtL1);
         //-
         pivot[6]=pivot[7]-((pivot[8]-pivot[7])*(0.618));
         pivot[13]=pivot[12]+((pivot[12]-pivot[11])*(0.618));
         //-
         pivot[15]=(Pvt*2)+(PvtH1)-(PvtL1*2);
         pivot[16]=(Pvt*3)+(PvtH1)-(PvtL1*3);
         pivot[17]=(Pvt*4)+(PvtH1)-(PvtL1*4);
         pivot[18]=(Pvt*5)+(PvtH1)-(PvtL1*5);
         pivot[19]=(Pvt*6)+(PvtH1)-(PvtL1*6);
         //--
        }
     } //-end for(p)
//- prediction the price movements
   ArrayResize(ema02m,100);
   ArrayResize(sma20m,100);
   ArrayResize(maon10,100);
   ArrayResize(maon62,100);
   ArraySetAsSeries(ema02m,true);
   ArraySetAsSeries(sma20m,true);
   ArraySetAsSeries(maon10,true);
   ArraySetAsSeries(maon62,true);
   for(int j=99; j>=0; j--)
     {ema02m[j]=iMA(_Symbol,cprz,2,0,1,4,j);}
   for(int k=99; k>=0; k--)
     {sma20m[k]=iMA(_Symbol,cprz,20,0,0,4,k);}
   for(int q=99; q>=0; q--)
     {maon10[q]=iMAOnArray(sma20m,0,10,0,0,q);}
   for(int m=99; m>=0; m--)
     {maon62[m]=iMAOnArray(sma20m,0,62,0,0,m);}
   double ma10620=maon10[0]-maon62[0];
   double ma10621=maon10[1]-maon62[1];
   double ma20100=sma20m[0]-maon10[0];
   double ma20101=sma20m[1]-maon10[1];
//-
   bool ma5xupn=(ema02m[0]>ema02m[1])&&(sma20m[0]>sma20m[1])&&(ma10620>=ma10621)&&((maon10[2]<maon62[2])&&(maon10[0]>maon62[0]));
   bool ma5xupc=(ema02m[0]>ema02m[1])&&(sma20m[0]>sma20m[1])&&(ma10620>=ma10621)&&(maon10[0]>maon62[0])&&(maon10[0]>maon10[1]);
   bool ma5xupb=(ema02m[0]>ema02m[1])&&(sma20m[0]>sma20m[1])&&(ma20100>ma20101)&&(maon62[0]>maon62[1])&&(sma20m[0]>maon10[0]);
   bool ma5xdnn=(ema02m[0]<ema02m[1])&&(sma20m[0]<sma20m[1])&&(ma10620<=ma10621)&&((maon10[2]>maon62[2])&&(maon10[0]<maon62[0]));
   bool ma5xdnc=(ema02m[0]<ema02m[1])&&(sma20m[0]<sma20m[1])&&(ma10620<=ma10621)&&(maon10[0]<maon62[0])&&(maon10[0]<maon10[1]);
   bool ma5xdna=(ema02m[0]<ema02m[1])&&(sma20m[0]<sma20m[1])&&(ma20100<ma20101)&&(maon62[0]<maon62[1])&&(sma20m[0]<maon10[0]);
//-
   for(int zz=99; zz>=0; zz--) //- for(zz)
     {
      //--
      if(iHigh(_Symbol,prh1,zz)==iCustom(_Symbol,prh1,"ZigZag",1,zz))
        {zzh1=zz;}
      if(iLow(_Symbol,prh1,zz)==iCustom(_Symbol,prh1,"ZigZag",2,zz))
        {zzl1=zz;}
      //-
      if(iHigh(_Symbol,prhh,zz)==iCustom(_Symbol,prhh,"ZigZag",1,zz))
        {zhm1=zz;}
      if(iLow(_Symbol,prhh,zz)==iCustom(_Symbol,prhh,"ZigZag",2,zz))
        {zlm1=zz;}
     } //-end for(zz)
//-
   RefreshRates();
//-
   double macd0=iMACD(_Symbol,prh1,12,26,9,0,0,0)-iMACD(_Symbol,prh1,12,26,9,0,1,0);
   double macd1=iMACD(_Symbol,prh1,12,26,9,0,0,1)-iMACD(_Symbol,prh1,12,26,9,0,1,1);
   double mcdm0=iMACD(_Symbol,prh1,12,26,9,0,0,0);
   double mcdm1=iMACD(_Symbol,prh1,12,26,9,0,0,1);
   double mcds0=iMACD(_Symbol,prh1,12,26,9,0,1,0);
   double mcds1=iMACD(_Symbol,prh1,12,26,9,0,1,1);
//-
   if((((zzl1<zzh1) && (zzl1>0) && (zzl1<4) && (zlm1<zhm1))) || ((macd0>macd1) && (mcdm0>mcdm1)))
     {bool ArrUp=true;}
   if((((zzl1>zzh1) && (zzh1>0) && (zzh1<4) && (zlm1>zhm1))) || ((macd0<macd1) && (mcdm0<mcdm1)))
     {bool ArrDn=true;}
   if(((ArrUp==true)&&(zzl1>4))||((mcdm0<mcdm1)&&(macd0<macd1))) {ArrDn=true; ArrUp=false;}
   if(((ArrDn==true)&&(zzh1>4))||((mcdm0>mcdm1)&&(macd0>macd1))) {ArrUp=true; ArrDn=false;}
   if((mcdm0>=mcdm1)&&(mcdm0>mcds0)&&(mcds0>mcds1)) {ArrUp=true; ArrDn=false;}
   if((mcdm0<=mcdm1)&&(mcdm0<mcds0)&&(mcds0<mcds1)) {ArrDn=true; ArrUp=false;}
   if(ma5xupn||ma5xupc||ma5xupb) {ArrUp=true; ArrDn=false;}
   if(ma5xdnn||ma5xdnc||ma5xdna) {ArrDn=true; ArrUp=false;}
//-
   double fpCls0=(iHigh(_Symbol,prh1,0)+iLow(_Symbol,prh1,0)+iClose(_Symbol,prh1,0)+iClose(_Symbol,prh1,0))/4;
   double fpCls1=(iHigh(_Symbol,prh1,1)+iLow(_Symbol,prh1,1)+iClose(_Symbol,prh1,1)+iClose(_Symbol,prh1,1))/4;
   double hlcc0=fpCls0-iMA(_Symbol,prh1,20,0,0,4,0);
   double hlcc1=fpCls1-iMA(_Symbol,prh1,20,0,0,4,1);
//- prepare the braking movement
   if((ArrUp==true) && (hlcc0>hlcc1))
     {bool opsup=true; int stax=18; string stdir="BUY"; color opsclr=fbarup;}
   if((ArrDn==true) && (hlcc0<hlcc1))
     {bool opsdn=true; opsup=false; stax=22; stdir="SELL"; opsclr=fbardn;}
   if((!opsup) && (!opsdn))
     {bool opsnt=true; opsup=false; opsdn=false; opsclr=fbarnt;}
//-- prepare the Fibo Highest and Lowest Price
   int inH=iHighest(_Symbol,prfb,MODE_HIGH,HiLo,0);
   int inL=iLowest(_Symbol,prfb,MODE_LOW,HiLo,0);
   if(inH!=-1) double himax=iHigh(_Symbol,prfb,inH);
   if(inL!=-1) double lomin=iLow(_Symbol,prfb,inL);
   if((PvtH<=pivot[12]) && (PvtL>=pivot[7])) {himax=pivot[12]; lomin=pivot[7];}
   double dayHi=MarketInfo(_Symbol,MODE_HIGH);
   double dayLo=MarketInfo(_Symbol,MODE_LOW);
//-
   for(int g=0; g<dlvl; g++)
     {
      //--
      barlvl[g]=prztick/dfl*fibolvl[g];
      przlvl[g]=lomin+(((himax-lomin)/dfl)*fibolvl[g]);
     }
//--
   RefreshRates();
//-
   int fbar0=barlvl[1]-barlvl[0];
   int fbar1=barlvl[2]-barlvl[1];
   int fbar2=barlvl[3]-barlvl[2];
   int fbar3=barlvl[4]-barlvl[3];
   int fbajs=prztick-(fbar0+fbar1+fbar2+fbar3);
//-
   if((PvtO>=przlvl[0]) && (PvtO<=przlvl[1]))
     {double fpo10=(PvtO-przlvl[0])/(przlvl[1]-przlvl[0]); int pso=(fpo10*fbar0)+fbajs;}
   if((PvtO>=przlvl[1]) && (PvtO<=przlvl[2]))
     {double fpo21=(PvtO-przlvl[1])/(przlvl[2]-przlvl[1]); pso=fbar0+(fpo21*fbar1)+fbajs;}
   if((PvtO>=przlvl[2]) && (PvtO<=przlvl[3]))
     {double fpo32=(PvtO-przlvl[2])/(przlvl[3]-przlvl[2]); pso=fbar0+fbar1+(fpo32*fbar2)+fbajs;}
   if((PvtO>=przlvl[3]) && (PvtO<=przlvl[4]))
     {double fpo43=(PvtO-przlvl[3])/(przlvl[4]-przlvl[3]); pso=fbar0+fbar1+fbar2+(fpo43*fbar3)+fbajs;}
//-
   if((PvtH>=przlvl[0]) && (PvtH<=przlvl[1]))
     {double fph10=(PvtH-przlvl[0])/(przlvl[1]-przlvl[0]); int psh=(fph10*fbar0)+fbajs;}
   if((PvtH>=przlvl[1]) && (PvtH<=przlvl[2]))
     {double fph21=(PvtH-przlvl[1])/(przlvl[2]-przlvl[1]); psh=fbar0+(fph21*fbar1)+fbajs;}
   if((PvtH>=przlvl[2]) && (PvtH<=przlvl[3]))
     {double fph32=(PvtH-przlvl[2])/(przlvl[3]-przlvl[2]); psh=fbar0+fbar1+(fph32*fbar2)+fbajs;}
   if((PvtH>=przlvl[3]) && (PvtH<=przlvl[4]))
     {double fph43=(PvtH-przlvl[3])/(przlvl[4]-przlvl[3]); psh=fbar0+fbar1+fbar2+(fph43*fbar3)+fbajs;}
//-
   if((PvtL>=przlvl[0]) && (PvtL<=przlvl[1]))
     {double fpl10=(PvtL-przlvl[0])/(przlvl[1]-przlvl[0]); int psl=(fpl10*fbar0)+fbajs;}
   if((PvtL>=przlvl[1]) && (PvtL<=przlvl[2]))
     {double fpl21=(PvtL-przlvl[1])/(przlvl[2]-przlvl[1]); psl=fbar0+(fpl21*fbar1)+fbajs;}
   if((PvtL>=przlvl[2]) && (PvtL<=przlvl[3]))
     {double fpl32=(PvtL-przlvl[2])/(przlvl[3]-przlvl[2]); psl=fbar0+fbar1+(fpl32*fbar2)+fbajs;}
   if((PvtL>=przlvl[3]) && (PvtL<=przlvl[4]))
     {double fpl43=(PvtL-przlvl[3])/(przlvl[4]-przlvl[3]); psl=fbar0+fbar1+fbar2+(fpl43*fbar3)+fbajs;}
//-   
   if((PvtC>=przlvl[0]) && (PvtC<=przlvl[1]))
     {double fpb10=(PvtC-przlvl[0])/(przlvl[1]-przlvl[0]); int pst=(fpb10*fbar0)+fbajs;}
   if((PvtC>=przlvl[1]) && (PvtC<=przlvl[2]))
     {double fpb21=(PvtC-przlvl[1])/(przlvl[2]-przlvl[1]); pst=fbar0+(fpb21*fbar1)+fbajs;}
   if((PvtC>=przlvl[2]) && (PvtC<=przlvl[3]))
     {double fpb32=(PvtC-przlvl[2])/(przlvl[3]-przlvl[2]); pst=fbar0+fbar1+(fpb32*fbar2)+fbajs;}
   if((PvtC>=przlvl[3]) && (PvtC<=przlvl[4]))
     {double fpb43=(PvtC-przlvl[3])/(przlvl[4]-przlvl[3]); pst=fbar0+fbar1+fbar2+(fpb43*fbar3)+fbajs;}
   int fbbar=psh-psl;
//--
   for(int b=0; b<=bhl; b++)
     {
      //--
      if((PvtO>=pivot[b])&&(PvtO<pivot[b+1])) {int ob=b; int ot=b+1;}
      if((PvtH>=pivot[b])&&(PvtH<pivot[b+1])) {int tb=b; int tt=b+1;}
      if((PvtL>=pivot[b])&&(PvtL<pivot[b+1])) {int bb=b; int bt=b+1;}
      if((PvtC>=pivot[b])&&(PvtC<pivot[b+1])) {int cb=b; int ct=b+1;}
      if((PvtH<=pivot[12])&&(PvtL>=pivot[7]))
        {bool pvths=true; int hb=11; int ht=12; int lb=7; int lt=8;}
      else {pvths=false; hb=tb; ht=tt; lb=bb; lt=bt;}
     }
//--
   if(ht-lb<5) {ht=lb+5;}
   pstep=ht-lb;
   int pvtlvl=prztick/pstep;
//--
   double barop=((PvtO-pivot[ob])/(pivot[ot]-pivot[ob])*pvtlvl)+((ob-lb)*pvtlvl);
   double barhi=((PvtH-pivot[tb])/(pivot[tt]-pivot[tb])*pvtlvl)+((tb-lb)*pvtlvl);
   double barcl=((PvtC-pivot[cb])/(pivot[ct]-pivot[cb])*pvtlvl)+((cb-lb)*pvtlvl);
   double barlo=((PvtL-pivot[bb])/(pivot[bt]-pivot[bb])*pvtlvl);
   if(pvths==true) {barlo=((PvtL-pivot[bb])/(pivot[bt]-pivot[bb])*pvtlvl)+((bb-lb)*pvtlvl);}
   int candlo=(int)barlo;
   int candhi=(int)barhi;
   int candop=(int)barop-1;
   int candcl=(int)barcl;
   int candbar=candhi-candlo;
   if(PvtC>PvtO) {int candclu=candcl-candop+1; clrmove=fbarup;}
   if(PvtC<PvtO) {int candcld=candop-candcl+1; clrmove=fbardn;}
   if(PvtC==PvtO) {clrmove=fbarnt;}
//--
   for(int d=0; d<=bhl; d++)
     {
      ObjectDelete("PivotLevel_"+d);
      ObjectDelete("PivotLableLevel_"+d);
     }
//--
   for(int s=0; s<=prztick; s++)
     {
      ObjectDelete("PivotBar"+s);
      ObjectDelete("CloseBar"+s);
      ObjectDelete("PivotBarNt"+s);
     }
//--
   ObjectDelete("PivotDir");
//--
   for(int r=0; r<=pstep; r++)
     {
      //-- Create Pivot Bar Levels
      ObjectCreate("PivotLevel_"+r,OBJ_LABEL,0,0,0,0,0);
      ObjectSet("PivotLevel_"+r,OBJPROP_CORNER,corner);
      ObjectSet("PivotLevel_"+r,OBJPROP_XDISTANCE,distance_x-109);
      ObjectSet("PivotLevel_"+r,OBJPROP_YDISTANCE,distance_y+r*pvtlvl);
      ObjectSetText("PivotLevel_"+r,
                    StringConcatenate(CharToStr(45),DoubleToStr(pivot[lb+r],digit)),font_size,font_face,font_color);
      //-
      ObjectCreate("PivotLableLevel_"+r,OBJ_LABEL,0,0,0,0,0);
      ObjectSet("PivotLableLevel_"+r,OBJPROP_CORNER,corner);
      ObjectSet("PivotLableLevel_"+r,OBJPROP_XDISTANCE,distance_x-33);
      ObjectSet("PivotLableLevel_"+r,OBJPROP_YDISTANCE,distance_y+r*pvtlvl);
      ObjectSetText("PivotLableLevel_"+r,
                    StringConcatenate(label[lb+r],CharToStr(45)),font_size,font_face,font_color);
      //--
      if(r==pstep)
        {
         //--
         RefreshRates();
         //-
         for(int pv=0; pv<prztick; pv++)
           {
            //--
            ObjectCreate("PivotBarNt"+pv,OBJ_LABEL,0,0,0,0,0);
            ObjectSet("PivotBarNt"+pv,OBJPROP_CORNER,corner);
            ObjectSet("PivotBarNt"+pv,OBJPROP_XDISTANCE,distance_x-52);
            ObjectSet("PivotBarNt"+pv,OBJPROP_YDISTANCE,distance_y-1+pv);
            ObjectSetText("PivotBarNt"+pv,CharToStr(45),font_size,font_face,color_fbar);
           }
         //-
         for(int i=0; i<candbar; i++)
           {
            //--
            ObjectCreate("PivotBar"+i,OBJ_LABEL,0,0,0,0,0);
            ObjectSet("PivotBar"+i,OBJPROP_CORNER,corner);
            ObjectSet("PivotBar"+i,OBJPROP_XDISTANCE,distance_x-52);
            ObjectSet("PivotBar"+i,OBJPROP_YDISTANCE,distance_y+candlo+1+i);
            ObjectSetText("PivotBar"+i,CharToStr(45),font_size,font_face,clrmove);
           }
         //--
         if(PvtC>PvtO)
           {
            for(int v=0; v<candclu; v++)
              {
               //--
               ObjectCreate("CloseBar"+v,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("CloseBar"+v,OBJPROP_CORNER,corner);
               ObjectSet("CloseBar"+v,OBJPROP_XDISTANCE,distance_x-66);
               ObjectSet("CloseBar"+v,OBJPROP_YDISTANCE,distance_y+candop+1+v);
               ObjectSetText("CloseBar"+v,
                             StringConcatenate(CharToStr(151),CharToStr(151),CharToStr(151)),font_size,font_face,clrmove);
              }
           }
         //-
         if(PvtC<PvtO)
           {
            for(v=0; v<candcld; v++)
              {
               //--
               ObjectCreate("CloseBar"+v,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("CloseBar"+v,OBJPROP_CORNER,corner);
               ObjectSet("CloseBar"+v,OBJPROP_XDISTANCE,distance_x-66);
               ObjectSet("CloseBar"+v,OBJPROP_YDISTANCE,distance_y+candcl+1+v);
               ObjectSetText("CloseBar"+v,
                             StringConcatenate(CharToStr(151),CharToStr(151),CharToStr(151)),font_size,font_face,clrmove);
              }
           }
         //-
         if(PvtC==PvtO)
           {
            for(v=0; v<2; v++)
              {
               //--
               ObjectCreate("CloseBar"+v,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("CloseBar"+v,OBJPROP_CORNER,corner);
               ObjectSet("CloseBar"+v,OBJPROP_XDISTANCE,distance_x-66);
               ObjectSet("CloseBar"+v,OBJPROP_YDISTANCE,distance_y+candop+1+v);
               ObjectSetText("CloseBar"+v,
                             StringConcatenate(CharToStr(151),CharToStr(151),CharToStr(151)),font_size,font_face,clrmove);
              }
           }
        }
     }
//--
   for(int n=0; n<dlvl; n++)
     {
      //--
      ObjectDelete("FiboBarLevel_"+n);
      ObjectDelete("FiboBar_"+n);
     }
//--
   for(int db=0; db<prztick; db++)
     {
      ObjectDelete("FiboBar"+db);
      ObjectDelete("FiboBar_cu"+db);
      ObjectDelete("FiboBar_cd"+db);
      ObjectDelete("FiboBar_nt"+db);
      ObjectDelete("FiboBarUph"+db);
      ObjectDelete("FiboBarDnl"+db);
      ObjectDelete("FiboBar_cln"+db);
      ObjectDelete("FiboBar_clu"+db);
      ObjectDelete("FiboBar_cld"+db);
     }
//--
   ObjectDelete("FiboDir");
   ObjectDelete("StochDir");
//--
   for(n=0; n<dlvl; n++)
     {
      //--
      ObjectCreate("FiboBar_"+n,OBJ_LABEL,0,0,0,0,0);
      ObjectSet("FiboBar_"+n,OBJPROP_CORNER,corner);
      ObjectSet("FiboBar_"+n,OBJPROP_XDISTANCE,distance_x-5);
      ObjectSet("FiboBar_"+n,OBJPROP_YDISTANCE,distance_y+fbajs+(int)barlvl[n]);
      ObjectSetText("FiboBar_"+n,
                    StringConcatenate(CharToStr(45),DoubleToStr(przlvl[n],digit)),font_size,font_face,font_color);
      //-
      ObjectCreate("FiboBarLevel_"+n,OBJ_LABEL,0,0,0,0,0);
      ObjectSet("FiboBarLevel_"+n,OBJPROP_CORNER,corner);
      ObjectSet("FiboBarLevel_"+n,OBJPROP_XDISTANCE,distance_x+71);
      ObjectSet("FiboBarLevel_"+n,OBJPROP_YDISTANCE,distance_y+fbajs+(int)barlvl[n]);
      ObjectSetText("FiboBarLevel_"+n,
                    StringConcatenate(DoubleToStr(fibolvl[n],1),CharToStr(45)),font_size,font_face,font_color);
      //--
      if(n==fstp)
        {
         //--
         RefreshRates();
         //-
         for(int fb=0; fb<prztick; fb++)
           {
            //--
            ObjectCreate("FiboBar"+fb,OBJ_LABEL,0,0,0,0,0);
            ObjectSet("FiboBar"+fb,OBJPROP_CORNER,corner);
            ObjectSet("FiboBar"+fb,OBJPROP_XDISTANCE,distance_x+52);
            ObjectSet("FiboBar"+fb,OBJPROP_YDISTANCE,distance_y-1+fbajs+fb);
            ObjectSetText("FiboBar"+fb,CharToStr(45),font_size,font_face,color_fbar);
           }
         //--
         if(PvtC<PvtO)
           {
            //--
            for(int l=0; l<=psh-psl; l++)
              {
               //--
               ObjectCreate("FiboBar_cd"+l,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("FiboBar_cd"+l,OBJPROP_CORNER,corner);
               ObjectSet("FiboBar_cd"+l,OBJPROP_XDISTANCE,distance_x+52);
               ObjectSet("FiboBar_cd"+l,OBJPROP_YDISTANCE,distance_y-1+fbajs+psl+l);
               ObjectSetText("FiboBar_cd"+l,CharToStr(45),font_size,font_face,clrmove);
              }
            //-
            for(int fl=0; fl<pso-pst+1; fl++)
              {
               //--
               ObjectCreate("FiboBar_cld"+fl,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("FiboBar_cld"+fl,OBJPROP_CORNER,corner);
               ObjectSet("FiboBar_cld"+fl,OBJPROP_XDISTANCE,distance_x+38);
               ObjectSet("FiboBar_cld"+fl,OBJPROP_YDISTANCE,distance_y-1+fbajs+pst+fl);
               ObjectSetText("FiboBar_cld"+fl,
                             StringConcatenate(CharToStr(151),CharToStr(151),CharToStr(151)),font_size,font_face,fbardn);
              }
           }
         //--
         if(PvtC>PvtO)
           {
            //--
            for(l=0; l<=psh-psl; l++)
              {
               //--
               ObjectCreate("FiboBar_cu"+l,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("FiboBar_cu"+l,OBJPROP_CORNER,corner);
               ObjectSet("FiboBar_cu"+l,OBJPROP_XDISTANCE,distance_x+52);
               ObjectSet("FiboBar_cu"+l,OBJPROP_YDISTANCE,distance_y-1+fbajs+psl+l);
               ObjectSetText("FiboBar_cu"+l,CharToStr(45),font_size,font_face,clrmove);
              }
            //-
            for(fl=0; fl<pst-pso+1; fl++)
              {
               //--
               ObjectCreate("FiboBar_clu"+fl,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("FiboBar_clu"+fl,OBJPROP_CORNER,corner);
               ObjectSet("FiboBar_clu"+fl,OBJPROP_XDISTANCE,distance_x+38);
               ObjectSet("FiboBar_clu"+fl,OBJPROP_YDISTANCE,distance_y-1+fbajs+pso+fl);
               ObjectSetText("FiboBar_clu"+fl,
                             StringConcatenate(CharToStr(151),CharToStr(151),CharToStr(151)),font_size,font_face,fbarup);
              }
           }
         //--
         if(PvtC==PvtO)
           {
            //--
            for(l=0; l<=psh-psl; l++)
              {
               //--
               ObjectCreate("FiboBar_nt"+l,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("FiboBar_nt"+l,OBJPROP_CORNER,corner);
               ObjectSet("FiboBar_nt"+l,OBJPROP_XDISTANCE,distance_x+52);
               ObjectSet("FiboBar_nt"+l,OBJPROP_YDISTANCE,distance_y-1+fbajs+psl+l);
               ObjectSetText("FiboBar_nt"+l,CharToStr(45),font_size,font_face,fbarnt);
              }
            //-
            for(fl=0; fl<2; fl++)
              {
               //--
               ObjectCreate("FiboBar_cln"+fl,OBJ_LABEL,0,0,0,0,0);
               ObjectSet("FiboBar_cln"+fl,OBJPROP_CORNER,corner);
               ObjectSet("FiboBar_cln"+fl,OBJPROP_XDISTANCE,distance_x+38);
               ObjectSet("FiboBar_cln"+fl,OBJPROP_YDISTANCE,distance_y-1+fbajs+pso+fl);
               ObjectSetText("FiboBar_cln"+fl,
                             StringConcatenate(CharToStr(151),CharToStr(151),CharToStr(151)),font_size,font_face,fbarnt);
              }
           }
         //--
         if(ArrUp==true)
           {
            //--
            if((PvtL==dayLo) && (PvtC>dayLo))
              {
               //--
               cral=-2;
               for(int bd=0; bd<pst-psl; bd++)
                 {
                  ObjectCreate("FiboBarDnl"+bd,OBJ_LABEL,0,0,0,0,0);
                  ObjectSet("FiboBarDnl"+bd,OBJPROP_CORNER,corner);
                  ObjectSet("FiboBarDnl"+bd,OBJPROP_XDISTANCE,distance_x+52);
                  ObjectSet("FiboBarDnl"+bd,OBJPROP_YDISTANCE,distance_y+fbajs+psl+bd);
                  ObjectSetText("FiboBarDnl"+bd,CharToStr(45),font_size,font_face,fbarup);
                 }
              }
            //-
            ObjectCreate(0,"FiboDir",OBJ_LABEL,0,0,0,0,0);
            ObjectSetString(0,"FiboDir",OBJPROP_TEXT,CharToStr(217));
            ObjectSetString(0,"FiboDir",OBJPROP_FONT,"Wingdings");
            ObjectSetInteger(0,"FiboDir",OBJPROP_FONTSIZE,20);
            if((ArrUp==true) && (opsup==true))
              {ObjectSetInteger(0,"FiboDir",OBJPROP_COLOR,fbarup);}
            else {ObjectSetInteger(0,"FiboDir",OBJPROP_COLOR,fbarnt);}
            ObjectSetInteger(0,"FiboDir",OBJPROP_CORNER,corner);
            ObjectSetInteger(0,"FiboDir",OBJPROP_XDISTANCE,distance_x+66);
            ObjectSetInteger(0,"FiboDir",OBJPROP_YDISTANCE,distance_y-2);
            //--
            if(opsup==true)
              {
               //--
               cral=1;
               ObjectCreate("StochDir",OBJ_LABEL,0,0,0,0,0);
               ObjectSet("StochDir",OBJPROP_CORNER,corner);
               ObjectSet("StochDir",OBJPROP_XDISTANCE,distance_x-stax);
               ObjectSet("StochDir",OBJPROP_YDISTANCE,distance_y-27);
               ObjectSetText("StochDir",stdir,12,font_ohlc,opsclr);
              }
            //--
            if((opsdn==true) || (opsnt==true))
              {
               //--
               ObjectCreate("StochDir",OBJ_LABEL,0,0,0,0,0);
               ObjectSet("StochDir",OBJPROP_CORNER,corner);
               ObjectSet("StochDir",OBJPROP_XDISTANCE,distance_x-23);
               ObjectSet("StochDir",OBJPROP_YDISTANCE,distance_y-27);
               ObjectSetText("StochDir","WAIT",12,font_ohlc,fbarnt);
              }
           }
         //--
         if(ArrDn==true)
           {
            //--
            if((PvtH==dayHi) && (PvtC<dayHi))
              {
               //--
               cral=2;
               for(int bu=0; bu<psh-pst; bu++)
                 {
                  ObjectCreate("FiboBarUph"+bu,OBJ_LABEL,0,0,0,0,0);
                  ObjectSet("FiboBarUph"+bu,OBJPROP_CORNER,corner);
                  ObjectSet("FiboBarUph"+bu,OBJPROP_XDISTANCE,distance_x+52);
                  ObjectSet("FiboBarUph"+bu,OBJPROP_YDISTANCE,distance_y+fbajs+pst+bu);
                  ObjectSetText("FiboBarUph"+bu,CharToStr(45),font_size,font_face,fbardn);
                 }
              }
            //-
            ObjectCreate(0,"FiboDir",OBJ_LABEL,0,0,0,0,0);
            ObjectSetString(0,"FiboDir",OBJPROP_TEXT,CharToStr(218));
            ObjectSetString(0,"FiboDir",OBJPROP_FONT,"Wingdings");
            ObjectSetInteger(0,"FiboDir",OBJPROP_FONTSIZE,20);
            if((ArrDn==true) && (opsdn==true))
              {ObjectSetInteger(0,"FiboDir",OBJPROP_COLOR,fbardn);}
            else {ObjectSetInteger(0,"FiboDir",OBJPROP_COLOR,fbarnt);}
            ObjectSetInteger(0,"FiboDir",OBJPROP_CORNER,corner);
            ObjectSetInteger(0,"FiboDir",OBJPROP_XDISTANCE,distance_x+66);
            ObjectSetInteger(0,"FiboDir",OBJPROP_YDISTANCE,distance_y-2);
            //--
            if(opsdn==true)
              {
               //--
               cral=-1;
               ObjectCreate("StochDir",OBJ_LABEL,0,0,0,0,0);
               ObjectSet("StochDir",OBJPROP_CORNER,corner);
               ObjectSet("StochDir",OBJPROP_XDISTANCE,distance_x-stax);
               ObjectSet("StochDir",OBJPROP_YDISTANCE,distance_y-27);
               ObjectSetText("StochDir",stdir,12,font_ohlc,opsclr);
              }
            //-
            if((opsup==true) || (opsnt==true))
              {
               //--
               ObjectCreate("StochDir",OBJ_LABEL,0,0,0,0,0);
               ObjectSet("StochDir",OBJPROP_CORNER,corner);
               ObjectSet("StochDir",OBJPROP_XDISTANCE,distance_x-23);
               ObjectSet("StochDir",OBJPROP_YDISTANCE,distance_y-27);
               ObjectSetText("StochDir","WAIT",12,font_ohlc,fbarnt);
              }
           }
        }
     }
//--
   if(ArrUp==true)
     {
      //--
      ObjectCreate(0,"PivotDir",OBJ_LABEL,0,0,0,0,0);
      ObjectSetString(0,"PivotDir",OBJPROP_TEXT,CharToStr(217));
      ObjectSetString(0,"PivotDir",OBJPROP_FONT,"Wingdings");
      ObjectSetInteger(0,"PivotDir",OBJPROP_FONTSIZE,20);
      if((ArrUp==true) && (opsup==true))
        {ObjectSetInteger(0,"PivotDir",OBJPROP_COLOR,fbarup);}
      else {ObjectSetInteger(0,"PivotDir",OBJPROP_COLOR,fbarnt);}
      ObjectSetInteger(0,"PivotDir",OBJPROP_CORNER,corner);
      ObjectSetInteger(0,"PivotDir",OBJPROP_XDISTANCE,distance_x-38);
      ObjectSetInteger(0,"PivotDir",OBJPROP_YDISTANCE,distance_y-2);
     }
//--
   if(ArrDn==true)
     {
      //--
      ObjectCreate(0,"PivotDir",OBJ_LABEL,0,0,0,0,0);
      ObjectSetString(0,"PivotDir",OBJPROP_TEXT,CharToStr(218));
      ObjectSetString(0,"PivotDir",OBJPROP_FONT,"Wingdings");
      ObjectSetInteger(0,"PivotDir",OBJPROP_FONTSIZE,20);
      if((ArrDn==true) && (opsdn==true))
        {ObjectSetInteger(0,"PivotDir",OBJPROP_COLOR,fbardn);}
      else {ObjectSetInteger(0,"PivotDir",OBJPROP_COLOR,fbarnt);}
      ObjectSetInteger(0,"PivotDir",OBJPROP_CORNER,corner);
      ObjectSetInteger(0,"PivotDir",OBJPROP_XDISTANCE,distance_x-38);
      ObjectSetInteger(0,"PivotDir",OBJPROP_YDISTANCE,distance_y-2);
     }
//--
   pos_alerts(cral);
   OnTimer();
   ChartRedraw(0);
   Sleep(500);
   RefreshRates();
//---
   return(0);
  } //--Done!
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   MqlRates rate0[];
   ArraySetAsSeries(rate0,true);
   per=CopyRates(_Symbol,0,0,100,rate0);
   if(per==0) return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void doAlerts(string msgText,string eMailSub)
  {
//--
   if(MsgAlerts) Alert(msgText);
   if(SoundAlerts) PlaySound(SoundAlertFile);
   if(eMailAlerts) SendMail(eMailSub,msgText);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string strTF(int period)
  {
   switch(period)
     {
      //--
      case PERIOD_M1: return("M1");
      case PERIOD_M5: return("M5");
      case PERIOD_M15: return("M15");
      case PERIOD_M30: return("M30");
      case PERIOD_H1: return("H1");
      case PERIOD_H4: return("H4");
      case PERIOD_D1: return("D1");
      case PERIOD_W1: return("W1");
      case PERIOD_MN1: return("MN");
     }
   return(_Period);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void pos_alerts(int alert)
  {
//--
   crmnt=(int)Minute();
   if(crmnt!=prmnt)
     {
      //--
      if((cral!=pral) && (alert==2))
        {
         alBase=StringConcatenate("FiboPivotCandleBar: ",_Symbol,", TF: ",strTF(_Period)," @ ",TimeToStr(TimeLocal()));
         alSubj=StringConcatenate(alBase,". The Price Began to Down,");
         alMsg=StringConcatenate(alSubj," Action: Wait and See.!!");
         prmnt=crmnt;
         pral=cral;
         doAlerts(alMsg,alSubj);
        }
      //--
      if((cral!=pral) && (alert==1))
        {
         alBase=StringConcatenate("FiboPivotCandleBar: ",_Symbol,", TF: ",strTF(_Period)," @ ",TimeToStr(TimeLocal()));
         alSubj=StringConcatenate(alBase,". The Price Goes Up,");
         alMsg=StringConcatenate(alSubj," Action: Open BUY.!!");
         prmnt=crmnt;
         pral=cral;
         doAlerts(alMsg,alSubj);
        }
      //--
      if((cral!=pral) && (alert==-2))
        {
         alBase=StringConcatenate("FiboPivotCandleBar: ",_Symbol,", TF: ",strTF(_Period)," @ ",TimeToStr(TimeLocal()));
         alSubj=StringConcatenate(alBase,". The Price Began to Up,");
         alMsg=StringConcatenate(alSubj," Action: Wait and See.!!");
         prmnt=crmnt;
         pral=cral;
         doAlerts(alMsg,alSubj);
        }
      //--
      if((cral!=pral) && (alert==-1))
        {
         alBase=StringConcatenate("FiboPivotCandleBar: ",_Symbol,", TF: ",strTF(_Period)," @ ",TimeToStr(TimeLocal()));
         alSubj=StringConcatenate(alBase,". The Price Goes Down,");
         alMsg=StringConcatenate(alSubj," Action: Open SELL.!!");
         prmnt=crmnt;
         pral=cral;
         doAlerts(alMsg,alSubj);
        }
     }
//--
   return;
//----
  } //-end pos_alerts()
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---