//+------------------------------------------------------------------+
//|                                                       Spread.mq4 |
//|                                  Copyright © 2009, Andriy Moraru |
//+------------------------------------------------------------------+
//|                                                     spreader.mq4 |
//|                    Copyright © 2008, syanwar (www.viking234.com) |
//|                                              admin@viking234.biz |
//+------------------------------------------------------------------+
//|                                        Pip Value&Spread Alert.mq4|
//|       Add Spread Alert + Min Lot + Swap + Pip Value = ? %Balance |
//|                                    by Cmkm-2012[thhudu@yahoo.com]|
//|             version 2 : % account can calculated on input Balance|
//+------------------------------------------------------------------+
//|version3 :Pip Value+Swap+Min Lot+Spread Alert +Virtual Balance.mq4|
//|       Add Virtual Room -Turn your Real Balance to Virtual Balance|
//|Practice how many time you want with the "Balance level" you like | 
//|                                       [psychological steady Tool]|
//|                                    by Cmkm-2012[thhudu@yahoo.com]|
//+------------------------------------------------------------------+
#property copyright "Cmkm-2012[thhudu@yahoo.com]"
#property link  "All my indicators: http://www.forexfactory.com/showthread.php?t=325434"

#property indicator_chart_window

//---- alert
extern int    Alert_Spread = 7;
//---- alert
extern string _________Pip_Value_Of_Lot="Lot = 0 ( MinLot )";
extern double Lot=0;
extern int nPip=10;
extern string _=".";

extern string ______________Virtual.Room="Your.Balance=0 => MT4 Balance"; 
extern double  Your.Balance =0;
extern double  Switch.To.Virtual.Balance =0;

extern string _________="_________";
extern bool Show.Swap = False;
extern int corner = 2; //0 ,1 ,2 ,3

bool normalize = true; //If true then the spread is normalized to traditional pips
color font_color = PaleGreen;
string font = "Arial";
int font_size = 9;

double Poin;
int n_digits = 0;
double divider = 1;

//+-----------------------------------------+
int init()
{
   //Checking for unconvetional Point digits number
   if (Point == 0.00001) Poin = 0.0001; //5 digits
   else if (Point == 0.001) Poin = 0.01; //3 digits
   else Poin = Point; //Normal
   
   ObjectCreate("Spread", OBJ_LABEL, 0, 0, 0);
   ObjectSet("Spread", OBJPROP_CORNER, corner);
   ObjectSet("Spread", OBJPROP_XDISTANCE, 5);
   ObjectSet("Spread", OBJPROP_YDISTANCE, 15);
   double spread = MarketInfo(Symbol(), MODE_SPREAD);
   
   if ((Poin > Point) && (normalize))
   {
      divider = 10.0;
      n_digits = 1;
   }
   
   return(0);
}
//+-----------------------------------------+

int deinit()
{
   ObjectDelete("Spread");
   ObjectDelete("Swap");

   return(0);
}
//+-----------------------------------------+

int start()
{     
  int Virtual=Switch.To.Virtual.Balance;
  if (Virtual==0){Virtual=Your.Balance;}
//--------Lot-------
   double MinLot =MarketInfo(Symbol(), MODE_MINLOT);
   if (Lot<0.01){Lot=MinLot;}
   //-----Lot digits----
   int Lot_digits = 1;
   if (Lot<0.1){Lot_digits=2;}
   
//--------Pip-Lot-------

   double Pip_Lot=MarketInfo(Symbol(), MODE_TICKVALUE)/10;
   if (Lot<=0.01){ Pip_Lot=Pip_Lot;}
     else{Pip_Lot=Pip_Lot*Lot/MinLot;}
     
//--------Spread n Pip Value-------  
   RefreshRates();

   if (Your.Balance==0){ Your.Balance = AccountBalance();}  //--------Account Balance------- 
                   
   double spread = (Ask - Bid) / Point;

   ObjectSetText("Spread", "Spread = " + DoubleToStr(NormalizeDouble(spread / divider, 1), n_digits )+ " pips"+ //Spread
                 " | "+nPip+" Pip = " + DoubleToStr((Pip_Lot*nPip)*Virtual/Your.Balance,1)+ " $ ( "+        //Pip value
                 DoubleToStr((Pip_Lot*nPip)*100/Your.Balance,1)+" % Acc) [ "+          //% Your.Balance
                 DoubleToStr(Lot,Lot_digits)+" Lot ]", font_size, font, font_color);  //Of Lot
    
//--------alert-------
       int Spread_digit=NormalizeDouble(spread / divider, 1), n_digits;

       if(Spread_digit > Alert_Spread) {
       Alert(Symbol()+"  spread=  "+Spread_digit);}
//--------Swap-------
  if (Show.Swap==true) { // on/off show swap (only this line)
   ObjectCreate("Swap", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Swap","Swap Long =  "+DoubleToStr(MarketInfo(Symbol(), MODE_SWAPLONG),1)+ " $"+
                 "   |  Swap Short =  "+DoubleToStr(MarketInfo(Symbol(), MODE_SWAPSHORT),1)+ " $", font_size, font, White);
   ObjectSet("Swap", OBJPROP_CORNER, corner);
   ObjectSet("Swap", OBJPROP_XDISTANCE, 5);
   ObjectSet("Swap", OBJPROP_YDISTANCE, 32); }
//+-----------------------------------------+
return(0);
}