Sahil Bagdi
Sahil Bagdi

Reputation: 23

Get One Click Trading Lot Size MT4

I want to get lot size from one click trading in MT4, See below image to understand what I am talking about:Lot size in One click trading

Using MQL4 Of course

Imports:

#import "user32.dll"
   int FindWindowW(string className, string windowName);
   int FindWindowExW(int hwndParent, int hwndChildAfter, string className, string windowName);
   int GetWindowTextW(int hWnd, string lpString, int nMaxCount);
   int GetParent(int hWnd);
   int SendMessageW(int hWnd, int Msg, int wParam, string lParam);
#import

Function To get lot size:

double GetLotSizeFromOneClickTrading()
{
   int hwndMT4 = FindWindowW("MetaQuotes::MetaTrader::4.00", NULL);
   if (hwndMT4 == 0)
      return -1;

   int hwndMDIClient = FindWindowExW(hwndMT4, 0, "MDIClient", NULL);
   if (hwndMDIClient == 0)
      return -2;

   int hwndAboveChart = FindWindowExW(hwndMDIClient, 0, "Afx:00610000:b:00010003:00000006:000715CD", NULL);
   if (hwndAboveChart == 0)
      return -3;

   int hwndChart = FindWindowExW(hwndAboveChart, 0, "AfxFrameOrView140s", NULL);
   if (hwndChart == 0)
      return -4;

   int hwndEdit = FindWindowExW(hwndChart, 0, "Edit", NULL);
   if (hwndEdit == 0)
      return -5;

   // Get the lot size text from the edit box
   string lotSizeText;
   GetWindowTextW(hwndEdit, lotSizeText, 31);

   // Convert the text to a double and return it
   return StringToDouble(lotSizeText);

}

Afx:00610000:b:00010003:00000006:000715CD -> This value change on restart, I got this from WinSpy++ hwndEdit -> This variable will conatain the Edit box handle Now I just need text from it but I am unable to get it

My tries: But I am unable to get the lot size, I have tried below:

1.)

// Get the lot size text from the edit box
   string lotSizeText;
   GetWindowTextW(hwndEdit, lotSizeText, 31);

Doesn't do anything and I do not get anything in my variable

2.)

// Get the lot size text from the edit box
   string lotSizeText;
   const int WM_GETTEXT = 0x000D;
   SendMessageW(hwndEdit, WM_GETTEXT, 31, lotSizeText);

Again, Doesn't do anything

I was happy finally finding the Edit box handle but I can't get the text out of it, It's the worst

Some help will be really appreaciated

Upvotes: 0

Views: 376

Answers (1)

TTSS000
TTSS000

Reputation: 1

I had a similar issue. I found that once I click the edit box manually, then GetWindowTextW(...) returns the value correctly.

I tried to simulate the mouse click automatically. SendInput(...) is the only API I was able to obtain the same effect. But I don't think it's a beatiful solution.

Upvotes: 0

Related Questions