[MQL4] Need few tips writing an expert advisor

 

Hi all.

I worked with MQL4 too long time ago and my skills went bit rusted!

And someone asked me to give him few simple things to learn about market, for example a statistics calc (sum of all open orders.. profanity :D) at each graph tick. (wants to track his money making machine performance per each EA at realtime :D :D :D).

I see this https://docs.mql4.com/trading/OrdersTotal so it is possible to get all open orders in a loop. Questions:

1. What function should I implement to intercept a signal about new order being placed (by other EA)/trade complete, if any ?

2. What function .... to intercept a chart update? (need each tick signal)

3. Where I can put a loop that does, like, { i = OrdersTotal .. sleep 10; }

What is the best way to notice orders being open by other advisors?

 

1. I'm not aware of any, and I've looked hard. AFAIK only scanning & selecting orders can do it. If I'm wrong someone PLEASE let me know!

2. Read The Manual. start() gives you that for free; it's (near enough) called for each tick

3. Your idea of "sleep 10" worries me. MT4 is an event driven concept and you should only sleep if you must (e.g. trying to open or close an order that's not happening due to slippage). Using can cause my previous 'near enough' to be inaccurate.
If you find that looping all orders each tick is stealing too much CPU, then to do it no more frequently than every 10 seconds consider something like:

static datetime LastOrderScan = 0;
   if(TimeCurrent() > LastOrderTime + 10)
   {
      DoOrderScan();
      LastOrderTime = TimeCurrent();
   )

(code is just typed, not compiled, checked or tested)

 

an idea for your first question


use global variables from one ea to another, if you want to enable/disable to take position


here: https://book.mql4.com/variables/globals

 

greatdragon:

1. What function should I implement to intercept a signal about new order being placed (by other EA)/trade complete, if any ?

2. What function .... to intercept a chart update? (need each tick signal)

3. Where I can put a loop that does, like, { i = OrdersTotal .. sleep 10; }

What is the best way to notice orders being open by other advisors?

  1. This is no intercept (Mql5 only.) Remember the previous count in a static. If the new count differs ...
  2. Each tick calls start()
  3. Don't sleep. Return from start. Otherwise you'll need to while(!IsStopped()){ RefreshRate(); ... Sleep(..); }
Reason: