我正在尝试创建一个专家顾问(EA),以将打开符号的数量限制为3
例如,如果我将EA加载到15个不同的交易品种上,则在任何特定时间都不会开设超过3个交易品种。下面是我插入到EA中但无法正常工作的代码:
int SYMBOL_NUMBER_LIMIT = 3;
string COUNTED_SYMBOLS[];
ArrayResize(COUNTED_SYMBOLS, SYMBOL_NUMBER_LIMIT, 0);
for(int s=0; s<SYMBOL_NUMBER_LIMIT; s++) COUNTED_SYMBOLS[s]="";
int SYMBOLS_IN_TRADE_SO_FAR = 0;
bool NEW_TRADE_PERMISSION = true;
int ALL_POSITIONS = OrdersTotal(); // PositionsTotal();
if(ALL_POSITIONS > 0)
{
for(int index=0; index<ALL_POSITIONS; index++)
{
string THIS_SYMBOL = OrderSymbol(); // PositionGetSymbol(index);
bool Symbol_already_counted = false;
for(int i=0; i<SYMBOL_NUMBER_LIMIT; i++)
{
if(COUNTED_SYMBOLS[i]==THIS_SYMBOL)
{
Symbol_already_counted = true;
break;
}
if(Symbol_already_counted) continue;
else
{
SYMBOLS_IN_TRADE_SO_FAR++;
if(SYMBOLS_IN_TRADE_SO_FAR >= SYMBOL_NUMBER_LIMIT)
{
NEW_TRADE_PERMISSION = false;
break;
}
for(int j=0; j<SYMBOL_NUMBER_LIMIT; j++)
if(COUNTED_SYMBOLS[j]=="")
{
COUNTED_SYMBOLS[j] = THIS_SYMBOL;
break;
}
}
}
}
}
我会尽一切帮助使它如我所描述的那样工作。预先感谢