//+------------------------------------------------------------------+
//|                                                 #MarketPrice.mq4 |
//|                                                       ServerUang |
//|                                    http://www.indofx-trader.net/ |
//+------------------------------------------------------------------+
#property copyright "ServerUang"
#property link      "http://www.indofx-trader.net/"

#property indicator_chart_window

extern string Indicator_Name = "#MarketPrice";
extern bool Right_Top = true;
extern int Shift_Y = 0; 
extern int Shift_X = 0;

// Untuk menentukan Warna Harga sesuai arah Trend
extern string Price_Variable = "Setting for Price Color" ; // change
extern color Price_color_Up = Blue;
extern color Price_color_Dn = Red;
extern int Time_Frame=15;

extern int MA_Fast_Period = 1; 
extern int MA_Fast_Method = 0; 
extern int MA_Fast_Apply_To = 0;
extern int MA_Fast_Shift = 0;

extern int MA_Slow_Period = 5; 
extern int MA_Slow_Method = 0;
extern int MA_Slow_Apply_To = 1;
extern int MA_Slow_Shift = 0;

extern string Value_Color ="Setting for Value Color";
extern color Highest_Color          = White;
extern color Distance_from_Highest_Color = Gainsboro;
extern color Lowest_Color           = Yellow;
extern color Distance_from_Lowest_Color  = Gold;
extern color Hi_to_Lo_Color         = LightGray;
extern color Daily_Av_Up_Color      = Lime;
extern color Daily_Av_Dn_Color      = Orange;
extern color Time_n_Spread_Color    = Aqua;
extern color PipsToOpen_Up_Color    = LightSkyBlue;
extern color PipsToOpen_Dn_Color    = Salmon;

extern string Xtra_Information = "Setting for Extra information"; 

extern bool  Show_Xtra_Info    = true;

extern string CCi_Parameters      = "CCi Parameters";
extern int   CCI_period           = 24; 
extern color Label_color          = Silver;
extern color Text_Xtreme_Up_Color = White;
extern color Text_Up_Color        = LightBlue;
extern color Text_Dn_Color        = Orange;
extern color Text_Xtreme_Dn_Color = Yellow;

// Input Parameter utk Bollinger Bands
extern string Bands_Parameters = "Bollinger Bands Parameters" ; // change
extern int Periode = 20;
extern int Deviation = 2;
extern int Bands_shift = 0;
extern int Applied_price = PRICE_CLOSE;
extern color Bands_ExtremePlus_Color = Aqua;
extern color Bands_Plus_Color = DodgerBlue;
extern color Bands_PlusMid_Color = Blue;
extern color Bands_Mid_Color = Silver;
extern color Bands_MinMid_Color = Red;
extern color Bands_Minus_Color = DarkOrange;
extern color Bands_ExtremeMinus_Color = Yellow;

// Untuk menentukan arah Trend
extern string Trend_Variable = "Variable TRend Direction" ; // change
extern int   xMA_Fast_Period     = 1; 
extern int   xMA_Fast_Method     = 0; 
extern int   xMA_Fast_Apply_To   = 0;
extern int   xMA_Fast_Shift      = 0;

extern int   xMA_Slow_Period     = 24; 
extern int   xMA_Slow_Method     = 0;
extern int   xMA_Slow_Apply_To   = 6;
extern int   xMA_Slow_Shift      = 0;
extern color Trend_Up_Color     = Blue;
extern color Trend_Dn_Color     = Red;
//=================================================================================
string Label_Teks="", Huruf="", Teks="", nomor="";
double Nilai, x, y, d_A, d_B, TF, Range, bbP, bbMid, bbM, nilaiWarnaCandle;
color  WarnaHarga, WarnaTrend, WarnaCandle;
int    Ukuran, n, Kolom;

// --- variabel Daili_Av --------------------------------------------
int    R1, R5, R10, R20, RAvg, i;
string Teks_ReRata = "", Teks_Rerata_Kemarin ="", Nomor="";
color  Warna_ReRata;

