Kursus Forex Solo Tempat Belajar Trading Forex Solo Pelatihan Forex Solo Edukasi Forex Solo Training Forex Solo Privat Membuat EA Robot Forex

BACA TUTORIAL: CARA DAFTAR MT4 FOREX!

Coding MQL4 EA Martingale Hidden TP

Coding MQL4 EA Martingale Hidden TP, Belajar Membuat EA Robot Forex Dengan Bahasa Pemrograman MetaQuotes Language Editor.

////+------------------------------------------------------------------+
//|                                              EA MART 24NOV21.mq4 |
//|                                                       EA Creator |
//|                                           http://daftarmt4.my.id |
//+------------------------------------------------------------------+
#property copyright "EA Creator"
#property link      "http://daftarmt4.my.id"
#property version   "1.00"
#property strict

extern double Lots   = 0.01;
extern int TP        = 100;
extern int JarakMart = 200;
extern double Dmart  = 2;

int Magic = 75;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   label();
   CloseOrderSellIf();
   CloseOrderBuyIf();
   //modifytp();
   //cekprofitbuy();
   //cekprofitsell();
   //CheckOpenOrdersSell();
   //CheckOpenOrdersBuy();
   double ma14  = iMA(NULL,NULL,14,0,MODE_SMA,PRICE_CLOSE,0);
   double ma100 = iMA(NULL,NULL,100,0,MODE_SMA,PRICE_CLOSE,0);

   if(jumlahorder(0)+jumlahorder(1)==0)
     {
      if(Ask<ma14 && ma14>ma100)
        {
         opbuy();
        }
      if(OrdersTotal()<1 && Bid>ma14 && ma14<ma100)
        {
         opsell();
        }
     }
   if(jarakmart()==1 && jumlahorder(0)>=1)
     {
      opbuymart();
     }
   if(jarakmart()==2 && jumlahorder(1)>=1)
     {
      opsellmart();
     }
  }

//+------------------------------------------------------------------+
void opbuy()
  {
   if(OrdersTotal()<1)
     {
      int buyticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,4,0,0,"EAbuy",Magic,0,Blue);
     }
  }
//+------------------------------------------------------------------+
void opsell()
  {
   if(OrdersTotal()<1)
     {
      int sellticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,4,0,0,"EAsell",Magic,0,Red);
     }
  }
//+------------------------------------------------------------------+
void opbuymart()
  {
   int buymartiticket = OrderSend(Symbol(),OP_BUY,mart(0),Ask,4,0,0,"EAmartbuy",Magic,0,Green);
  }

//+------------------------------------------------------------------+
void opsellmart()
  {
   int sellmartiticket = OrderSend(Symbol(),OP_SELL,mart(1),Bid,4,0,0,"EAmartsell",Magic,0,Yellow);
  }
//+------------------------------------------------------------------+
int jumlahorder(int tipe)
  {
   int jumlah = 0;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe)
         continue;
      jumlah++;
     }
   return(jumlah);
  }

//+------------------------------------------------------------------+
int jarakmart()
  {
   int jarakMart = 0;
   double openpricebuy  = 0;
   double openpricesell = 0;

   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic)
         continue;

      if(OrderType()==0)
         openpricebuy  = OrderOpenPrice();
      if(OrderType()==1)
         openpricesell = OrderOpenPrice();
     }
   double priceAsk = openpricebuy - JarakMart * Point;
   double priceBid = openpricesell + JarakMart * Point;
   if(Ask<= priceAsk && jumlahorder(0)>0)
      jarakMart = 1;
   if(Bid>=priceBid && jumlahorder(1)>0)
      jarakMart = 2;
   return(jarakMart);
  }

//+------------------------------------------------------------------+
double mart(int type)
  {
   double lotMart = 0;
   double lotOp = 0;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=type)
         continue;
      lotOp+=OrderLots();
     }
   if(OrderType()==type)
      lotMart=(Lots*MathPow(Dmart,jumlahorder(type)));
   return(lotMart);
  }
