Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

votes: 30
2013.03.01 13:38
2016.09.23 09:03
incmidi.mqh (5.03 KB)view
emidi.mq5 (4.68 KB)view

A class to control the MIDI device is located in the IncMIDI.mqh file. The example of its use is represented in the eMIDI.mq5 file.

The order of using the CMIDI class

  1. Connect a file with a class:
    #include <IncMIDI.mqh>
  2. Declare a class:
    CMIDI m;
  3. Transfer music program using the SetMusic(string & aMusic[]) method.

  4. Enable playback using the Play(bool aSynch=true) method. If aSynch is true, play is performed in a synchronous mode in the cycle with pauses using the Sleep() function. If aSynch is false, play is performed in a synchronous mode, besides you can stop play using the Stop() method. To work in a synchronous mode from the OnChartEvent() function of the Expert Advisor the ChartEvent() method must be called.

  5. Call the Stop() method upon completion of work. It is necessary for the MIDI device closing, otherwise to rerun it you should restart the terminal.

Music program

Music program is recorded in the string array. In one array element is written a list of actions. Actions are written by a comma. At first a command, an equal sign and a command value are written. The following commands are available:

  • Tick - time in milliseconds through which all the commands of one array element will be performed. It defines the tempo with which the play is performed.
  • Volume - the volume level, from 0 to 100.
  • VolumeL - the left channel volume level, from 0 to 100.
  • VolumeR - the right channel volume level, from 0 to 100.
  • Instrument - selection of the music instrument, from 0 to 127.
  • NoteDN - press a key. Number 60 corresponds to "do" note of the main octave, 61 - to "C sharp", 62 - to "re", etc.
  • NoteUP - release a key. For several instruments you cannot use release a key, the sound fades away itself, and for some keys it is obligatory to press.

It is possible to take chords, for example, "NoteDN=57, NoteDN=60, NoteDN=64". A possible parallel play on several instruments, for example, "Instrument=1, NoteDN=60, Instrument=123, NoteDN=60". Different instruments' volume can not be changed, all is played on the same volume, but you can change the volume of different parts of playing, for example:

"Tick=1500, Instrument=123, Volume=100, NoteDN=60",
"VolumeL=0, VolumeR=100, NoteDN=64",
"VolumeL=100, VolumeR=0, NoteDN=57",
"Volume=50, NoteDN=67, NoneDN=57",
"Volume=25, NoteDN=64, NoneDN=67"

The CMIDI class methods 

  • void ChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) - called from the function when using play in an asynchronous mode.
  • void Play(bool aSynch=true) - enable play. If aSynch is false, from the OnChartEvent function the ChartEvent() method must be called.  
  • void Stop() - stop play in an asynchronous play. Stop play and close the device.
  • void SetMusic(string & aMusic[]) - sending an array with a music program.
  • void SetEventID(ushort aID) - setting a number of a custom event. It is necessary when using play in an asynchronous mode. It is not necessary to call, default value is 1.

Translated from Russian by MetaQuotes Software Corp.
Original code:

MD5 Hash MD5 Hash

Calculation of 32 digit string MD5-hash from transmitted byte array

EMAPredictive3 EMAPredictive3

The Moving Average drawn on the basis of the EMA algorithm. A linear interpolation of two different period EMA is used

i-Friday_Sig i-Friday_Sig

Signals of entries and exits on the system "Friday effect"

Narrowest Range Signal Narrowest Range Signal

The narrowest range indicator defines the moments when the market is in the "compressed" state that says of the future breakthrough in this or that side