Or i should use BuyNow() Instead of BuyNow !
I do it but not work !
Hello
Is it possible to have one click trading script code ?
if not can you let me know have script that not work after click on that! and only run after set values on chart and click for example buy button ?
i have script that work immidiately after click on that and i use simple code like this for buy button but not work!
Thank
You cannot create two different objects with the same string-name.
You cannot create two different objects with the same string-name.
This is two objects with same name ??
Can you let me now how can i have simple objects like mt4 base one click trading script?
Just let me see simple code i can understand and improve that :)
Thanks
This is two objects with same name ??
Can you let me now how can i have simple objects like mt4 base one click trading script?
Just let me see simple code i can understand and improve that :)
Thanks
You need to handle events with OnChartEvent. Here is a quick example.
//+------------------------------------------------------------------+ //| SimpleButtonEA.mq4 | //| nicholishen | //| http://www.reddit.com/u/nicholishenFX | //+------------------------------------------------------------------+ #property copyright "nicholishen" #property link "http://www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict #include <ChartObjects\ChartObjectsTxtControls.mqh> //+------------------------------------------------------------------+ class BuyButton : public CChartObjectButton { public: bool Create() { if(!CChartObjectButton::Create(ChartID(),"BuyButton",0,110,35,100,30)) return false; Corner(CORNER_LEFT_LOWER); Description("BUY"); Color(clrWhite); BackColor(clrDodgerBlue); return true; } void OnChartEvent() { if(State()) { Alert("BUY button pressed"); EventSetMillisecondTimer(100); } } }; //+------------------------------------------------------------------+ class SellButton : public CChartObjectButton { public: bool Create() { if(!CChartObjectButton::Create(ChartID(),"SellButton",0,5,35,100,30)) return false; Corner(CORNER_LEFT_LOWER); Description("SELL"); Color(clrWhite); BackColor(clrRed); return true; } void OnChartEvent() { if(State()) { Alert("SELL button pressed"); EventSetMillisecondTimer(100); } } }; //--- global class instances BuyButton buy; SellButton sell; //+------------------------------------------------------------------+ int OnInit() { //--- ObjectDelete(0,"BuyButton"); ObjectDelete(0,"SellButton"); if(!buy.Create() || !sell.Create()) return INIT_FAILED; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_OBJECT_CLICK) { sell.OnChartEvent(); buy.OnChartEvent(); } } //+------------------------------------------------------------------+ void OnTimer() { //This is only for graphics of button being pressed. buy.State(false); sell.State(false); EventKillTimer(); } //+------------------------------------------------------------------+
You need to handle events with OnChartEvent. Here is a quick example.
Thanks for your code
But it is not work and i can't run it .
Thanks for your code
But it is not work and i can't run it .
It's an expert advisor. Here is a different version which is a little more advanced. It demonstrates inheritance and polymorphism of the button class.
//+------------------------------------------------------------------+ //| SimpleButtonEA.mq4 | //| nicholishen | //| http://www.reddit.com/u/nicholishenFX | //+------------------------------------------------------------------+ #property copyright "nicholishen" #property link "http://www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict #include <ChartObjects\ChartObjectsTxtControls.mqh> #include <Arrays\ArrayObj.mqh> //+------------------------------------------------------------------+ #define BUTTON_WIDTH 100 #define BUTTON_HEIGHT 30 #define PADDING 2 //+------------------------------------------------------------------+ class BaseButton : public CChartObjectButton { protected: string m_desc; string m_obj_name; int m_pos; public: BaseButton(const string des,const string name,const int pos):m_desc(des),m_obj_name(name),m_pos(pos){} virtual bool Create() { if(!CChartObjectButton::Create(ChartID(),m_obj_name,0,(BUTTON_WIDTH*m_pos)+(PADDING*(m_pos+1)),BUTTON_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT)) return false; Corner(CORNER_LEFT_LOWER); Color(clrWhite); Description(m_desc); return true; } virtual void OnChartEvent() { if(State()) { Alert(m_desc+" button pressed"); EventSetMillisecondTimer(100); } } virtual void OnTimer() { State(false); } }; //+------------------------------------------------------------------+ class BuyButton : public BaseButton { public: BuyButton():BaseButton("BUY","BuyButton",0){} virtual bool Create() { if(!BaseButton::Create()) return false; BackColor(clrDodgerBlue); return true; } }; //+------------------------------------------------------------------+ class SellButton : public BaseButton { public: SellButton():BaseButton("SELL","SellButton",1){} virtual bool Create() { if(!BaseButton::Create()) return false; BackColor(clrRed); return true; } }; //+------------------------------------------------------------------+ class CloseAllButton : public BaseButton { public: CloseAllButton():BaseButton("CLOSE ALL","CloseAllButton",2){} virtual bool Create() { if(!BaseButton::Create()) return false; Color(clrBlack); BackColor(clrGold); return true; } virtual void OnChartEvent() { if(State()) { if(MessageBox("Would you like to close all trades?",NULL,MB_YESNO)==IDYES) Alert("CloseAllTrades confirmed"); State(false); } } virtual void OnTimer(){return;} }; //+------------------------------------------------------------------+ class ButtonManager : private CArrayObj { public: BaseButton* operator[](const int index)const{return (BaseButton*)At(index);} void OnChartEvent() { for(int i=0;i<Total();i++) this[i].OnChartEvent(); } void OnTimer() { for(int i=0;i<Total();i++) this[i].OnTimer(); } bool OnInit() { ObjectDelete(0,"BuyButton"); ObjectDelete(0,"SellButton"); ObjectDelete(0,"CloseAllButton"); BaseButton *button = new BuyButton; if(!button.Create()) return false; else Add(button); button = new SellButton; if(!button.Create()) return false; else Add(button); button = new CloseAllButton; if(!button.Create()) return false; else Add(button); return true; } }; //+------------------------------------------------------------------+ //--- global class instances ButtonManager manager; //+------------------------------------------------------------------+ int OnInit() { if(!manager.OnInit()) return INIT_FAILED; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK) manager.OnChartEvent(); } //+------------------------------------------------------------------+ void OnTimer() { //This is only for graphics of button being pressed. manager.OnTimer(); EventKillTimer(); } //+------------------------------------------------------------------+
Thanks for your answer
i use it
#property copyright "nicholishen" #property link "http://www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict #include <ChartObjects\ChartObjectsTxtControls.mqh> #include <Arrays\ArrayObj.mqh> //+------------------------------------------------------------------+ #define BUTTON_WIDTH 100 #define BUTTON_HEIGHT 30 #define PADDING 2 input double Lots = 0.01; input int TP = 200; input int SL = 200; input int slippage = 1; input string comment = "MyOrder"; input int magic = 1234; //+------------------------------------------------------------------+ class BaseButton : public CChartObjectButton { protected: string m_desc; string m_obj_name; int m_pos; public: BaseButton(const string des,const string name,const int pos):m_desc(des),m_obj_name(name),m_pos(pos){} virtual bool Create() { if(!CChartObjectButton::Create(ChartID(),m_obj_name,0,(BUTTON_WIDTH*m_pos)+(PADDING*(m_pos+1)),BUTTON_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT)) return false; Corner(CORNER_LEFT_LOWER); Color(clrWhite); Description(m_desc); return true; } virtual void OnChartEvent() { if(State()) { Alert(m_desc+" button pressed"); EventSetMillisecondTimer(100); } } virtual void OnTimer() { State(false); } }; //+------------------------------------------------------------------+ class BuyButton : public BaseButton { public: BuyButton():BaseButton("BUY","BuyButton",0){} virtual bool Create() { if(!BaseButton::Create()) return false; BackColor(clrDodgerBlue); return true; } }; //+------------------------------------------------------------------+ class SellButton : public BaseButton { public: SellButton():BaseButton("SELL","SellButton",1){} virtual bool Create() { if(!BaseButton::Create()) return false; BackColor(clrRed); return true; } }; //+------------------------------------------------------------------+ class CloseAllButton : public BaseButton { public: CloseAllButton():BaseButton("CLOSE ALL","CloseAllButton",2){} virtual bool Create() { if(!BaseButton::Create()) return false; Color(clrBlack); BackColor(clrGold); return true; } virtual void OnChartEvent() { if(State()) { if(MessageBox("Would you like to close all trades?",NULL,MB_YESNO)==IDYES) Alert("CloseAllTrades confirmed"); State(false); } } virtual void OnTimer(){return;} }; //+------------------------------------------------------------------+ class ButtonManager : private CArrayObj { public: BaseButton* operator[](const int index)const{return (BaseButton*)At(index);} void OnChartEvent() { for(int i=0;i<Total();i++) this[i].OnChartEvent(); } void OnTimer() { for(int i=0;i<Total();i++) this[i].OnTimer(); } bool OnInit() { ObjectDelete(0,"BuyButton"); ObjectDelete(0,"SellButton"); ObjectDelete(0,"CloseAllButton"); BaseButton *button = new BuyButton; if(!button.Create()) return false; else Add(button); button = new SellButton; if(!button.Create()) return false; else Add(button); button = new CloseAllButton; if(!button.Create()) return false; else Add(button); return true; } }; //+------------------------------------------------------------------+ //--- global class instances ButtonManager manager; //+------------------------------------------------------------------+ int OnInit() { if(!manager.OnInit()) return INIT_FAILED; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK) manager.OnChartEvent(); } //+------------------------------------------------------------------+ void OnTimer() { //This is only for graphics of button being pressed. manager.OnTimer(); EventKillTimer(); } //+------------------------------------------------------------------+ void OnStart(){ if(ObjectFind(0,"BuyButton")) int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-(SL*Point),Ask+(TP*Point),comment,magic,0,Green); }
as an script but not work ! and objects not create on chart!
and use it as an EA but buybutton not work
#property copyright "nicholishen" #property link "http://www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict #include <ChartObjects\ChartObjectsTxtControls.mqh> #include <Arrays\ArrayObj.mqh> //+------------------------------------------------------------------+ #define BUTTON_WIDTH 100 #define BUTTON_HEIGHT 30 #define PADDING 2 input double Lots = 0.01; input int TP = 200; input int SL = 200; input int slippage = 1; input string comment = "MyOrder"; input int magic = 1234; //+------------------------------------------------------------------+ class BaseButton : public CChartObjectButton { protected: string m_desc; string m_obj_name; int m_pos; public: BaseButton(const string des,const string name,const int pos):m_desc(des),m_obj_name(name),m_pos(pos){} virtual bool Create() { if(!CChartObjectButton::Create(ChartID(),m_obj_name,0,(BUTTON_WIDTH*m_pos)+(PADDING*(m_pos+1)),BUTTON_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT)) return false; Corner(CORNER_LEFT_LOWER); Color(clrWhite); Description(m_desc); return true; } virtual void OnChartEvent() { if(State()) { Alert(m_desc+" button pressed"); EventSetMillisecondTimer(100); } } virtual void OnTimer() { State(false); } }; //+------------------------------------------------------------------+ class BuyButton : public BaseButton { public: BuyButton():BaseButton("BUY","BuyButton",0){} virtual bool Create() { if(!BaseButton::Create()) return false; BackColor(clrDodgerBlue); return true; } }; //+------------------------------------------------------------------+ class SellButton : public BaseButton { public: SellButton():BaseButton("SELL","SellButton",1){} virtual bool Create() { if(!BaseButton::Create()) return false; BackColor(clrRed); return true; } }; //+------------------------------------------------------------------+ class CloseAllButton : public BaseButton { public: CloseAllButton():BaseButton("CLOSE ALL","CloseAllButton",2){} virtual bool Create() { if(!BaseButton::Create()) return false; Color(clrBlack); BackColor(clrGold); return true; } virtual void OnChartEvent() { if(State()) { if(MessageBox("Would you like to close all trades?",NULL,MB_YESNO)==IDYES) Alert("CloseAllTrades confirmed"); State(false); } } virtual void OnTimer(){return;} }; //+------------------------------------------------------------------+ class ButtonManager : private CArrayObj { public: BaseButton* operator[](const int index)const{return (BaseButton*)At(index);} void OnChartEvent() { for(int i=0;i<Total();i++) this[i].OnChartEvent(); } void OnTimer() { for(int i=0;i<Total();i++) this[i].OnTimer(); } bool OnInit() { ObjectDelete(0,"BuyButton"); ObjectDelete(0,"SellButton"); ObjectDelete(0,"CloseAllButton"); BaseButton *button = new BuyButton; if(!button.Create()) return false; else Add(button); button = new SellButton; if(!button.Create()) return false; else Add(button); button = new CloseAllButton; if(!button.Create()) return false; else Add(button); return true; } }; //+------------------------------------------------------------------+ //--- global class instances ButtonManager manager; //+------------------------------------------------------------------+ int OnInit() { if(!manager.OnInit()) return INIT_FAILED; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK) manager.OnChartEvent(); } //+------------------------------------------------------------------+ void OnTimer() { //This is only for graphics of button being pressed. manager.OnTimer(); EventKillTimer(); } //+------------------------------------------------------------------+ void OnTick(){ if(ObjectFind(0,"BuyButton")) int ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-(SL*Point),Ask+(TP*Point),comment,magic,0,Green); }
and can you help me for get tex box ! for example user write own lot then click buy ?
how can i use EA inputs parameter set on chart in script ?
codes not clear for me?
Thanks for your answer
i use it
as an script but not work ! and objects not create on chart!
and use it as an EA but buybutton not work
and can you help me for get tex box ! for example user write own lot then click buy ?
how can i use EA inputs parameter set on chart in script ?
codes not clear for me?
This is an example of a button GUI on the chart. It will not place trades. You will need to program it to your specifications.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
Is it possible to have one click trading script code ?
if not can you let me know have script that not work after click on that! and only run after set values on chart and click for example buy button ?
i have script that work immidiately after click on that and i use simple code like this for buy button but not work!
Thank