Emulation of ticks from an EA/indicator - page 8

 
expertboss, do you even need a 2008 server? In my opinion, the capabilities of 2003 are enough, and it is less demanding on resources, which means that you can choose cheaper hardware.
 
Meat:

If this clock of yours is an expert (not an indicator), then in all likelihood it is simply looped, so it has no problem getting information across multiple symbols. This is what I wrote about earlier, that there really is no big problem with ticks in Expert Advisor, because it can be looped. But with an indicator this number won't work.

As for the different OS, it is still a mystery to me. As I wrote above, it works fine on my computer on 7, but other people don't have it for some reason. Probably something to do with access rights...

By the way, regarding "replacement libraries", try to take user32 and kernel32 files from WinXP(2003) and stick them in Experts\libraries folder on that computer where Vista(2008) is installed. What if it works? :) ...although I doubt it...

I'll tell directly on the ticks, I'm on "your side" but as for the clock, judging by your answer, you have not understood my thought I will try with the code:

int init()

{

ObjectCreate("ServerTime", OBJ_LABEL, 0,0,0,0,0;)

ObjectSet("ServerTime", OBJPROP_CORNER, 3);

ObjectSet("ServerTime", OBJPROP_XDISTANCE, 10);

ObjectSet("ServerTime", OBJPROP_YDISTANCE, 37);

ObjectSetText("ServerTime", "", 20, "Arial", Green);

return;

}

int start()

{

ObjectSetText("ServerTime", TimeToStr( TimeCurrent(), TIME_SECONDS ));

...

return;

}

If there is only one symbol in the "Market Watch" window, for which a chart is created, the time and the update of the time also coincides with the tick in the chart and accordingly with the work of Expert Advisor. If there are several symbols in the "Market Watch" window, then the small watch that displays in the "Market Watch : 22:59:58" header, those clocks are ticking almost all the time, they are ticking somewhere and as the quote has changed on my currency pair so my clocks are aligned with those ones. That's my idea """" if these all ticks can be added and applied to my EA or a window where the EA works"". and end up with a lot more ticks than just one pair quote.

Alexander.

I don't want to loop resources ... That is, to combine all ticks from all quotations in one chart?

 

What makes you gentlemen think this is aggression? It is merely a reminder of the principles of politeness. Before you offer something, you have to put something in return. If you have nothing you can only ask and this is the truth.

I am not very experienced in 64-bit systems but I am very interested in this topic, but as I can do nothing to help here I have to ask people who know. I see nothing shameful in it.

 
FAQ:

What makes you gentlemen think this is aggression? It is merely a reminder of the principles of politeness. Before you offer something, you have to put something in return. If you have nothing you can only ask and this is the truth.

I am not very experienced in 64-bit systems but I am very interested in this topic, but as I can do nothing to help here I have to ask people who know. I can't see anything wrong in it.


I guess I got caught up in my emotions, but you are a moderator and you watch your mouth, thank you for the remark and I will try to cool my ardour.

Goodbye. Alexander.

 
expertboss:

Here is the thought """" whether these all ticks can be added up and applied to my Expert Advisor or the window where the Expert Advisor works""" and end up with a lot more ticks than a quote for just one pair.

Alexander.

I don't want to loop resources ... That is, you want to combine all the ticks from all the quotes in one chart?

An EA only reacts to its own ticks, so you cannot "add" anything. There are only two options: either you set a timer (as I suggested), or you run in parallel a looped EA on another chart, which will "tick" your EA. And in this looped EA, you can specify the conditions under which it will "tick". For example, if the value of TimeCurrent() has changed, as in your case. Although, again, I don't see the point in having an additional EA, if the initial EA (i.e., your clock) can do the same.

 
Actually, imho, the solution to all problems would be to find the address of the Start function in memory :) Then you could think of many things, up to multi-threaded program execution.
 
