Navigation´╝ÜHome > Content >

FiboCalc__mod.mq4

Time: 2014-02-22 | Download file:FiboCalc__mod.mq4

//+-------------------------------------------------------------------+
//|                                                     FiboCalc_ mod  |
//|                                                                   |
//+-------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DarkGreen
#property indicator_color2 Maroon
#property indicator_color3 Magenta
#property indicator_color4 Goldenrod

extern double buystop=0;
extern double sellstop=0;
//---- buffers
double PrevDayHiBuffer[];
double PrevDayLoBuffer[];
double PrevDayOpenBuffer[];
double PrevDayCloseBuffer[];
//----
int fontsize = 8;
double fb, fs, fbe, fse, tpb1, tpb2, tpb3;
double tps1, tps2, tps3;
double rib, rbe1, rbe2, rbe3, rba1, rba2, rba3;
double ris, rse1, rse2, rse3, rsa1, rsa2, rsa3;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //IndicatorBuffers(4);
//---- indicator line
   SetIndexBuffer(0, PrevDayHiBuffer);
  //SetIndexStyle(0,DRAW_NONE );
   SetIndexBuffer(1, PrevDayLoBuffer);
  // SetIndexStyle(1,DRAW_NONE );
   SetIndexBuffer(2, PrevDayOpenBuffer);
  // SetIndexStyle(2,DRAW_NONE );
   SetIndexBuffer(3, PrevDayCloseBuffer);
  // SetIndexStyle(3,DRAW_NONE );
   SetIndexLabel(0, "PrevDayHigh");
   SetIndexLabel(1, "PrevDayLow");
   SetIndexLabel(2, "PrevDayOpen");
   SetIndexLabel(3, "PrevDayClose");      
//----
   Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("fbe");
   ObjectDelete("fbe Line");
   ObjectDelete("fse");
   ObjectDelete("fse Line");
   ObjectDelete("fs");
   ObjectDelete("fs Line");
   ObjectDelete("tpb3");
   ObjectDelete("tpb3 Line");
   ObjectDelete("tpb2");
   ObjectDelete("tpb2 Line");
   ObjectDelete("tpb1");
   ObjectDelete("tpb1 Line");
   ObjectDelete("tps3");
   ObjectDelete("tps3 Line");
   ObjectDelete("tps2");
   ObjectDelete("tps2 Line");
   ObjectDelete("tps1");
   ObjectDelete("tps1 Line");
   ObjectDelete("fb");
   ObjectDelete("fb Line");
   Comment("");
