需要MQL帮助,如何生成密钥

时间:2017-11-08 03:39:58

标签: mql4

我正在努力解决一个代码问题。它是专家顾问的密钥生成线。有人可以帮我弄清楚如何通过使用这一行来生成密钥:

int key=3*(StringToInteger(StringSubstr(IntegerToString(AccountNumber()), 0, 3)))+333333;

2 个答案:

答案 0 :(得分:0)

问题是什么?

int accountNumber = AccountNumber(); string accountNumberString = IntegerToString(accountNumber); string accountNumberStringFirst3Digits= StringSubstr(accountNumberString,0,3); int accountNumberFirstThreeDigits = StringToInteger(accountNumberStringFirst3Digits); int accountNumberFirstThreeDigitsMultiplied = 3 * accountNumberFirstThreeDigits; int key = accountNumberFirstThreeDigitsMultiplied + 333333;

答案 1 :(得分:0)

有人可以帮我弄清楚如何通过这条线生成密钥吗?

欢迎,当然,让我们来看看:

int key = 3*(StringToInteger(StringSubstr(IntegerToString(AccountNumber()), 0, 3)))+333333;

您的代码实际上意味着:

//   +------------------------------------------------------------------------------- type declaration
//   |   +--------------------------------------------------------------------------- variable name definition
//   |   | +------------------------------------------------------------------------- assignment operator
//   |   | | +----------------------------------------------------------------------- compile-time integer constant
//   |   | | | +--------------------------------------------------------------------- multiply operator
//   |   | | | |                  +-------------------------------------------------- MT4 system function: StringToInteger( aString )
//   |   | | | |                  |             +------------------------------------ MT4 system function: StringSubstr(    aString, aPosToStartSubstrFrom, aSubstrLength )
//   |   | | | |                  |             |                +------------------- MT4 system function: IntegerToString( aIntNum )                    |              |
//   |   | | | |                  |             |                |              +---- MT4 system function: AccountNumber()                               |              |
//   |   | | | |                  |             |                |              |                                                                        |              |
//   |   | | | |                  |             |                |              |     +------------------------------------------------------------------+              |
//   |   | | | |                  |             |                |              |     |  +------------------------------------------------------------------------------+
//   |   | | | |                  |             |                |              |     |  |
   int key = 3 * ( StringToInteger( StringSubstr( IntegerToString( AccountNumber() ), 0, 3 ) ) )
           + 333333;
//         |      ||
//         +------||----------------------------------------------------------------- add operator
//                +|----------------------------------------------------------------- compile-time integer constant
//                 +----------------------------------------------------------------- literal MQL4-language syntax-terminator

上面的代码定义并生成一个公平的整数值,因此,只要您的EA交易代码引用 key 的值,就会使用此计算值(另请参阅文档关于 -MQL4有效范围,在此范围内,此变量仍然可见。)