I faced a problem with the following plan when the terminal does not receive regular ticks and the timer is running respectively EA is working through the code and at some point the EA starts sending false requests for example to close the order, there it turns out in the end the server sends a general error "2" then error "3" and may also give by the order number, etc. I got out of the situation this way """""""""""" if (OrdersTotal()==0){Alert ("Nothing to delete");Sleep(1000);break;} // If there are no orders, exit the loop by closing """"""""""""" (exit while), but you know, it's a little bit incorrect. Question: is it possible to make some kind of command or operator (I don't even know what to call it) to suspend ticks until we get a reply from the server true (for example true=OrderClose (OrderTicket(),....) and then as usual. Of course, this is a request, as far as it is possible. One more observation (I noticed it at the weekend) - if I shift the chart, it will go back to the position of the generator or a regular tick, the button "EAs" is released and there are no ticks, but the chart goes back anyway, I have removed the EA from the chart, all this has stopped. Sv. Alexander.
 
Meat:

Anyway, here is the final version of the function:

// push ebp; move ebp,esp; push 01; push 02; push MT4InternMsg; push hWnd; mov eax,PostMsgAddr; call eax; pop ebp; ret 0010;

As far as I understand, you use the PostMessageA(hwnd, RegisterWindowMessageA("MetaTrader4_Internal_Message"), 2, 1) command. This command emulates ticks for the Expert Advisor (according to the description in WinUser32.h). For indicators the ticks are not emulated, and consequently the indicator is not updated. Unfortunately, I don't have WinXP for testing, but if the ticks for the indicator are emulated in XP, I am surprised.

I also checked your algorithm

  for (int i=0;  i<ArraySize(value);  i++)
    for (int j=0;  j<len[i];  j++, byte++)
      TimerCode[byte/4] |= value[i]>>(8*j)&0xFF<<(byte%4*8);

under the debugger VisualStudio and the result I got in the TimerCode array did not at all correspond to expected results. Are you sure this algorithm doesn't contain errors? I can give you the code and a screenshot of the result. If you want, we may discuss it in more detail.

 

Although this topic is not very actual now, but I think there are still those who are not in a hurry to switch to new builds :) So, if someone does not have tick timer in Win7/Win8, you must either disable DEP tool or add this function:

#import "kernel32.dll"
  bool  VirtualProtect(int lpAddress[], int dwSize, int flNewProtect, int& lpflOldProtect[]);

And in the end this variant:

int SetMyTimer(int interval=1000, int timerId=0)
{    
  int MT4InternMsg= RegisterWindowMessageA("MetaTrader4_Internal_Message");
  int hWnd= WindowHandle(Symbol(),Period());
  int PostMsgAddr= GetProcAddress(GetModuleHandleA("user32.dll"),"PostMessageA");
  if (PostMsgAddr==0 || hWnd==0) return(0);
  static int TimerCode[7];  ArrayInitialize(TimerCode,0);
  int oldprotect[1]; 
  VirtualProtect(TimerCode, ArraySize(TimerCode)*4, 0x40, oldprotect);  // PAGE_EXECUTE_READWRITE
  // push ebp; move ebp,esp; push 01; push 02; push MT4InternMsg; push hWnd; mov eax,PostMsgAddr; call eax; pop ebp; ret 0010;    
  int bytes[]={ 0x55, 0x8B,0xEC, 0x6A,01, 0x6A,02, 0x68,0000, 0x68,0000, 0xB8,0000, 0xFF,0xD0, 0x5D, 0xC2,0x10 };
  int len[]=  { 1,    1,   1,    1,   1,  1,   1,  1,   4,    1,   4,    1,   4,    1,   1,    1,    1,   2 };
  bytes[8]=MT4InternMsg;  bytes[10]=hWnd;  bytes[12]=PostMsgAddr;
  int nbyte=0;  
  for (int i=0;  i<ArraySize(bytes);  i++)
    for (int j=0;  j<len[i];  j++, nbyte++)
      TimerCode[nbyte/4] |= bytes[i]>>(8*j)&0xFF<<(nbyte%4*8);
  timerId= SetTimer(hWnd, timerId, interval, TimerCode);
  return (timerId);
}