感谢Daniel的回复,代码位于start(){...}
中,如下所示。
我有点困惑为什么它不起作用。
希望我提供的详细信息就足够了:
int SYMBOL_NUMBER_LIMIT = 3;
int start()
{
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 )
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;
}
}
}
}
}
答案 0 :(得分:1)
input int SYMBOL_NUMBER_LIMIT;
int start(){
// some logic
int direction; string symbol;//these parameters to initialize to send a new trade
// some function to get a new direction and symbol
if(direction!=0 && symbol!=NULL){
bool allowSendNewTrade=isNewTradeAllowed(symbol);
if(allowSendNewTrade)OrderSend(symbol,lot,direction>0?OP_BUY:OP_SELL,0,0,0);
}
return(0);
}
bool isNewTradeAllowed(string symbolInQuestion){
string symbols[];
int SYMBOLS_IN_TRADE_SO_FAR=0;
ArrayResize(symbols,OrdersTotal());
for(int i=OrdersTotal()-1;i>=0;i--){
if(!OrderSelect(i,SELECT_BY_POS))continue;
string currentSymbol=OrderSymbol();
boolean symbolAlreadyInList=false;
for(int j=SYMBOLS_IN_TRADE_SO_FAR-1;j>=0;j--){
if(symbols[j]==currentSymbol){
symbolAlreadyInList=true;
break;
}
}
if(!symbolAlreadyInList)
symbols[SYMBOLS_IN_TRADE_SO_FAR++]=currentSymbol;
}
if(SYMBOLS_IN_TRADE_SO_FAR>SYMBOL_NUMBER_LIMIT)
return false;
if(SYMBOLS_IN_TRADE_SO_FAR==SYMBOL_NUMBER_LIMIT){
for(int j=SYMBOLS_IN_TRADE_SO_FAR-1;j>=0;j--){
if(symbols[SYMBOLS_IN_TRADE_SO_FAR]==symbolInQuestion)
return true;
}
return false;
}
return true; //SYMBOLS_IN_TRADE_SO_FAR<SYMBOL_NUMBER_LIMIT
}
答案 1 :(得分:-1)
您的代码缺少 session_start()
-代码块语法结尾括号。
{...}