Forex Zone - Forex Forum

Function To Open MT4 Trade Window

Discussion started on MT4 / MT5 EAs

  • Sr. Member
  • Posts: 352
  • Points: 71
  • Likes Received: 150
  • Reputation: +11/-0
Hi Admin/CP

Is there a function I can call to open the trade window?

I know I can use the OrderSend fn to open a new trade.
Let me explain 1st what I've done.
I have that Advanced Currency Meter and a Daily FX indi's open.
Both only print objects on the chart, so I get the object values etc etc.
As you can see in the code below, if certain conditions are met, the EA will pop up a OK/Cancel MessageBox.
If I decide to take the trade and press OK, (int of 1) it must open the trade window (And then also go to sleep for a while), or else it must sleep for x amount of time.
(I will still see how else I can keep the EA quiet, because it will obviously keep on popping up the MessageBox while the 2 green arrows are on the chart, and that can sometimes last quite some time, so I thought Sleep is the best option.)

Code: [Select]
string c02 = ObjectGetString(0,"label-02",OBJPROP_TEXT);//GBPUSD
string a02 = ObjectGetString(0,"act-02",OBJPROP_TEXT);
string tp02 = ObjectGetString(0,"ttp-02",OBJPROP_TEXT);
string GBPUSD = ObjectGetString(0,"currency41",OBJPROP_TEXT);
double cl02 = iClose(c02,0,0);
double diff = (cl02-StrToDouble(tp02));
 if ((c02=="GBPUSD")&& (a02 == "Buy") && (GBPUSD==buy) && (cl02<tp02))
    { int mb =     MessageBox("Buy Signal "+c02+
                 "\n TP"+tp02,"Trade Alert"
                 ,0x00000001) ;
  
      if (mb == 1)
     {  Sleep (SleepTime);}
// Here I need to place an order, or cancel the MB
      if (mb==2)
      {  Sleep (30000);}
      }

This is just part of the EA.

I will try to fully automate this, but the OrderSelect fn etc are still getting me down, as these Indi's only need to be on one chart, (They are quite resource hungry) thus the reason I also get the symbol from the EA, so the chart can be on any pair, but the EA will only notify the symbol(s) which meet(s) the requirements.
This is why for now I want to manually place the order.
(Yes, I know I can just open the trade window and place the order, but with all the features etc available in MQL4, I thought there might be a way, if I select OK, it will open a place order feature or something)

Thanks for the help again.


Linkback: https://www.forex.zone/mt4-mt5-eas/7/function-to-open-mt4-trade-window/376/
#1 - November 06, 2018, 01:28:56 PM
Attachments:
« Last Edit: November 06, 2018, 01:57:42 PM by Admin »

Administrator
  • Hero Member
  • Posts: 4886
  • Points: 33341
  • Likes Received: 4973
  • Reputation: +220/-14
If I remember correctly, the EA will sit there anyways if there is a MessageBox open that needs your click. So it will do the same as Sleep and the EA will just sit there waiting for your click.

If your whole point of using Sleep is just to prevent multiple Message Boxes in a row, there is a better way to do this. You wouldn't want to use Sleep because the EA will do nothing at all then (eg. manage trades already open, check for opportunities on other charts, etc). So as an example of a better way, you could record the time of the last signal that caused the Message Box. Then check to see if the current time is still on the same candle. If so, no more Message Boxes. Or you could record the last signal type. If it was a buy, then the next signal must be a sell.
#2 - November 06, 2018, 01:56:46 PM
Function To Open MT4 Trade Window in MT4 / MT5 EAs_FEN-Indicator-728x90

  • Sr. Member
  • Posts: 352
  • Points: 71
  • Likes Received: 150
  • Reputation: +11/-0
I will try the time thing, eg, record the last message time, and then use that as part of the logic.
The other question is, is there a way to open the trade window, or place orders by pressing the OK button? Or do I have to use the OrderSend function?
#3 - November 06, 2018, 03:30:16 PM

Administrator
  • Hero Member
  • Posts: 4886
  • Points: 33341
  • Likes Received: 4973
  • Reputation: +220/-14
The other question is, is there a way to open the trade window, or place orders by pressing the OK button? Or do I have to use the OrderSend function?
I'm sure there is a complex way to open the manual trading window from an EA, but I have never seen it done that I can remember.

As far as placing orders by pressing the Ok button, yes, this is possible. However, the EA would still use the OrderSend to place the order though.
#4 - November 06, 2018, 03:56:41 PM

Members:

0 Members and 1 Guest are viewing this topic.