Download MetaTrader 5

Transfer object to a new chart and get string from user

To add comments, please log in or register
Maryam
78
Maryam  

Hi

I have two questions

Thank you for help me

Between run an expert how transfer object to new chart?

Between run an expert and how to get a string from the user?

for complate this Expert

#include <Controls\WndObj.mqh>

input string               symbol;                //input symbol  
input ENUM_TIMEFRAMES      period=PERIOD_D1;        //time frame    

string buttonID="button";
string txtsym="input symbol";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   CWndObj Obj;
   
   ObjectCreate(0,buttonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,buttonID,OBJPROP_XDISTANCE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_YDISTANCE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_XSIZE,80);
   ObjectSetInteger(0,buttonID,OBJPROP_YSIZE,25);
   ObjectSetString(0,buttonID,OBJPROP_FONT,"Arial");
   ObjectSetString(0,buttonID,OBJPROP_TEXT,"open symbol");
   ObjectSetInteger(0,buttonID,OBJPROP_FONTSIZE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_SELECTABLE,0);   
   ObjectSetInteger(0,buttonID,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,buttonID,OBJPROP_BGCOLOR,clrGray);
//*********
   ObjectCreate(0,txtsym,OBJ_TEXT,0,0,0);
   ObjectSetInteger(0,txtsym,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,txtsym,OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,txtsym,OBJPROP_YDISTANCE,50);
   ObjectSetString(0,txtsym,OBJPROP_FONT,"Trebuchet MS");
   ObjectSetString(0,txtsym,OBJPROP_TEXT,"input symbol");
   ObjectSetInteger(0,txtsym,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,txtsym,OBJPROP_SELECTABLE,0);  
   
  // Text(OBJPROP_SYMBOL); 
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
   {
   string sym;
   long idnew;
//--- Check the event by pressing a mouse button
    if(id==CHARTEVENT_OBJECT_CLICK)
       {         
         sym=ObjectGetString(0,txtsym,OBJPROP_TEXT,0);
         idnew=ChartOpen(sym,period);           
       }
       
   }     
//+------------------------------------------------------------------+ 
Gabor Torma
2680
Gabor Torma  

Maryam:

Between run an expert and how to get a string from the user?

input string               symbol;                //input symbol  //نماد مورد نظر را وارد کنید
input ENUM_TIMEFRAMES      period=PERIOD_D1;        //time frame    // پریود زمانی را وارد کنید

string buttonID="button";
string txtsym="input symbol";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   //CWndObj Obj;
   
   ObjectCreate(0,buttonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,buttonID,OBJPROP_XDISTANCE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_YDISTANCE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_XSIZE,80);
   ObjectSetInteger(0,buttonID,OBJPROP_YSIZE,25);
   ObjectSetString(0,buttonID,OBJPROP_FONT,"Arial");
   ObjectSetString(0,buttonID,OBJPROP_TEXT,"open symbol");
   ObjectSetInteger(0,buttonID,OBJPROP_FONTSIZE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_SELECTABLE,0);   
   ObjectSetInteger(0,buttonID,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,buttonID,OBJPROP_BGCOLOR,clrGray);
//*********
   ObjectCreate(0,txtsym,OBJ_EDIT,0,0,0);
   ObjectSetInteger(0,txtsym,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,txtsym,OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,txtsym,OBJPROP_YDISTANCE,50);
   ObjectSetInteger(0,txtsym,OBJPROP_XSIZE,100);
   ObjectSetInteger(0,txtsym,OBJPROP_YSIZE,40);
   ObjectSetString(0,txtsym,OBJPROP_FONT,"Trebuchet MS");
   ObjectSetString(0,txtsym,OBJPROP_TEXT,"input symbol");
   ObjectSetInteger(0,txtsym,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,txtsym,OBJPROP_SELECTABLE,0);  
   
  // Text(OBJPROP_SYMBOL); 
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
   {
   string sym;
   long idnew;
//--- Check the event by pressing a mouse button
    if(id==CHARTEVENT_OBJECT_CLICK)
       {         
         sym=ObjectGetString(0,txtsym,OBJPROP_TEXT,0);
         idnew=ChartOpen(sym,period);           
       }
       
   }     
//+------------------------------------------------------------------+ 
Modification highlited with yellow.
Maryam
78
Maryam  
VincentX:
Modification highlited with yellow.

thank you

Changes do not solved problem

 text "input symbol" not be seen

   ObjectCreate(0,txtsym,OBJ_EDIT,0,0,0);
   ObjectSetInteger(0,txtsym,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,txtsym,OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,txtsym,OBJPROP_YDISTANCE,50);
   ObjectSetInteger(0,txtsym,OBJPROP_XSIZE,100);
   ObjectSetInteger(0,txtsym,OBJPROP_YSIZE,40);
   ObjectSetString(0,txtsym,OBJPROP_FONT,"Trebuchet MS");
   ObjectSetString(0,txtsym,OBJPROP_TEXT,"input symbol");
   ObjectSetInteger(0,txtsym,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,txtsym,OBJPROP_SELECTABLE,0); 

and I want transfer button to new chart



Maryam
78
Maryam  
Please can anyone help me
To add comments, please log in or register