• Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)

Coding BUY SELL di Button

Aries Sekawan

New Member
Credits
0
halo para guru,,,
saya sudah belajar buat coding Button BUY, SELL dan CLOSE.
Bisa Tolong di bantu buatin Fungsinya ga guru,,,
Uda coba googling, tapi ga ketemu.
Code:
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#define BUTTON_CLOSE "Button Close"
#define BUTTON_BUY   "Button Buy"
#define BUTTON_SELL  "Button Sell"



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
   ObjectCreate      (0,BUTTON_CLOSE,OBJ_BUTTON,0,0,0);
   ObjectSetInteger  (0,BUTTON_CLOSE,OBJPROP_XSIZE,50);
   ObjectSetInteger  (0,BUTTON_CLOSE,OBJPROP_YSIZE,25);
   ObjectSetInteger  (0,BUTTON_CLOSE,OBJPROP_XDISTANCE,10);
   ObjectSetInteger  (0,BUTTON_CLOSE,OBJPROP_YDISTANCE,15);
   ObjectSetInteger  (0,BUTTON_CLOSE,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger  (0,BUTTON_CLOSE,OBJPROP_BGCOLOR,clrGold);
   ObjectSetString   (0,BUTTON_CLOSE,OBJPROP_TEXT,"CLOSE");
   
   ObjectCreate      (0,BUTTON_BUY,OBJ_BUTTON,0,0,0);
   ObjectSetInteger  (0,BUTTON_BUY,OBJPROP_XSIZE,50);
   ObjectSetInteger  (0,BUTTON_BUY,OBJPROP_YSIZE,25);
   ObjectSetInteger  (0,BUTTON_BUY,OBJPROP_XDISTANCE,70);
   ObjectSetInteger  (0,BUTTON_BUY,OBJPROP_YDISTANCE,15);
   ObjectSetInteger  (0,BUTTON_BUY,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger  (0,BUTTON_BUY,OBJPROP_BGCOLOR,clrBlue);
   ObjectSetString   (0,BUTTON_BUY,OBJPROP_TEXT,"BUY");
   
   ObjectCreate      (0,BUTTON_SELL,OBJ_BUTTON,0,0,0);
   ObjectSetInteger  (0,BUTTON_SELL,OBJPROP_XSIZE,50);
   ObjectSetInteger  (0,BUTTON_SELL,OBJPROP_YSIZE,25);
   ObjectSetInteger  (0,BUTTON_SELL,OBJPROP_XDISTANCE,130);
   ObjectSetInteger  (0,BUTTON_SELL,OBJPROP_YDISTANCE,15);
   ObjectSetInteger  (0,BUTTON_SELL,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger  (0,BUTTON_SELL,OBJPROP_BGCOLOR,clrRed);
   ObjectSetString   (0,BUTTON_SELL,OBJPROP_TEXT,"SELL");
   
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   }
 
tambahkan event-handle: OnEventChart()
di dalam fungsi event itu,
kamu bisa coding utk hadle object BUY/SELL, dll.

Contoh ya:

Code:
void OnChartEvent(const int id,
               const long &lparam,
               const double &dparam,
               const string &sparam)
{
//---
   if (id == CHARTEVENT_OBJECT_CLICK){
      int orderType = -1;
      if (sparam == "BUTTON_BUY"){
         Print ("Open BUY");
         //Disini bisa lanjutkan dengan code untuk open order BUY

      }else if (sparam == "BUTTON_SELL"){
         Print ("Open SELL");
      }
     
   }
}
//+------------------------------------------------------------------+

Silakan gabung di group belajar code MQL di https:/t.me/codeMQL
 
Back
Top