Alternative to Sleep() function in MT4 that can be tested?
Results 1 to 4 of 4

Thread: Alternative to Sleep() function in MT4 that can be tested?

  1. #1
    Is there an alternate to the Sleep() code in MT4 which can be used for testing in the Strategy Tester?

    According to MT4 documentation, Sleep() function Doesn't suspend execution of the Expert Advisor in the Strategy Tester.

    I would like see how the performance of an EA test results changes if I suspend trading after a large TP for X amount of time.

    Any tips on the best way to implement this so it can be tested?

  2. #2
    Before entery a new trade, just check the last trade close time and if enough time has elapsed (your delay prior to resume trading).

  3. #3
    So this is what I have done up to now, it is testing. Unfortunately not too as I had hoped, it is filtering more good trades than poor...
    At least it is testing for the time being. May tweak it later or just remove it.

    Added

    dual TimeMicroSecNow;
    dual TimeMicroSecAfterEQP;
    extern int MicroSecAfterEQP = 60000000;


    Replaced Sleep with:

    TimeMicroSecAfterEQP = GetMicrosecondCount();


    And Before new trades:

    TimeMicroSecNow = GetMicrosecondCount(); RefreshRates();
    if (TimeMicroSecNow gt; TimeMicroSecAfterEQP MicroSecAfterEQP)
    TRADE;

  4. #4
    Any workarounds would be appreciated.

    Basically I had something like this. . .until I understood it does nothing in evaluation mode. I would like something which will simulate the sleep OR freeze or pause function and will operate in evaluation mode also. I have a function that will shut out all open transactions if an open position exceeds an extended maximum profit range. I want to test suspending any prospective transactions for X amount of time and that I need it to appear in test mode also.

    Inserted Code void PipMaxCloseOut() int totalorders = OrdersTotal(); for(int I=totalorders-1;igt;=0;I--) if(! OrderSelect(i, SELECT_BY_POS)) Print(TimeToStr(TimeCurrent(),TIME_SECONDS), CHECK Function gt; , __FUNCTION__, !!!!! , OrderMagicNumber(), Error code , GetLastError()); else int result; if ((OrdersTotal() gt; 0) (OrderMagicNumber() == Trade1L)) RefreshRates(); Print(TimeToStr(TimeCurrent(),TIME_SECONDS), CLOSING Trade1L PipMax CLOSE OUT, Order PL:, OrderProfit(), Bid:, MarketInfo(Trade,MODE_BID), Open Trades:, OrdersTotal()); result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Tr ade,MODE_BID),MaxSlippage*2,CLR_NONE); if (result lt;= -1) Print(ERROR WHILE TRYING TO CLOSE Trade1L DURING PipMax CLOSE OUT! ERROR CODE #, GetLastError()); if ((OrdersTotal() gt; 0) (OrderMagicNumber() == Trade1S)) RefreshRates(); Printing (TimeToStr(TimeCurrent(),TIME_SECONDS), CLOSING Trade1S PipMax CLOSE OUT, Order PL:, OrderProfit(), Ask:, MarketInfo(Trade,MODE_ASK), Open Trades:, OrdersTotal()); result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Tr ade,MODE_ASK),MaxSlippage*two,CLR_NONE); if (result lt;= -1) Print(ERROR WHILE TRYING TO CLOSE Trade1S DURING PipMax CLOSE OUT! ERROR CODE # , GetLastError()); Sleep(MilliSecs);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information