#property copyright "Modifed by Marsya7"
#property link      "http://www.kgforexworld.com"

#include <stderror.mqh>
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| script "transaksi untuk semua pairs"                             |
//+------------------------------------------------------------------+

bool MM = true;
int Risk       = 100,
    TakeProfit = 1000,
    StopLoss   = 1000;
double MinLot = 0.01;
int leverage;
double gd_200, dPoint;

int start()
  {
   /* Bila chartnya adalah broker 5 Digit maka Point dikali 10 */
   if (Digits==3 || Digits==5)
   {
      dPoint=Point*10;
   }
   else
   {
      dPoint=Point;
   } 
//----
   int slip = (MarketInfo(Symbol(), MODE_ASK) - MarketInfo(Symbol(), MODE_BID)) / MarketInfo(Symbol(), MODE_POINT);
   int ticket=OrderSend(Symbol(),OP_SELL,Lots(),Bid,slip,Ask+StopLoss*dPoint,Bid-TakeProfit*dPoint,"Sell_MM",7,0,CLR_NONE);
    RefreshRates();
    Comment("Placing order SELL ",Symbol(), " #",DoubleToStr(Lots(),2), " lots", ", please wait...");						   
    while( IsTradeContextBusy() ) { Sleep(100); }
   if(ticket<1)
     {
      int error=GetLastError();
      Comment("Placing order SELL ",Symbol(),"Error = ",ErrorDescription(error));
      return;
     }
//----
   OrderPrint();
   return(0);
  }
double Lots() {
   int li_0;
   int spread = MarketInfo(Symbol(),MODE_SPREAD);
   int sl = StopLoss + spread;
   double ld_4 = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2);
   double tickvalue = MarketInfo(Symbol(), MODE_TICKVALUE);
   if (ld_4 == 0.01) li_0 = 2;
   else li_0 = 1;
   leverage = AccountLeverage();   
   if (MM) gd_200 = NormalizeDouble(AccountFreeMargin()*Risk/100/(1000/leverage)/(sl*tickvalue), li_0);
   else gd_200 = MinLot;
   double ld_12 = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2);
   double ld_20 = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2);
   if (gd_200 < ld_12) gd_200 = ld_12;
   if (gd_200 > ld_20) gd_200 = ld_20;
   return (gd_200);
}