Reply

Bug or problem on my VPS lagging?, i got a lot of terminals and EAs working on my VPS but sometimes SL+TP not set on the order?, why?

24 replies

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

8 years ago #114929

Bug or problem on my VPS lagging?, i got a lot of terminals and EAs working on my VPS but sometimes SL+TP not set on the order?, why?

 

is it because of my VPS lagging?, or there is something wrong with the mql4 code?, my VPS is on high CPU+MEMORY usage regularly because of the many terminals and EAs working,

maybe because of this?..

 

it is very rare but it happened to me the 3rd time already..

 

 

did it happened to somebody here also?.., thanks..

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

7 years ago #136121

Nope, im getting the 146 error of “Trade context is busy” nothing else..,

 

yesterday i have modified the mql4 code and added the command to wait if the context is busy, but still having that same error, BTW that error only happens on the DEMO accounts with live account i’m not getting any error what so ever..,

what could it be?

0

mikeyc

Customer, bbp_participant, community, 877 replies.

Visit profile

7 years ago #136122

Trade context busy is either an overloaded terminal or the broker taking a long time to process orders.

 

If it still occurs after a reboot, I’d look at a different broker.

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

7 years ago #136124

Tried that also with the same EAs on Global Prime Demo server, same shit..,

but i already modified the mql4 code again, so ill see what will happen next,

ill update.. and if i fixed it ill post the fix,

 

thank you for your participation.

0

geektrader

Customer, bbp_participant, community, 522 replies.

Visit profile

7 years ago #136155

This is a simple one: you do NEVER EVER run more than 8 EAs per MT4 instance if you want reliable order execution (which you most likely want if trading with real money)! It is one of the many MT4 terminal limitations (some years ago it was 1 thread only per MT4 instance!) and has nothing to do with your broker at all (@mikeyc: if the broker is overloaded you will not get “trade context is busy” but “trade timeout”, nowadays though I have yet to see one of the serious brokers showing this error anymore).

It´s simply because there can only be 8 order operations be processed at once in each MT4 terminal (either opening a new order, modifying a existing one, closing an existing one) and you can´t do anything about that since the shitty MT4 terminal is designed like that.

 

Surely there are “hacks” around that and the EA could simply retry to modify the order if it failed before becasue of a busy trade context or the EA could check for if the trade context is free or not and wait if it is not before it passes on it´s next command to do something with an order. But these solutions are not very safe nor acceptable in live trading since they always delay things in one way or the other. If the EA retries after an error, price can have moved to far already. Especially during news your order might never get the needed SL because it already moved beyond/above it and it simply can´t be set to the desired value anymore then. Same with waiting for trade context to become free, this costs to much time as well and is highly unsafe because of that too.

 

The only solution if you are serious about live trading: run only 8 EA´s per MT4 instance! It´s just that easy and no way around with any kind of hacks if you want a reliable and fast order execution / modification all the time. If your VPS is fast enough as you say, that is no problem. Personally I have 7 MT4 terminals running, each with 8 EA´s (not all are SQ ones). Just copy your existing MT4 folder to a new one and that´s it, you have your next instance. The only thing you have to keep in mind is another limitation that is set by the MT4 terminal (yes, again!): you can only run 32 MT4 instances per machine. Number 33 simply won´t launch, even if you´ve copied to to another directory again. MQ introduced that after the latency arbitrage by BTN Lightning where they were “ripping off” these poor MT4 brokers on a massive scale by running up to 200 MT4 instances on mega-servers. I´ve already tried to crack that limitation, but it´s not easy since MT4 itself is wrapped into a virtual machine via the Themida copy protection method. So concluded: the max EA´s you will be able to run RELIABLE without getting another VPS is  32 x 8 = 256 EAs.

 

P.S.: If you want the unreliable solution (wait for the trade context to become free), use my code (I have tested this live too and did run 50 EA´s in one MT4 instance with it without any order ever throwing any error about trade context not being free):

int CheckTradeContext()
{

uint   WaitLimitTradeContext = 120; //seconds

    if (!IsTesting() && !IsTradeAllowed() && !IsStopped())
    {
        int ticks = GetTickCount();
        Print("Trade Context Is Busy! Waiting Until It Becomes Free...");
        while (true)
        {
            RefreshRates();
            Print("Waiting For Trade Context To Become Free...");
            if (IsStopped())
            {
                Print("The Expert Was Terminated By The User!");
                return(-1);
            }
            if (GetTickCount() - ticks > 1000 * WaitLimitTradeContext)
            {
                Print("The Maximum Waiting Limit Of " + WaitLimitTradeContext + " Seconds Was Exceeded!");
                return(-2);
            }
            if (IsTradeAllowed())
            {
                Print("Trade Context Has Become Free!");
                return(0);
            }
            Sleep(50);
        }
    }
    //Print("Trade Context Is Free!");

    return(1);
}

Then, before any order sending / modification / closing put: if (CheckTradeContext() >= 0) ….


🚀 Unlock Your Edge in Automated Forex Strategy Development 🚀

Historical Forex Data Starting From 1987, 28 Pairs, M1, 99% Error-Free, Lifetime Free Updates

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

7 years ago #136171

Thank you geektrader,

i did however already created a function for it:

void CheckIfBusy()
{
  if(!IsTesting())
  while(IsTradeContextBusy()){//Print("#ERROR!: Order ("+OrderType()+") - Delayed.");
  Sleep(50);RefreshRates();}
}

but your’s more sophisticated with a timer, i’ve already edited all my EAs with that new function of yours :),

thank you for your time to write down this huge post also,

about the 8 thread thinggy and the link of official metaquotes update: https://forum.mql4.com/54431

so thank you once again for making it clear and that you’ve added more information on that subject!,

So from my understanding there is no problem to run multiple MT4 instances on the same trading account?, just need to set MagicNumbers differently between all the EAs did i get it right?..,

And what if the EAs are very active to some extent?, should i then divide the portfolio not by 8,8,8,8 but in 4,4,4,4 EAs on same instance?…,

thank you will wait for your answer mate.

0

geektrader

Customer, bbp_participant, community, 522 replies.

Visit profile

7 years ago #136179

Good to hear you are on the way to a non-busy-trade-context:) It´s really easy, you have to do nothing special, just use 8 EAs per MT4 instance, configure them the same way as if they were in 1 terminal (different magic number etc of course). You can run an unlimited number of connections to your broker to the same account, that´s no problem (at least 32 connections/terminals to the same account are possible, that´s how far I´ve tested it). If they are very active doesn´t matter, each MT4 terminal can do 8 trade operations in parallel, doesn´t matter how active the EAs are as long as you don´t do more than 8 requests at once per terminal, it will work just fine, even if each EA sends a command all 1ms:)


🚀 Unlock Your Edge in Automated Forex Strategy Development 🚀

Historical Forex Data Starting From 1987, 28 Pairs, M1, 99% Error-Free, Lifetime Free Updates

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

7 years ago #136180

Good to hear you are on the way to a non-busy-trade-context:) It´s really easy, you have to do nothing special, just use 8 EAs per MT4 instance, configure them the same way as if they were in 1 terminal (different magic number etc of course). You can run an unlimited number of connections to your broker to the same account, that´s no problem (at least 32 connections/terminals to the same account are possible, that´s how far I´ve tested it). If they are very active doesn´t matter, each MT4 terminal can do 8 trade operations in parallel, doesn´t matter how active the EAs are as long as you don´t do more than 8 requests at once per terminal, it will work just fine, even if each EA sends a command all 1ms:)

 

Thank you once again geektrader :),

i have 29 EAs so i spited them into 5 MT4s, 6x6x6x6x5, they are activ EAs and trading daily so just in case i’ve put only 6 per terminal,

 

thanks mate thats very critical information, i haven’t knew about that 8 threads thing i thought it was only 1 per terminal hehe..

have a great week and many green pips to you!  B)

0

geektrader

Customer, bbp_participant, community, 522 replies.

Visit profile

7 years ago #136181

Yes I see, my EA´s trade each 15 minutes (modifying pending orders – 8 at once each time), it´s really fine if you use 8 per terminal, even if they are “crazy scalpers”, since each EA is processed serial only in the MQL4 language, with 8 EAs you will never ever get a busy trade context – no need to waste resources really. You can safely use 8 per terminal.

 

Yes, in the past it was only 1 operation per terminal, had heaps of terminals running by that time. MT4 just SUCKS!

 

Green pips to you too:)


🚀 Unlock Your Edge in Automated Forex Strategy Development 🚀

Historical Forex Data Starting From 1987, 28 Pairs, M1, 99% Error-Free, Lifetime Free Updates

0

Viewing 8 replies - 16 through 23 (of 23 total)

1 2