How to read the lot size from the buy/sell buttons UI

 
Is it possible to read lot size from the buy/sell UI in top left corner of a chart? If so could someone paste some code? Is it possible to do so doing some `user.dll` call?
 
Do you mean One Click Trading Panel ??
 
  1. I don't think it's possible.
  2. Why do you care? It means nothing until the human clicks the button and a order opens.
 

I care, because I could automatically adjust my visual max risk indicator line

 
danielsokolowsk: I care, because I could automatically adjust my visual max risk indicator line

Then use (or create) a trading assistant panel, for example as described in the following article: Creating an assistant in manual trading.

There are also a few other such types of assistants available in the CodeBase, for example the Money Manager Graphic Tool, which was latter improved by @whroeder1 (see his discussion post).

 
danielsokolowsk: I care, because I could automatically adjust my visual max risk indicator line
  1. In code: Risk depends on your initial stop loss, lot size, and the value of the pair.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    • Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency (EUR, in this case).
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out
    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
  2. Use a EA GUI such as the one for MT4: Indicators: 'Money Manager Graphic Tool' indicator by 'takycard' Forum - Page 5
  3. Your doing it backwards, Human adjusts the SL line and your code should compute and display the maximum lot size.
 
//+------------------------------------------------------------------+
//|                                     och_test_use_trade_panel.mq5 |
//|                                        Copyright 2022, LUMM Ltd. |
//|                          https://squaloch.wixsite.com/index/home |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, LUMM Ltd."
#property link      "https://squaloch.wixsite.com/index/home"
#property version   "1.00"

#include <WinAPI\WinAPI.mqh>

#define GA_ROOT           0x00000002

#define WM_GETTEXT        0x000D
#define WM_GETTEXTLENGTH  0x000E

#import "user32.dll"
  PVOID SendMessageW( HANDLE, uint, PVOID, int &[] );
  PVOID SendMessageW( HANDLE, uint, PVOID, short &[] );
#import

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
HANDLE GetTerminalHandle( void )
  {
    static HANDLE Handle = user32::GetAncestor(::ChartGetInteger(0, CHART_WINDOW_HANDLE), GA_ROOT);
    
    return(Handle);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
long GetHandle( const int &ControlID[] )
  {
    long Handle = GetTerminalHandle();
    //PrintFormat("%s(%d):: TerminalHandle=%d", __FUNCTION__, __LINE__, Handle);
    const int Size = ::ArraySize(ControlID);

    for (int i = 0; i < Size; i++){
      Handle = user32::GetDlgItem(Handle, ControlID[i]);
      //PrintFormat("%s(%d)::ControlID=%I64x/%d, Handle=%d, ChartID()=%d", __FUNCTION__, __LINE__, ControlID[i], ControlID[i], Handle, ChartID());
    }
    return(Handle);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string GetEditBoxText( const long Handle )
  {
    short Buf[];

    ::ArrayResize(Buf, (int)user32::SendMessageW(Handle, WM_GETTEXTLENGTH, 0, 0 ) + 1);
    //user32::SendMessageW(Handle, WM_GETTEXT, 0, Buf);
    user32::GetWindowTextW(Handle, Buf, ArraySize(Buf));
    //PrintFormat("%s(%d)::Handle=%d", __FUNCTION__, __LINE__, Handle);
    return(::ShortArrayToString(Buf));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetLotFromTradePanel()
{
   int ControlID[] = {0xE900, 0xFF00, 0xE900, 0x27CE};
   ControlID[1] = ControlID[1] + GetChartIndex();
   static const long Handle = GetHandle(ControlID);
    
   string lot_value = GetEditBoxText(Handle);
    
   PrintFormat("%s(%d)::Handle=%d, value=%s", __FUNCTION__, __LINE__, Handle, lot_value);
   
   return(StringToDouble(lot_value));
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetChartIndex()
{
   int limit = 100;
   int index = 0;
   long chart_id = ChartFirst();
   
   while(index<100){
      if(chart_id == ChartID()) return(index);
      chart_id = ChartNext(chart_id);
      index++;
   }
   
   return(index);
}

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    int chart_index = GetChartIndex();
    int chart_id = 0xF00 + chart_index;
    //PrintFormat("%s(%d)::chart_index = %d, chart id (hex)=%I64x", __FUNCTION__, __LINE__, chart_index, chart_id);
    double lot = GetLotFromTradePanel();
   
  }
//+------------------------------------------------------------------+
Reason: