Download MetaTrader 5

keybd_event() does not work on Backtest for F12 key

To add comments, please log in or register
tachigi
10
tachigi  
I usually do manual backtesting and use F12 key to forward the candlestick one be one. (F12 key in backtesting is mentioned at  https://www.fxdayjob.com/manual-backtesting-in-mt4)
I want to speed up this, e.g., by pressing S key, 5 or 10 candlesticks are forwarded.
I wrote the following code, but the result is that pressing S key, sometimes one candlestick, sometimes two, at most three candlesticks come out.

I wonder why it is not five.

I even tried to make a dll using Visual C++ in which calling SendInput Windows API and in mql code to call the dll function, however, I did not get expected result.

Could someone please tell me the reason or any workaround?
Thank you!!!



#import "user32.dll"

    void keybd_event(int bVk, int bScan, int dwFlags,int dwExtraInfo);

#import


#define  KEYEVENTF_KEYUP 0x0002   //--- key is released (not pressed)


void OnChartEvent(const int id,         // Event identifier  

                  const long& lparam,   // Event parameter of long type

                  const double& dparam, // Event parameter of double type

                  const string& sparam) // Event parameter of string type

{

   

   if (id == CHARTEVENT_KEYDOWN)

   {

      switch(int(lparam))

      {

         case 0x53: // 'S'

         keybd_event(0x7B, 0, 0, 0); // F12   1th

         keybd_event(0x7B, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x7B, 0, 0, 0); // F12   2nd

         keybd_event(0x7B, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x7B, 0, 0, 0); // F12   3rd

         keybd_event(0x7B, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x7B, 0, 0, 0); // F12   4th

         keybd_event(0x7B, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x7B, 0, 0, 0); // F12   5th

         keybd_event(0x7B, 0, KEYEVENTF_KEYUP , 0);

         break;


         default:

         break;

      }

   }

}


Manual Backtesting Tips for Metatrader 4 (MT4)
Manual Backtesting Tips for Metatrader 4 (MT4)
  • 2016.06.06
  • www.fxdayjob.com
Manual backtesting is crucial when it comes to proving the profitability of a new trading strategy. Manual backtesting tips for Metatrader 4 (MT4).
tachigi
10
tachigi  

By the way, if not sending F12 but code of 'A' key it works fine.

if (id == CHARTEVENT_KEYDOWN)

   {

      switch(int(lparam))

      {

         case 0x53: // 'S'

         keybd_event(0x41, 0, 0, 0); // A   1th

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   2nd

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   3rd

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   4th

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   5th

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         break;

         

         case 0x41:

         Print("A");


         default:

         break;

      }

   }


tachigi
10
tachigi  
tachigi:

By the way, if not sending F12 but code of 'A' key it works fine.

if (id == CHARTEVENT_KEYDOWN)

   {

      switch(int(lparam))

      {

         case 0x53: // 'S'

         keybd_event(0x41, 0, 0, 0); // A   1th

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   2nd

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   3rd

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   4th

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         

         keybd_event(0x41, 0, 0, 0); // A   5th

         keybd_event(0x41, 0, KEYEVENTF_KEYUP , 0);

         break;

         

         case 0x41:

         Print("A");


         default:

         break;

      }

   }



Hello, no one can help to answer me? Is this the bug of mt4?

To add comments, please log in or register