Forex Zone | Forex Forum

Function To Open MT4 Trade Window

Discussion started on MT4 / MT5 EAs

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Function To Open MT4 Trade Window in MT4 / MT5 EAs_clip
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 »

  • Function To Open MT4 Trade Window in MT4 / MT5 EAs_index
  • Posts: 3123
  • Points: 34194
  • Likes Received: 2901
  • Reputation: +159/-13
Function To Open MT4 Trade Window in MT4 / MT5 EAs_xx
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

  • Posts: 352
  • Points: 71
  • Likes Received: 144
  • Reputation: +11/-0
Function To Open MT4 Trade Window in MT4 / MT5 EAs_xx
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

  • Function To Open MT4 Trade Window in MT4 / MT5 EAs_index
  • Posts: 3123
  • Points: 34194
  • Likes Received: 2901
  • Reputation: +159/-13
Function To Open MT4 Trade Window in MT4 / MT5 EAs_xx
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.


* Share Topic

Share via delicious Share via digg Share via facebook Share via linkedin Share via pinterest Share via reddit Share via stumble Share via tumblr Share via twitter

* Similar Topics

clip
m15 open candle strategy

Started by Torroco on Trading Systems

0 Replies
16 Views
Last post July 01, 2021, 01:02:00 AM
by Torroco
clip
using the open H1 timeframe line

Started by Torroco on Trading Systems

0 Replies
15 Views
Last post July 03, 2021, 12:45:43 AM
by Torroco
clip
EA CANDLE OPEN ON RENKO

Started by Anta on MT4 / MT5 EAs

7 Replies
1101 Views
Last post November 11, 2019, 07:21:49 AM
by Bacol
clip
open position with EMA 37+fractal

Started by Torroco on Trading Systems

0 Replies
18 Views
Last post July 03, 2021, 12:51:35 AM
by Torroco