//+------------------------------------------------------------------+
//|                                                   Littlebadz.mq4 |
//|                                                 Littlebadz Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Littlebadz Corp."
#property link      "http://www.metaquotes.net"

//--- input parameters
extern double    Lots=0.01;
extern int       Profit=30;
extern int       Stopp=90;
extern int       MaxLots=1;
extern int       SmallPeriod=5;
extern int       BigPeriod=20;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   int direction = 0;
//----
   double fiveema = iMA(Symbol(),0,SmallPeriod,0,MODE_EMA,PRICE_TYPICAL,0);
   double twotysma = iMA(Symbol(),0,BigPeriod,0,MODE_SMA,PRICE_TYPICAL,0);
   double fiveemab = iMA(Symbol(),0,SmallPeriod,0,MODE_EMA,PRICE_TYPICAL,1);
   double twotysmab = iMA(Symbol(),0,BigPeriod,0,MODE_SMA,PRICE_TYPICAL,1);


   int total = OrdersTotal();
   double bal = AccountBalance();
   

   
   Comment("   TerminalCompany= ",TerminalCompany(),     // One operator..
         "\n   Broker Time= ",TimeToStr(TimeCurrent(),TIME_SECONDS),
         "\n   Computer Time= ",TimeToStr(TimeLocal(),TIME_SECONDS),    // is located..
         "\n   Account Leverage = 1:",AccountLeverage(),
         "\n   Account Margin = ",AccountMargin(),
         "\n   Account Free Margin = ",AccountFreeMargin(),
         "\n   Account Free Margin Check = ",AccountFreeMarginCheck(Symbol(),OP_BUY,1),
         "\n   Account balance = ",DoubleToStr(AccountBalance(),2),
         "\n   Account Equity = ",DoubleToStr(AccountEquity(),2)
         );


 direction = Crossed(fiveema,twotysma);
 if (total < MaxLots){
 if ( ToStr(fiveemab) == ToStr(twotysmab) && direction == 1){
   //OrderSend(Symbol(),OP_BUY,Lots,Ask, 3,Ask-Stopp*Point,Ask+Profit*Point,
   OrderSend(Symbol(),OP_BUY,Lots,Ask, 3,0,Ask+Profit*Point,
         "LittlebadzEA",777,0,Green);
   }
 
 if (ToStr(fiveemab) == ToStr(twotysmab) && direction == 2){
    //OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stopp*Point,Bid-Profit*Point,
    OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-Profit*Point,
         "LittlebadzEA",777,0,Green);
   }
 }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_dirction = 0;
if(line1>line2)current_dirction = 1; //up
if(line1<line2)current_dirction = 2; //down
if(current_dirction != last_direction) //changed
{
   last_direction = current_dirction;

   return (last_direction);
}
else
{
return (0);
}
}  

//+--------------------------------------------------------------------------------+
//| ToStr function - calls DoubleToString (double, Digits) and returns the string  |
//+--------------------------------------------------------------------------------+
string ToStr(double ValueToString)
   {
   return (DoubleToStr(ValueToString, Digits));
   }

//+--------------------------------------------------------------------------------+   