//----
   return(0);
  }  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() 
  {
   int counted_bars = IndicatorCounted();
   int limit, i;
//---- indicator calculation
   limit = (Bars - counted_bars) - 1;
//----
   for(i = limit; i >= 0; i--)
     {
       if(TimeHour(iTime(NULL,0,i)) != 0)
        {
         PrevDayHiBuffer[i] = PrevDayHiBuffer[i+1];
         PrevDayLoBuffer[i] = PrevDayLoBuffer[i+1];
         PrevDayOpenBuffer[i] = PrevDayOpenBuffer[i+1];
         PrevDayCloseBuffer[i] = PrevDayCloseBuffer[i+1];
         continue;
        }
       int candlesPerDay = PERIOD_D1/Period(),
           day           = MathFloor(i/candlesPerDay);
           
       PrevDayHiBuffer[i] = iHigh(NULL,PERIOD_D1,day+1);
       PrevDayLoBuffer[i] = iLow(NULL,PERIOD_D1,day+1);
       PrevDayOpenBuffer[i] = iOpen(NULL,PERIOD_D1,day+1);
       PrevDayCloseBuffer[i] = iClose(NULL,PERIOD_D1,day+1);
     }
       ObjectDelete("fbe");
       ObjectDelete("fbe Line");
       ObjectDelete("fse");
       ObjectDelete("fse Line");
       ObjectDelete("fs");
       ObjectDelete("fs Line");
       ObjectDelete("tpb3");
       ObjectDelete("tpb3 Line");
       ObjectDelete("tpb2");
       ObjectDelete("tpb2 Line");
       ObjectDelete("tpb1");
       ObjectDelete("tpb1 Line");
       ObjectDelete("tps3");
       ObjectDelete("tps3 Line");
       ObjectDelete("tps2");
       ObjectDelete("tps2 Line");
       ObjectDelete("tps1");
       ObjectDelete("tps1 Line");
       ObjectDelete("fb");
       ObjectDelete("fb Line");
       fb = PrevDayHiBuffer[0] - (PrevDayHiBuffer[0] - PrevDayLoBuffer[0])*0.382;
       if(buystop==0) fbe = PrevDayHiBuffer[0] - (PrevDayHiBuffer[0] - PrevDayLoBuffer[0])*0.618;
       else fbe=buystop;
       tpb1 = ((PrevDayHiBuffer[0] - PrevDayLoBuffer[0])*0.618) + fb;
       tpb2 = (PrevDayHiBuffer[0] - PrevDayLoBuffer[0]) + fb;
       tpb3 = 1.618*(PrevDayHiBuffer[0] - PrevDayLoBuffer[0]) + fb;
       rib = MathRound((fb - fbe)*10000) / 10000;
       rbe1=MathRound((tpb1 - fb)*10000) / 10000;
       rbe2=MathRound((tpb2 - fb)*10000) / 10000;
       rbe3=MathRound((tpb3 - fb)*10000) / 10000;
       rba1=MathRound((rbe1 / rib)*10) / 10;
       rba2=MathRound((rbe2 / rib)*10) / 10;
       rba3=MathRound((rbe3 / rib)*10) / 10;
       //----
       if(ObjectFind("fb") != 0)
         {
           ObjectCreate("fb", OBJ_TEXT, 0, Time[0], fb);
           ObjectSetText("fb", " BUY LEVEL", 8, "Arial", EMPTY);
         }
       else
         {
           ObjectMove("fb",fb, Time[0], fb);
         }
       //----
       
       if(ObjectFind("fb Line") != 0)
         {
           ObjectCreate("fb Line", OBJ_HLINE, 0, Time[0],fb);
           ObjectSet("fb Line", OBJPROP_STYLE, STYLE_DASHDOT);
           ObjectSet("fb Line", OBJPROP_COLOR, Blue);
         }
       else
         {
           ObjectMove("fb Line",0, Time[0], fb);
         }
       //----
       fs = (PrevDayHiBuffer[0] - PrevDayLoBuffer[0])*0.382 + (PrevDayLoBuffer[0]);
       if(sellstop==0) fse = (PrevDayHiBuffer[0] - PrevDayLoBuffer[0])*0.618 + (PrevDayLoBuffer[0]);
       else fse=sellstop;
       tps1 = ((PrevDayLoBuffer[0] - PrevDayHiBuffer[0])*0.618) + fs;
       tps2 = (PrevDayLoBuffer[0] - PrevDayHiBuffer[0]) + fs;
       tps3 = 1.618*(PrevDayLoBuffer[0] - PrevDayHiBuffer[0]) + fs;
       ris = MathRound((fs - fse)*10000) / 10000;
       rse1 = MathRound((tps1 - fs)*10000) / 10000;
       rse2 = MathRound((tps2 - fs)*10000) / 10000;
       rse3 = MathRound((tps3 - fs)*10000) / 10000;
       rsa1 = MathRound((rse1 / ris)*10) / 10;
       rsa2 = MathRound((rse2 / ris)*10) / 10;
       rsa3 = MathRound((rse3 / ris)*10) / 10;
       //----
       if(ObjectFind("fs") != 0)
         {
           ObjectCreate("fs", OBJ_TEXT, 0, Time[0], fs);
           ObjectSetText("fs", " SELL LEVEL", 8, "Arial", EMPTY);
         }
       else
         {
           ObjectMove("fs",fs, Time[0], fs);
         }
       //----
       if(ObjectFind("fs Line") != 0)
         {
           ObjectCreate("fs Line", OBJ_HLINE, 0, Time[0],fs);
           ObjectSet("fs Line", OBJPROP_STYLE, STYLE_DASHDOT);
           ObjectSet("fs Line", OBJPROP_COLOR, Red);
         }
       else
         {
           ObjectMove("fs Line",0, Time[0], fs);
         }
       //----
       string Comm;
       Comm="Owner : "+AccountName()+"\nAccount number : "+AccountNumber()+
       "\n\nPrevDayHigh "+DoubleToStr(PrevDayHiBuffer[0],Digits)+"\nPrevDayLow "+DoubleToStr(PrevDayLoBuffer[0],Digits)+
       "\n\nBUY @ "+DoubleToStr(fb,Digits)+"\nBuyStopLoss "+DoubleToStr(fbe,Digits)+"";
       if(rba1>2) Comm=Comm+"\nBuyTakeProit 1 "+DoubleToStr(tpb1,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rba1,1)+"  OK Trade";
       else Comm=Comm+"\nBuyTakeProit 1 "+DoubleToStr(tpb1,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rba1,1)+"  NO Trade";
       if(rba2>2) Comm=Comm+"\nBuyTakeProit 2 "+DoubleToStr(tpb2,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rba2,1)+"  OK Trade";
       else Comm=Comm+"\nBuyTakeProit 2 "+DoubleToStr(tpb2,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rba2,1)+"  NO Trade";
       if(rba3>2) Comm=Comm+"\nBuyTakeProit 3 "+DoubleToStr(tpb3,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rba3,1)+"  OK Trade";
       else Comm=Comm+"\nBuyTakeProit 3 "+DoubleToStr(tpb3,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rba3,1)+"  NO Trade";
       Comm=Comm+"\n\nSELL @ "+DoubleToStr(fs,Digits)+"\nSellStopLoss "+DoubleToStr(fse,Digits)+"";
       if(rsa1>2) Comm=Comm+"\nSellTakeProit 1 "+DoubleToStr(tps1,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rsa1,1)+"  OK Trade";
       else Comm=Comm+"\nSellTakeProit 1 "+DoubleToStr(tps1,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rsa1,1)+"  NO Trade";
       if(rsa2>2) Comm=Comm+"\nSellTakeProit 2 "+DoubleToStr(tps2,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rsa2,1)+"  OK Trade";
       else Comm=Comm+"\nSellTakeProit 2 "+DoubleToStr(tps2,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rsa2,1)+"  NO Trade";
       if(rsa3>2) Comm=Comm+"\nSellTakeProit 3 "+DoubleToStr(tps3,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rsa3,1)+"  OK Trade";
       else Comm=Comm+"\nSellTakeProit 3 "+DoubleToStr(tps3,Digits)+"  Risk/Reward Ratio : "+DoubleToStr(rsa3,1)+"  NO Trade";
       Comment(Comm); 
//----
   if(buystop!=0)
    {
     if(ObjectFind("fbe") != 0)
      {
       ObjectCreate("fbe", OBJ_TEXT, 0, Time[0], fbe);
       ObjectSetText("fbe", " BUY STOP LEVEL", 8, "Arial", EMPTY);
      }
     else
      {
       ObjectMove("fbe",fbe, Time[0], fbe);
      }
//----
     if(ObjectFind("fbe Line") != 0)
      {
       ObjectCreate("fbe Line", OBJ_HLINE, 0, Time[0],fbe);
       ObjectSet("fbe Line", OBJPROP_STYLE, STYLE_DASHDOT);
       ObjectSet("fbe Line", OBJPROP_COLOR, OrangeRed );
      }
     else
      {
       ObjectMove("fbe Line",0, Time[0], fbe);
      }
    }
//----     
   if(sellstop!=0)
    {
     if(ObjectFind("fse") != 0)
      {
       ObjectCreate("fse", OBJ_TEXT, 0, Time[0], fse);
       ObjectSetText("fse", " SELL STOP LEVEL", 8, "Arial", EMPTY);
      }
     else
      {
       ObjectMove("fse",fse, Time[0], fse);
      }
//----
     if(ObjectFind("fse Line") != 0)
      {
       ObjectCreate("fse Line", OBJ_HLINE, 0, Time[0],fse);
       ObjectSet("fse Line", OBJPROP_STYLE, STYLE_DASHDOT);
       ObjectSet("fse Line", OBJPROP_COLOR, OrangeRed );
      }
     else
      {
       ObjectMove("fse Line",0, Time[0], fse);
      }
    }  
//----
   if(ObjectFind("tpb1") != 0)
     {
       ObjectCreate("tpb1", OBJ_TEXT, 0, Time[0], tpb1);
       ObjectSetText("tpb1", " BUY PROFIT TARGET 1", 8, "Arial", EMPTY);
     }
   else
     {
       ObjectMove("tpb1",tpb1, Time[0],tpb1 );
     }
//----
   if(ObjectFind("tpb1 Line") != 0)
     {
       ObjectCreate("tpb1 Line", OBJ_HLINE, 0, Time[0],tpb1);
       ObjectSet("tpb1 Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
       ObjectSet("tpb1 Line", OBJPROP_COLOR, SpringGreen );
     }
   else
     {
       ObjectMove("tpb1 Line",0, Time[0],tpb1 );
     }
//----
   if(ObjectFind("tpb2") != 0)
     {
       ObjectCreate("tpb2", OBJ_TEXT, 0, Time[0], tpb2);
       ObjectSetText("tpb2", " BUY PROFIT TARGET 2", 8, "Arial", EMPTY);
     }
   else
     {
       ObjectMove("tpb2",tpb2, Time[0],tpb2);
     }
   if(ObjectFind("tpb2 Line") != 0)
     {
       ObjectCreate("tpb2 Line", OBJ_HLINE, 0, Time[0],tpb2);
       ObjectSet("tpb2 Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
       ObjectSet("tpb2 Line", OBJPROP_COLOR, SpringGreen );
     }
   else
     {
        ObjectMove("tpb2 Line",0, Time[0],tpb2);
     }
//----
   if(ObjectFind("tpb3") != 0)
     {
       ObjectCreate("tpb3", OBJ_TEXT, 0, Time[0], tpb3);
       ObjectSetText("tpb3", " BUY PROFIT TARGET 3", 8, "Arial", EMPTY);
     }
   else
     {
       ObjectMove("tpb3",tpb3, Time[0], tpb3);
     }
//----
   if(ObjectFind("tpb3 Line") != 0)
     {
       ObjectCreate("tpb3 Line", OBJ_HLINE, 0, Time[0],tpb3);
       ObjectSet("tpb3 Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
       ObjectSet("tpb3 Line", OBJPROP_COLOR, SpringGreen );
     }
   else
     {
       ObjectMove("tpb3 Line",0, Time[0],tpb3);
     }
//----
   if(ObjectFind("tps1") != 0)
     {
       ObjectCreate("tps1", OBJ_TEXT, 0, Time[0], tps1);
       ObjectSetText("tps1", " SELL PROFIT TARGET 1", 8, "Arial", EMPTY);
     }
   else
     {
       ObjectMove("tps1",tps1, Time[0],tps1 );
     }
//----
   if(ObjectFind("tps1 Line") != 0)
     {
       ObjectCreate("tps1 Line", OBJ_HLINE, 0, Time[0],tps1);
       ObjectSet("tps1 Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
       ObjectSet("tps1 Line", OBJPROP_COLOR, SpringGreen );
     }
   else
     {
       ObjectMove("tps1 Line",0, Time[0],tps1 );
     }
//----
   if(ObjectFind("tps2") != 0)
     {
       ObjectCreate("tps2", OBJ_TEXT, 0, Time[0], tps2);
       ObjectSetText("tps2", " SELL PROFIT TARGET 2", 8, "Arial", EMPTY);
     }
   else
     {
       ObjectMove("tps2",tps2, Time[0],tps2);
     }
   if(ObjectFind("tps2 Line") != 0)
     {
       ObjectCreate("tps2 Line", OBJ_HLINE, 0, Time[0],tps2);
       ObjectSet("tps2 Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
       ObjectSet("tps2 Line", OBJPROP_COLOR, SpringGreen );
     }
   else
     {
        ObjectMove("tps2 Line",0, Time[0],tps2);
     }
//----
   if(ObjectFind("tps3") != 0)
     {
       ObjectCreate("tps3", OBJ_TEXT, 0, Time[0], tps3);
       ObjectSetText("tps3", " SELL PROFIT TARGET 3", 8, "Arial", EMPTY);
     }
   else
     {
       ObjectMove("tps3",tps3, Time[0], tps3);
     }
//----
   if(ObjectFind("tps3 Line") != 0)
     {
       ObjectCreate("tps3 Line", OBJ_HLINE, 0, Time[0],tps3);
       ObjectSet("tps3 Line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
       ObjectSet("tps3 Line", OBJPROP_COLOR, SpringGreen );
     }
   else
     {
       ObjectMove("tps3 Line",0, Time[0],tps3);
     }
//----     
   return(0);
  }
//+------------------------------------------------------------------+

Recommend