[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 259

 
paladin80:
Must close on a stop loss. Forex opens at 00:00 GMT.

But will close not at the stopLoss price, but at the first price, which may be much lower than the stopLoss! And TakeProfit will close for sure. Therefore it is better not to leave with StopLoss, and even better not to leave positions for the weekend!
 

How can I find out the address of my user function? That is, if my listing says

int start()
...
   int num=myFunc()//вызов функции
...
int myFunc()//описание моей функции
 {
    ...
 }

then how do I get the address of myFunc? I need it to find out how to find out address of WndProc (I describe with custom function) for passing further to class parameter.

 
paladin80:
Must close on a stop loss. Forex opens at 00:00 GMT.

It is far from certain, it may well close at the first quote. You have to read the documents, and the brokerage companies write whatever they want.
 
gyfto:

How can I find out the address of my user function? That is, if my listing says

then how do I get the address of myFunc? I need it to find out how to find out address of WndProc (I describe with custom function) for passing further to class parameter.


Who says it even has an address? it's an MQL4-function: it's not even compiled in the literal sense of the word, but runs through the interpreter at runtime.
 

Why doesn't the expert modify orders?

Here's the function:

//+-------------------------------------------------------------------------------------+
//| Первоначальная установка TP и SL                                                    |
//+-------------------------------------------------------------------------------------+
void OrdersModifyer(int ticket)
{ 
   double SL, TP;
    
   if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP)
   { 
       SL = ND(OrderOpenPrice() + i_sl * pt);
       TP = ND(OrderOpenPrice() - i_tp * pt); 
       
       if (SL - Ask <= g_stopLevel)
           SL = Ask + g_stopLevel;
       if (Ask - TP <= g_stopLevel)
           TP = Ask - g_stopLevel;
       
       if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0, Red))
       {
          Print ("Ошибка модификации ордера ", OrderType(), " - ", GetLastError());
          return(false);
       }
   }
       
   if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
   { 
       SL = ND(OrderOpenPrice() - i_sl * pt);
       TP = ND(OrderOpenPrice() + i_tp * pt);
       
       if (Bid - SL <= g_stopLevel)
           SL = Bid - g_stopLevel;
       if (TP - Bid <= g_stopLevel)
           TP = Bid + g_stopLevel;
       
       if (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0, Red))
       {
          Print ("Ошибка модификации ордера ", OrderType(), " - ", GetLastError());
          return(false);
       }
   }
}

Called at the start like this:

 for (g = OrdersTotal() - 1; g >= 0; g--)
   {
       if (!OrderSelect(g,SELECT_BY_POS)) continue;
       if (i_magic != -1) if (OrderMagicNumber() != (i_magic)) continue;
       if (OrderSymbol() != Symbol()) continue;
       
       ticket = OrderTicket();
       type = OrderType();
       
       if (i_sl != 0 || i_tp != 0)
       {
          if (OrderStopLoss() == 0 && OrderTakeProfit() == 0)
          {
             OrdersModifyer(ticket);
          }
       }
   }
 
TarasBY:

Thank you for your help.
 
alsu:

Who said that it even has an address? It's an MQL4 function: it's not even compiled in the literal sense of the word, but runs through an interpreter at runtime.


That's where the dog is buried. I'm just sorry for 2 or 3 weeks of wasting my time, because I've chosen an independent windowing interface for my robot within just MQL4+WinAPI without any self-written dlls. I'm sorry I didn't realize it earlier, I'm sorry for my own code and developments.

To summarize. You cannot create an overlapped (i.e. not a child) window without copying the code into your dll, because when describing WNDCLASS (or WNDCLASSEX)