// --- Variabel Time for next candle
string Teks_Menit, Teks_Detik;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll(0,OBJ_HLINE);
   ObjectsDeleteAll(0,OBJ_TEXT);
   ObjectsDeleteAll(0,OBJ_LABEL);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   int    counted_bars=IndicatorCounted();
   
   //Menampilkan Harga
   Nilai=iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0); Teks=DoubleToStr(Nilai,Digits);
   Huruf="Arial"; Ukuran=34; x=09+Shift_X; y=22+Shift_Y;
   // WarnaHarga=WarnaLampu pada trend TF 5 menit
   d_B = iMA(Symbol(),Time_Frame,MA_Fast_Period,MA_Fast_Shift,MA_Fast_Method,MA_Fast_Apply_To,0);
   d_A = iMA(Symbol(),Time_Frame,MA_Slow_Period,MA_Slow_Shift,MA_Slow_Method,MA_Slow_Apply_To,0);
   WarnaHarga=CheckWarna(d_B, d_A, Price_color_Up, Price_color_Dn);
   Tulis("MP01", Right_Top, x, y, Teks, Ukuran, Huruf, WarnaHarga);

   Huruf="Tahoma Bold"; Ukuran=10; 
   //Menampilkan Highest
   d_A=iHigh(NULL,1440,0); Teks=DoubleToStr(d_A, Digits);
   x=100+Shift_X; y=14+Shift_Y;
   Tulis("MP02", Right_Top, x, y, Teks, Ukuran, Huruf, Highest_Color);
   
   //Menampilkan Lowest
   d_B=iLow(NULL,1440,0); Teks=DoubleToStr(d_B, Digits);
   x=100+Shift_X; y=62+Shift_Y;
   Tulis("MP03", Right_Top, x, y, Teks, Ukuran, Huruf, Lowest_Color);
   
   //--- Informasi Distance from Highest ---
   Teks=DoubleToStr((Nilai-d_A)/Point,0);
   x=56+Shift_X; y=14+Shift_Y;
   Tulis("MP04", Right_Top, x, y, Teks, Ukuran, Huruf, Distance_from_Highest_Color);
   
   //--- Informasi Distance from Lowest ---
   Teks=DoubleToStr((Nilai-d_B)/Point,0);
   x=56+Shift_X; y=62+Shift_Y;
   Tulis("MP05", Right_Top, x, y, Teks, Ukuran, Huruf, Distance_from_Lowest_Color);
   
   //--- Informasi Hi to Lo ---
   Teks=DoubleToStr((d_A - d_B)/Point,0);
   x=10+Shift_X; y=14+Shift_Y;
   Tulis("MP06", Right_Top, x, y, Teks, Ukuran, Huruf, Hi_to_Lo_Color);
   
   //--- Informasi Daily Av ---
   R1=0; R5=0; R10=0; R20=0; RAvg=0; i=0;
   R1 =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
   for(i=1;i<=5;i++)   
     R5  = R5  + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=10;i++)
     R10 = R10 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=20;i++)
     R20 = R20 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

   R5 = R5/5;
   R10 = R10/10;
   R20 = R20/20;
   RAvg  =  (R1+R5+R10+R20)/4;    
   
   Teks_ReRata = (DoubleToStr(RAvg,Digits-4));
   Teks_Rerata_Kemarin = (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
   
   if (Teks_ReRata > Teks_Rerata_Kemarin) {Warna_ReRata = Daily_Av_Up_Color;}
      else {Warna_ReRata = Daily_Av_Dn_Color;}
      
   x=10+Shift_X; y=62+Shift_Y;
   Tulis("MP07", Right_Top, x, y, Teks_ReRata, Ukuran, Huruf, Warna_ReRata);
   
   //Time for Next Candle
   d_B = (Time[4]-Time[5])-MathMod(CurTime(),Time[4]-Time[5]);
   d_A = d_B/60;
   d_B = (d_A-MathFloor(d_A))*60;
   d_A = MathFloor(d_A);
   Teks_Menit = DoubleToStr(d_A,0);
   Teks_Detik = DoubleToStr(d_B,0);
   Teks=Teks_Menit+":"+Teks_Detik;
   x=100+Shift_X; y=74+Shift_Y;
   Tulis("MP08", Right_Top, x, y, Teks, Ukuran, Huruf, Time_n_Spread_Color);
   
   // --- Spread
   d_A = (Ask - Bid)/Point;
   Teks = (DoubleToStr(d_A,Digits-4));
   x=56+Shift_X; y=74+Shift_Y;
   Tulis("MP09", Right_Top, x, y, Teks, Ukuran, Huruf, Time_n_Spread_Color);
   
   //--- Informasi from Pips to Open ---
   d_A = iOpen(NULL,1440,0);
   d_B = iClose(NULL,1440,0);
   WarnaHarga=CheckWarna(d_B, d_A, PipsToOpen_Up_Color, PipsToOpen_Dn_Color);
   Teks=DoubleToStr((d_B-d_A)/Point,0);
   x=10+Shift_X; y=74+Shift_Y;
   Tulis("MP10", Right_Top, x, y, Teks, Ukuran, Huruf, WarnaHarga);
   
   //--- Show_Xtra_Info ---
   if (Show_Xtra_Info)
      {//--- Info CCi ---
       Huruf="Tahoma Narrow"; Ukuran=7;
       if (Right_Top) {Teks="M1   M5  M15  M30  H1     H4";}
                 else {Teks="H4     H1   M30  M15  M5  M1";}
       x=10+Shift_X; y=88+Shift_Y+4;
       Tulis("MP11", Right_Top, x, y, Teks, Ukuran, Huruf, Label_color);
       Tulis("MP12", Right_Top, x+122, y+11,  "CCi", Ukuran, Huruf, Label_color);
       Tulis("MP13", Right_Top, x+123, y+21, "BB", Ukuran, Huruf, Label_color);
       Tulis("MP14", Right_Top, x+124, y+31, "TR", Ukuran, Huruf, Label_color);
       Tulis("MP15", Right_Top, x+123, y+41, "BS", Ukuran, Huruf, Label_color);
       Tulis("MP16", Right_Top, x+123, y+51, "CC", Ukuran, Huruf, Label_color);
       n=1;
       while (n<=6)
         {
          switch (n)
             {
              case 1: TF =    1;  Range=2; break;
              case 2: TF =    5;  Range=(Ask - Bid)/Point; break;
              case 3: TF =   15;  Range=(Ask - Bid)/Point; break;
              case 4: TF =   30;  Range=(Ask - Bid)/Point; break;
              case 5: TF =   60;  Range=(Ask - Bid)/Point; break;
              case 6: TF =  240;  Range=(Ask - Bid)/Point; break;
              //case 7: TF = 1440;  break;
             }//switch
          
          nomor=DoubleToStr(n,0); x=130+Shift_X; y=98+Shift_Y+4; Kolom=20;
          Nilai=iCCI(Symbol(),TF,CCI_period,0,0); Teks=DoubleToStr(Nilai,0);
          Huruf="Tahoma"; Ukuran=8; WarnaHarga=CheckWarnaAngka(Nilai, 200, 0, -200);
          Tulis("MP17"+nomor, Right_Top, x-(n*Kolom), y, Teks, Ukuran, Huruf, WarnaHarga);
          
          Huruf="Arial Bold"; Ukuran=30;
          bbP   = iBands(Symbol(),TF,Periode,Deviation,Bands_shift,Applied_price,MODE_PLUSDI,0);
          bbMid = iBands(Symbol(),TF,Periode,Deviation,Bands_shift,Applied_price,MODE_MAIN,0);
          bbM   = iBands(Symbol(),TF,Periode,Deviation,Bands_shift,Applied_price,MODE_MINUSDI,0);
          Check_Bands("MP18"+nomor, x-(n*Kolom), y-10, bbP, bbMid, bbM, Range);
          
          //TRend
          d_B = iMA(Symbol(),TF, xMA_Fast_Period, xMA_Fast_Shift, xMA_Fast_Method, xMA_Fast_Apply_To,0);
          d_A = iMA(Symbol(),TF, xMA_Slow_Period, xMA_Slow_Shift, xMA_Slow_Method, xMA_Slow_Apply_To,0);
          WarnaTrend=CheckWarna(d_B, d_A, Trend_Up_Color, Trend_Dn_Color);
          Tulis("MP19"+nomor, Right_Top, x-(n*Kolom), y, "-", Ukuran, Huruf, WarnaTrend);
          
          //BuySeLL
          //d_B = iMA(Symbol(),TF, 1, 0, 0, 0, 0);
          //d_A = iMA(Symbol(),TF, 5, 0, 0, 0, 0);
          d_B = iMA(Symbol(),TF,MA_Fast_Period,MA_Fast_Shift,MA_Fast_Method,MA_Fast_Apply_To,0);
          d_A = iMA(Symbol(),TF,MA_Slow_Period,MA_Slow_Shift,MA_Slow_Method,MA_Slow_Apply_To,0);
          WarnaTrend=CheckWarna(d_B, d_A, Trend_Up_Color, Trend_Dn_Color);
          Tulis("MP20"+nomor, Right_Top, x-(n*Kolom), y+10, "-", Ukuran, Huruf, WarnaTrend);
          
          //Candle_Color
          nilaiWarnaCandle = iClose( NULL , TF, 0) - iOpen( NULL , TF, 0);
          
          if ( nilaiWarnaCandle > 0 ) WarnaCandle = Bands_PlusMid_Color; 
          else {
          if ( nilaiWarnaCandle < 0 )  WarnaCandle = Bands_MinMid_Color; 
          else WarnaCandle = Bands_Mid_Color; }
          Tulis("MP21"+nomor, Right_Top, x-(n*Kolom), y+20, "-", Ukuran, Huruf, WarnaCandle);
          
          
          //Huruf="Tahoma Narrow"; Ukuran=7; x=10+Shift_X; y=88+Shift_Y+44;
          //Tulis("MP20", Right_Top, x, y, "Created by ServerUang", Ukuran, Huruf, Gray);
          n++;   
         }//while
      }//Show
   else 
      {
       Huruf="Tahoma Narrow"; Ukuran=7; x=10+Shift_X; y=88+Shift_Y+4;
       Tulis("MP19", Right_Top, x, y, "Created by ServerUang", Ukuran, Huruf, Gray);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Prosedur Tulis
void Tulis(string LBL, double sebelah, int pos_x, int pos_y, string teks, int ukuran_huruf, string nama_huruf, color warna=CLR_NONE)
     {
       Label_Teks=LBL;
       ObjectCreate(LBL, OBJ_LABEL, 0, 0, 0);
       ObjectSetText(LBL,teks, ukuran_huruf, nama_huruf, warna);
       ObjectSet(LBL, OBJPROP_CORNER, sebelah);
       ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
       ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
     }

// Function CheckWarna
color CheckWarna(double a, double b, color U, color D)
      {
        if (a>b) { return (U); } else { return (D); }
      } 
      
// Function CheckWarnaAngka
color  CheckWarnaAngka(double n, double BatasAtas, double BatasTengah, double BatawBawah)
         {
          if (n > BatasAtas) {return (Text_Xtreme_Up_Color);}
          else if ( (n <= (BatasAtas-1)) && (n > BatasTengah) )  {return (Text_Up_Color);}
          else if ( (n <= (BatasTengah-1)) && (n > BatawBawah) )  {return (Text_Dn_Color);}
          else {return (Text_Xtreme_Dn_Color);}
         }      
         
// Prosedure Mengecek warna BollingerBands
void Check_Bands(string LBL, int px, int py, double bbPs, double bbMids, double bbMs, int Ranges)
     {
      if( Bid > bbPs+(Ranges*Point)) 
           {Teks=DoubleToStr(bbPs,0); Tulis(LBL, Right_Top, px, py, "-", Ukuran, Huruf, Bands_ExtremePlus_Color);}
      
      else if( (Bid <= bbPs+(Ranges*Point)) && (Bid >= bbPs-(Ranges*Point)) )
           {Teks=DoubleToStr(bbPs,0); Tulis(LBL, Right_Top, px, py+0, "-", Ukuran, Huruf, Bands_Plus_Color);
           //Tulis(LBL+"a", Right_Top, px, py+80, DoubleToStr(bbPs,2), 7, "Tahoma Narrow", White);
           }  
      
      else if( (Bid < bbPs-(Ranges*Point)) && (Bid > bbMids+(Ranges*Point)))
           {Teks=DoubleToStr(bbMids,0); Tulis(LBL, Right_Top, px, py, "-", Ukuran, Huruf, Bands_PlusMid_Color);}
             
      else if( (Bid <= bbMids+(Ranges*Point)) && (Bid >= bbMids-(Ranges*Point)))
           {Teks=DoubleToStr(bbMids,0); Tulis(LBL, Right_Top, px, py, "-", Ukuran, Huruf, Bands_Mid_Color);}

        
      else if( (Bid < bbMids-(Ranges*Point)) && (Bid > bbMs+(Ranges*Point)))
           {Teks=DoubleToStr(bbMids,0); Tulis(LBL, Right_Top, px, py, "-", Ukuran, Huruf, Bands_MinMid_Color);}
      
      else if( (Bid <= bbMs+(Ranges*Point)) && (Bid >= bbMs-(Ranges*Point)))
           {Teks=DoubleToStr(bbMs,0); Tulis(LBL, Right_Top, px, py, "-", Ukuran, Huruf, Bands_Minus_Color);}
           
      else if( Bid < bbMs-(Ranges*Point))
           {Teks=DoubleToStr(bbMs,0); Tulis(LBL, Right_Top, px, py, "-", Ukuran, Huruf, Bands_ExtremeMinus_Color);}

     }         