0

if由于无法执行第二条语句,我完全筋疲力尽。

我最初的想法是当波动率在 90 - 110 范围内时,程序将发送一个且仅一个订单。等到波动率达到111-150区间后,再下单

如果我这里不使用bool函数,程序会在到达范围时发送无数的命令。

有人可以帮我吗?

  if (  TodayMaxVolatilityPercentage >= 90.0
     && ( dayTrend  == 1 )
     && orderOpened == false
        )
  {
        Print( "Entered if clause" );
     // Print( "Today volatility percentage is: ", TodayMaxVolatilityPercentage + "%" );
     // ticket: Returns number of the ticket assigned to the order by the trade server or -1 if it fails.
        ticket = OrderSend( Symbol(),
                            OP_SELL,
                            0.3,
                            Bid,
                            3,
                             0 * MyPoint,
                            30 * MyPoint,
                            NULL,
                            MagicNumber,
                            0,
                            Blue
                            );
        Print( "Order is opened on", OrderOpenTime()+" at price: ", OrderOpenPrice() );
        Print( "trend number is ",dayTrend );

        if (  ticket > 0 )
        {
              if (  TakeProfit > 0 ) TheTakeProfit = Bid - TakeProfit * MyPoint;
              OrderSelect( ticket, SELECT_BY_TICKET ); // bool value
           /* OrderModify( OrderTicket(),
                           OrderOpenPrice(),
                           0,
                           NormalizeDouble( TheTakeProfit, Digits  ),
                           0,
                           Green
                           );
                         */
        }
        orderOpened = true;
        if (  TodayMaxVolatilityPercentage >= 110.0 ) orderOpened = false;              
  }
  if (  TodayMaxVolatilityPercentage >= 110.0
     && ( dayTrend  == 1 )
     && orderOpened == false
        )
  {
        Print( "Entered second if clause" );
     // ticket: Returns number of the ticket assigned to the order by the trade server or -1 if it fails.
        ticket = OrderSend(  Symbol(),
                             OP_SELL,
                             0.3,
                             Bid,
                             3,
                              0 * MyPoint,
                             30 * MyPoint,
                             NULL,
                             MagicNumber,
                             0,
                             Blue
                             );
        if (  ticket > 0 )
        {
              if (  TakeProfit > 0 ) TheTakeProfit = Bid - TakeProfit * MyPoint;
              OrderSelect( ticket, SELECT_BY_TICKET ); // bool value
           /* OrderModify( OrderTicket(),
                           OrderOpenPrice(),
                           0,
                           NormalizeDouble( TheTakeProfit, Digits ),
                           0,
                           Green
                           );
                       */
        }
        orderOpened = true;
     }
4

1 回答 1

0

一个隐藏的表演者:

按照设计,第一个成功OrderSend()返回一个您分配给ticket = OrderSend(...).

魔鬼隐藏在细节之中。

[MQL4-Help]说:

返回交易服务器分配给订单的票-1,如果失败则返回。

因此,返回的第一个成功OrderSend()票证# 是0(在 StrategyTester 中,一个真正的 MT4/Server 会从db.pool票证中抽取大量数字)。

因此,第二个if ( ticket > 0 )永远不会让你进来。

通常宁可使用if ( ticket > EMPTY ),以便也阐明意图并使用符号而不是-1整数常量。

于 2015-10-03T16:33:19.967 回答