
extern double lots = 1;
extern int TP = 100;
extern int SL = 100;
extern int slippage = 10;
extern int magic = 248248;
extern string comment = "Slimcat_v2";
extern int fast_ma_period = 5;
extern int slow_ma_period = 8;
extern int proximity = 140;                   

int digit;
double point;
               
               
double fma;// = iMA(NULL,0,fast_ma_period,0,MODE_SMA,PRICE_CLOSE,0);
double sma;// = iMA(NULL,0,slow_ma_period,0,MODE_SMA,PRICE_CLOSE,0);                    
///-------------------------------------------------------------------------------------------------------------------------------------------
int init() {
 
digit = Digits;
point = Point;


 return (0);
}
///-------------------------------------------------------------------------------------------------------------------------------------------
int start() {
 
gatherer (); 
 
  if (buy_signal()) {
  
     buy();
  }
  if (sell_signal()) {
  
   sell();  
  }
                   
}
///----------------------------------------------------------------------------------------------------------------------------------------------
void gatherer () {

fma = iMA(NULL,0,fast_ma_period,0,MODE_SMA,PRICE_CLOSE,0);
sma = iMA(NULL,0,slow_ma_period,0,MODE_SMA,PRICE_CLOSE,0); 

}
///----------------------------------------------------------------------------------------------------------------------------------------------
bool buy_signal () {
  
if (fma < sma) return (false); //1
if (Bid > fma) return (false); //2

if ((Bid + proximity*point) < sma) {

   return (true);
 
} 
  
return (false);

}
///----------------------------------------------------------------------------------------------------------------------------------------------
bool sell_signal () {

if (fma > sma) return (false);//1
if (Bid < fma) return (false);//2

if ((Bid - proximity*point) > sma) {

   return (true);
 
} 
  
return (false);

}
///----------------------------------------------------------------------------------------------------------------------------------------------
void buy () {
 
 if(trade_exists()) return;
 
double open_price = Ask;
double sl = NormalizeDouble(open_price - SL*point,digit);
double tp = NormalizeDouble(fma + TP*point,digit);

int ticket = OrderSend(Symbol(),OP_BUY,lots,open_price,slippage,sl,tp,comment,magic,0,Blue);
 

}
///----------------------------------------------------------------------------------------------------------------------------------------------
void sell () {

 if(trade_exists()) return;
 
double open_price = Bid;
double sl = NormalizeDouble(open_price + SL*point,digit);
double tp = NormalizeDouble(fma - TP*point,digit);

int ticket = OrderSend(Symbol(),OP_SELL,lots,open_price,slippage,sl,tp,comment,magic,0,Red);

}
///----------------------------------------------------------------------------------------------------------------------------------------------
bool trade_exists () {

for (int i = 0; i < OrdersTotal(); i++) {

 OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
 
 if(OrderSymbol() != Symbol()) continue;
 
 if(OrderMagicNumber() == magic) return (true);

}

return (false);
}
///-------------------------------------------------------------------------------------------------------------------------------------------
int deinit() {
 
 return (0);
}
///-------------------------------------------------------------------------------------------------------------------------------------------