//+------------------------------------------------------------------+
void closeallorder()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic)
         continue;
      if(OrderType()>1)
         int ticket = OrderDelete(OrderTicket());
      if(OrderType()==0)
         int ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),4,Blue);
      if(OrderType()==1)
         int ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),4,Red);
     }
  }
//+------------------------------------------------------------------+
double cekprofitall()
  {
   double profitall = 0;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic)
         continue;
      profitall+=OrderProfit();
     }
   return(profitall);
  }
//+------------------------------------------------------------------+

void cekprofitbuy()
  {
   double profitbuy = 0;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=OP_BUY)
         continue;
      profitbuy+=OrderProfit();
     }
   if(profitbuy>=TP)
     {
      int ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),4,Aqua);
     }
  }
//+------------------------------------------------------------------+

void cekprofitsell()
  {
   double profitsell = 0;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=OP_SELL)
         continue;
      profitsell+=OrderProfit();
     }
   if(profitsell>=TP)
     {
      int ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),4,Aqua);
     }
  }
//+------------------------------------------------------------------+
void modifytp()
  {
   double tpop = 0;
   double lasttp;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol())
         continue;
      tpop = OrderTakeProfit();
     }
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol())
         continue;
      lasttp = OrderTakeProfit();
      if(tpop!=lasttp)
        {
         int modifytpticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tpop,0,Aqua);
        }
     }
  }

//+------------------------------------------------------------------+
void CheckOpenOrdersBuy()
  {
   double profit = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            profit += OrderProfit();
           }
        }
     }

   if(profit > TP)
     {
      int ticket = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Aqua);

     }
  }
//+------------------------------------------------------------------+

void CheckOpenOrdersSell()
  {
   double profit = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            profit += OrderProfit();
           }
        }
     }

   if(profit > TP)
     {
      int ticket = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Aqua);

     }
  }
//+------------------------------------------------------------------+

void CloseOrderBuyIf()
  {
   int orders = 0;
   for(int i = 0; i < OrdersTotal(); i++)
     {
      bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != Magic)
        {
         continue;
        }
      if(OrderProfit() > ((Lots*MathPow(Dmart,jumlahorder(0)))*TP)/2)
        {
         int ticket = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
         }
         
         }
   }      
//+------------------------------------------------------------------+
void CloseOrderSellIf()
  {
   int orders = 0;
   for(int i = 0; i < OrdersTotal(); i++)
     {
      bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != Magic)
        {
         continue;
        }
      if(OrderProfit() > ((Lots*MathPow(Dmart,jumlahorder(1)))*TP)/2)
        {

         int ticket = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Blue);
         }
     }

  }

//+------------------------------------------------------------------+
void label()
  {
   string profit = "PROFIT: " +DoubleToStr(OrderProfit(),2);
   ObjectCreate("a",OBJ_LABEL,0,0,0);
   ObjectSet("a",OBJPROP_CORNER,4);
   ObjectSet("a",OBJPROP_XDISTANCE,10);
   ObjectSet("a",OBJPROP_YDISTANCE,20);
   ObjectSetText("a",profit,25,"Mistral",Yellow);

   string balance = "BALANCE: " +DoubleToStr(AccountBalance(),2);
   ObjectCreate("b",OBJ_LABEL,0,0,0);
   ObjectSet("b",OBJPROP_CORNER,4);
   ObjectSet("b",OBJPROP_XDISTANCE,10);
   ObjectSet("b",OBJPROP_YDISTANCE,80);
   ObjectSetText("b",balance,25,"Mistral",Yellow);

   string equity = "EQUITY: " +DoubleToStr(AccountEquity(),2);
   ObjectCreate("c",OBJ_LABEL,0,0,0);
   ObjectSet("c",OBJPROP_CORNER,4);
   ObjectSet("c",OBJPROP_XDISTANCE,10);
   ObjectSet("c",OBJPROP_YDISTANCE,140);
   ObjectSetText("c",equity,25,"Mistral",Yellow);
  }
//+------------------------------------------------------------------+//



Ada Ingin Bertanya Seputar Coding MQL4 EA Martingale Hidden Take Profit? tuliskan dikolom komentar. 

0 comments: