【发布时间】:2015-12-31 09:20:08
【问题描述】:
第二个 if 语句无法执行,我完全筋疲力尽了。
我最初的想法是当波动率在 90 - 110 范围内时,程序将发送一个且只有一个订单。等到波动率达到111-150区间后,才会发出二单。
如果我这里不使用bool函数,程序会在达到范围时发送countless命令。
有人可以帮帮我吗?
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;
}
【问题讨论】:
-
如果 TodayMaxVolatilityPercentage >= 110.0,那么可以肯定,TodayMaxVolatilityPercentage > 90.0。所以把第二个 if 子句放在前面,这样逻辑就会被执行。我想这会有所帮助。或者,您可以为 TodayMaxVolatilityPercentage 定义范围,因此您添加一个检查:
if (TodayMaxVolatilityPercentage >=90 && TodayMaxVolatilityPercentage <110) -
在您的第一个
if(TodayMaxVolatilityPercentage>=90.0正文中,您也有if(TodayMaxVolatilityPercentage>=110.0),但没有任何内容写入TodayMaxVolatilityPercentage(在您显示的代码中)。真的可以改变吗?
标签: trading algorithmic-trading mql4 metatrader4