typedef struct tagWNDCLASSEX {//    это с MSDN
  UINT      cbSize;
  UINT      style;
  WNDPROC   lpfnWndProc;//<-
  int       cbClsExtra;
  int       cbWndExtra;
  HINSTANCE hInstance;
  HICON     hIcon;
  HCURSOR   hCursor;
  HBRUSH    hbrBackground;
  LPCTSTR   lpszMenuName;
  LPCTSTR   lpszClassName;
  HICON     hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;

lines indicated by the arrow when packing the structure into an int array

lpwcx[0]=0x30;//cbSize//    это на MQL4
lpwcx[1]=0x0A23;//style
//lpwcx[2]=lpfnWndProc;<-
lpwcx[3]=0;//cbClsExtra
lpwcx[4]=0;//cbWndExtra
lpwcx[5]=GetModuleHandleA(lpModuleName);//hInstance
lpwcx[6]=LoadIconA(hInstance,IDI[0]);//hIcon
lpwcx[7]=LoadCursorA(hInstance,IDC[0]);//hCursor
lpwcx[8]=GetStockObject(WHITE_BRUSH);//hbrBackground
lpwcx[9]=StrStrA(lpszMenuName,lpszMenuName);
lpwcx[10]=StrStrA(lpszClassName,lpszClassName);
lpwcx[11]=0;//hIconSm
//передаём структуру в упакованном интовом массиве и регистрируем класс
atom=RegisterClassExA(lpwcx[12]);

array, the address of window procedure, i.e. mouse and keyboard handler for this window, is passed. The window procedure in MQL4 can be implemented as a user-defined function, but it is impossible to get its address within the interpreter, so there is nothing to pass. The maximum that is possible in MQL4 is to use the standard window classes, but they will be used only as the child windows. To put it simply, a window created by the indicator cannot be grasped with a mouse and placed over the terminal border (since it will be a child window), while an overlapped window can be placed over the terminal border. The child window on standard window classes is already implemented in mt4gui.dll, if anyone needs. But the overlapped window with its own mouse and keyboard handler is impossible.

I ask moderators to post this dialog and all related messages to a separate topic like "how to create a window in MQL4", so that others won't make the same mistakes and will be able to find it in a search engine.

 
Hello, I downloaded metatreider4. the trading tab is not popping up as it did in the demo version(((. tell me what's wrong??????
 

Good day!

Does the broker read the ip address of the trader's computer only in online mode or is it technically possible to upload the history from some folder in MT4?

 

I decided to implement "hotkeys" (without using the control keys like Ctrl, Alt, Shift). But the code doesn't work.

#property indicator_chart_window
#import "user32.dll"
bool RegisterHotKey(int hWnd, int id, int fsModifiers, int vk);
bool PeekMessage (int& lpMsg[7], int hWnd, int wMsgFilterMin, int wMsgFilterMax, int wRemoveMsg);
bool UnregisterHotKey (int hWnd, int id);
#import

extern string s0="идентификатор горячей клавиши";
extern int id;
extern string s1="код клавиши (список см. winuser.h)";
extern int vk;
extern string s2="номер окна (от нуля до WindowsTotal()-1)";
extern int aWindowNumber;
bool PM;

int init()
  {
   ObjectCreate("Smile",OBJ_LABEL,aWindowNumber,0,0);
   ObjectSet("Smile",OBJPROP_XDISTANCE,0);
   ObjectSet("Smile",OBJPROP_YDISTANCE,0);
   ObjectSetText("Smile", StringSetChar("", 0, 75), 50, "WingDings", Red);
   return(RegisterHotKey(WindowHandle(Symbol(), Period()), id, 0, vk));
  }

int deinit()
  {
   ObjectDelete("Smile");
   WindowRedraw();
   return(UnregisterHotKey(WindowHandle(Symbol(), Period()), id));
  }

int start()
  {
   int lpMsg[7];
   /*
   Структура lpMsg для WM_HOTKEY:
   0 - хэндл окна//HWND(MSDN)//int(MQL4)
   1 - WM_HOTKEY (0x0312)//UINT(MSDN)//int(MQL4)
   2 - заданный id//WPARAM(MSDN)//int(MQL4)
   3 - млардшее слово - ноль (модификатор, - не задаём), старшее - код виртуальной клавиши//LPARAM(MSDN)//int(MQL4)
   4 - время//DWORD(MSDN)//int(MQL4)
   5 - координата х мышки//структура POINT. LONG(MSDN)//int(MQL4)
   6- координата у мышки//LONG(MSDN)//int(MQL4)
   */
   PM=PeekMessage(lpMsg, WindowHandle(Symbol(), Period()), 0, 0, 1);//1 = PM_REMOVE
   if (lpMsg[1]==0x0312){
      if(lpMsg[2]==id){
         switch(StringGetChar(ObjectDescription("Smile"),0)){
            case 74 : ObjectSetText("Smile", StringSetChar("", 0, 75), 50, "WingDings", Red);
            case 75 : ObjectSetText("Smile", StringSetChar("", 0, 74), 50, "WingDings", Red);
            }
      }
   }
   return(0);
  }

Why would it not work? In theory, the smiley is supposed to change. I set 81 (Q key code), but you can set anything there. Here are the key codes:

1  2  3  4  5  6  7  8
49 50 51 52 53 54 55 56
Q  W  E  R  T  Y  U  I
81 87 69 82 84 89 85 73
A  S  D  F  G  H  J  K
65 83 68 70 71 72 74 75
Z  X  C  V  B  N  M  ,
90 88 67 86 66 78 77 188

Added: can't call PeekMessage - system error 127 "specified procedure not found". RegisterHotKey returns 1 (true). I tried to look calling RtlGetLastWin32Error() with NativeAPI after PeekMessage, it does not even come to it. And to point

PM=PeekMessage(lpMsg[],...

- the compilation error will appear.