Monday 22 August 2011

MQL4 Magic Number Provision

This include script assigns a preset magic number to an EA, it can be useful during development as it means you you dont have to manually reassign the magic number to the EA every time you recompile it.

I placed all this code in an include file called "Inc_AssignMagic.mq4" and then referenced it in my EA using the directive: #include <Inc_AssignMagic.mqh>


From OrderSend you can call the function AssignMagic(Symbol()) to populate the magic number for the order. Please note this is not suitable for multiple time frames, but could be easy adapted.

//+------------------------------------------------------------------+
//|                                              Inc_AssignMagic.mqh |
//|                               Copyright © Jul 2011, Nigel Martin |
//|                                  http://nigel-forex.blogspot.com |
//+------------------------------------------------------------------+
//#property copyright "©2011, Nigel Martin"
//#property link      "http://nigex-forex.blogspot.com"

// Version 1.0

//+------------------------------------------------------------------+
//| Return Magic Number                                              |
//+------------------------------------------------------------------+

 int AssignMagic(string symbol)
 {
    // AUD
    if(symbol == "AUDCAD") { return(111111); }
    if(symbol == "AUDJPY") { return(111222); }
    if(symbol == "AUDNZD") { return(111333); }
    if(symbol == "AUDUSD") { return(111444); }

    // CAD
    if(symbol == "CADJPY") { return(333111); }
  
    // CHF
    if(symbol == "CHFJPY") { return(333222); }
  
    // EUR
    if(symbol == "EURAUD") { return(555111); }
    if(symbol == "EURCAD") { return(555222); }
    if(symbol == "EURCHF") { return(555333); }
    if(symbol == "EURGBP") { return(555444); }
    if(symbol == "EURJPY") { return(555555); }
    if(symbol == "EURUSD") { return(555666); }
  
    // GBP
    if(symbol == "GBPCHF") { return(777111); }
    if(symbol == "GBPJPY") { return(777222); }
    if(symbol == "GBPUSD") { return(777222); }

    // JPY
  
    // NZD
    if(symbol == "NZDUSD") { return(014111); }

    // USD
    if(symbol == "USDCAD") { return(021111); }
    if(symbol == "USDCHF") { return(021222); }
    if(symbol == "USDJPY") { return(021333); }
  
    return(0);       
 }

1 comment:

  1. Imagine if you had a robot with 6 years authenticated live proof?

    I just got done with a webinar with Mark and his partner, Antony, two days ago and it was AWESOME.

    During the webinar Mark and Antony shared their secrets to success and answered questions about their new version of the GPS Forex Robot that is coming out TODAY!

    ReplyDelete