關於MT4自帶的範例MACD Sample,有些疑問一直想不清楚,
google半天也找不到答案,想請教版上的前輩高手
以下為第89行到123行的程式碼
//--- it is important to enter the market correctly, but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) <------(1)
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- should it be closed?
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDCloseLevel*Point))
{
//--- close order and exit
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)) <--(2)
Print("OrderClose error ",GetLastError());
return;
}
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
(3)----> if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
我用括號標註了3個地方(抱歉,不知道怎麼上色...)
(1)第92行的!OrderSelect
(2)第105行的!OrderClose
(3)第117行的!OrderModify
想請問是只要有寫==false的情況,==true的狀況就不用寫了嗎?
另外這樣寫有什麼用意或好處嗎?
希望有好心人能解答我的疑問,先謝謝了...
--
google半天也找不到答案,想請教版上的前輩高手
以下為第89行到123行的程式碼
//--- it is important to enter the market correctly, but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) <------(1)
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- should it be closed?
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDCloseLevel*Point))
{
//--- close order and exit
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)) <--(2)
Print("OrderClose error ",GetLastError());
return;
}
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
(3)----> if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
我用括號標註了3個地方(抱歉,不知道怎麼上色...)
(1)第92行的!OrderSelect
(2)第105行的!OrderClose
(3)第117行的!OrderModify
想請問是只要有寫==false的情況,==true的狀況就不用寫了嗎?
另外這樣寫有什麼用意或好處嗎?
希望有好心人能解答我的疑問,先謝謝了...
--
All Comments