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!

Cara Membuat Script New Order

Belajar script MQL4 - Cara membuat script new order / OPEN ORDER. Langkahnya: buka MT4, tekan tombol F4, tekan tombol Ctrl+N, klik lingkaran script, klik next, tulis nama script, tulis author script, tulis link url website kalian, klik next, klik lagi next, klik finish.

Tulis coding dibawah ini untuk membuat script new order!

Variable untuk membuat script new order.

//+------------------------------------+
//|           Script  New Order v1.mq4 |
//|                                        admin |
//|        http://kursusforex.net |
//+------------------------------------+
#property copyright "Hasan"
#property link      "http://hasan.com"
#property version   "1.00"
#property strict
#property show_inputs

enum Operation{
   buy=OP_BUY,    //BUY
   sell=OP_SELL,   //SELL
};

extern double Lots           =1;                  
extern bool UseRiskPercentage=false;    
extern double RiskPercentage =2;       
input Operation Command      =buy;           
extern int TakeProfit        =15;              
extern int StopLoss          =10;                
       int Slippage          =2;                
       int MagicNumber       =0;             
       string Cmt            ="";     
Coding untuk membuat script new order.

double CalculateNormalizedDigits()
{
   if(Digits<=3){
      return(0.01);
   }
   else if(Digits>=4){
      return(0.0001);
   }
   else return(0);
}

//+-----------------------------------------------------------+
//| Script program start function                             |
//+-----------------------------------------------------------+
void OnStart()
  {
   if(StopLoss==0 && UseRiskPercentage){
      Print("stop loss perlu jika persentase risiko digunakan");
      return;
   }
   
   int Cmd=Command;
   
   double nTickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
   double nDigits=CalculateNormalizedDigits();
   if(Digits==3 || Digits==5){
      Slippage=Slippage*10;
      nTickValue=nTickValue*10;
   }   
Coding untuk membuat script new order.

if(UseRiskPercentage){
      Lots=(AccountBalance()*RiskPercentage/100)/(StopLoss*nTickValue);
      Lots=MathRound(Lots/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP);
   }   
   double OpenPrice=0;
   double TakeProfitPrice=0;
   double StopLossPrice=0;
   if(Cmd==OP_BUY){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice+TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice-StopLoss*nDigits,Digits);
   } 
Script untuk membuat script new order.

if(Cmd==OP_SELL){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice-TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice+StopLoss*nDigits,Digits);
   }    
   Print("buka transaksi ",Command," size ",Lots, " open price ",OpenPrice," slippage ",Slippage," SL ",StopLossPrice," TP ",TakeProfitPrice," comment ",Cmt," magic ",MagicNumber);
   
   int OrderNumber;
   OrderNumber=OrderSend(Symbol(),Cmd,Lots,OpenPrice,Slippage,StopLossPrice,TakeProfitPrice,Cmt,MagicNumber);
   if(OrderNumber>0){
      Print("transaksi ",OrderNumber," terbuka");
   }
   else{
      Print("transaksi gagal dengan error - ",GetLastError());
   }   
  }
//+------------------------------------------------------------------+

Kalau sudah selesai menulis semua scriptnya, silahkan klik compile!

Bagi teman-teman yang ingin bertanya terkait cara membuat script new order atau untuk bapak-bapak dan ibu-ibu yang berminat ingin mendapatkan bimbingan privat belajar script MQL4, silahkan Anda menghubungi ke kontak kami

0 comments: