0

对于止损对象,我需要该功能,包括每次调用时(即在每个时间间隔内)都会递增的乘数,但在第一次调用之前(即开仓时),它必须重置为 0(将其重置为SL 对象的结尾是不可能的,因为当 SL 被击中时,该对象不会被调用)。当我尝试使用在 SL 类之外声明的全局变量时,出现编译错误(“缺少声明”;该类被放置在包含文件中,以防信息很重要)。

除了让我的 SL 对象成为函数(可以访问全局变量)之外,还有其他方法吗?

非常感谢!

4

1 回答 1

1
int  stoplossMultiplier,
     lastOpenedTicket;

void OnInit(){
     stoplossMultiplier = 0;
     lastOpenedTicket   = 0;                // also possible to find among open
}

int  TradeSend(){
  // do what you need here, include ticket = OrderSend(); function
  // compute lot based on stoplossMultiplier
     lastOpenedTicket = ticket;
}

void OnTick(){
     if ( lastOpenedTicket >  0 ){
          if ( !isTicketExist( lastOpenedTicket() ){
                if (  isClosedByStopLoss( lastOpenedTicket() ) ){
                      stoplossMultiplier = 0;
                }else{
                      stoplossMultiplier++;
                }
          }
     }
}

bool isTicketExist(      int ticket ){ /* make sure order is open        */ }
bool isClosedByStopLoss( int ticket ){ /* loop over OrdersHistoryTotal() */ }
于 2018-02-22T22:24:34.257 回答