MQL4問題請教 - 財經
By Sarah
at 2019-01-01T00:33
at 2019-01-01T00:33
Table of Contents
關於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的狀況就不用寫了嗎?
另外這樣寫有什麼用意或好處嗎?
希望有好心人能解答我的疑問,先謝謝了...
--
Tags:
財經
All Comments
By Faithe
at 2019-01-04T02:55
at 2019-01-04T02:55
By Tom
at 2019-01-06T14:44
at 2019-01-06T14:44
By Ula
at 2019-01-08T14:08
at 2019-01-08T14:08
By Zanna
at 2019-01-13T10:58
at 2019-01-13T10:58
By Oscar
at 2019-01-14T21:41
at 2019-01-14T21:41
By Rachel
at 2019-01-19T12:15
at 2019-01-19T12:15
By Erin
at 2019-01-20T15:10
at 2019-01-20T15:10
By George
at 2019-01-23T01:50
at 2019-01-23T01:50
By Yuri
at 2019-01-26T07:48
at 2019-01-26T07:48
By Jessica
at 2019-01-28T08:34
at 2019-01-28T08:34
By Gilbert
at 2019-01-30T14:25
at 2019-01-30T14:25
By Carol
at 2019-02-02T07:38
at 2019-02-02T07:38
By Oliver
at 2019-02-05T05:14
at 2019-02-05T05:14
By Joseph
at 2019-02-07T13:57
at 2019-02-07T13:57
By Gary
at 2019-02-10T15:49
at 2019-02-10T15:49
By Queena
at 2019-02-13T06:51
at 2019-02-13T06:51
By Hedwig
at 2019-02-14T19:42
at 2019-02-14T19:42
By Robert
at 2019-02-17T15:31
at 2019-02-17T15:31
By Todd Johnson
at 2019-02-19T19:32
at 2019-02-19T19:32
Related Posts
程式交易- 如何粗略判斷/預測盤勢?
By David
at 2018-12-20T13:24
at 2018-12-20T13:24
求檔:2018/12/11及12/12台指期成交檔及上下5檔
By Charlotte
at 2018-12-16T02:53
at 2018-12-16T02:53
想詢問一下大家對SQ的看法
By Rebecca
at 2018-12-10T22:05
at 2018-12-10T22:05
MC之後 程式交易下一步選擇
By Kama
at 2018-12-06T16:31
at 2018-12-06T16:31
Multicharts加碼(程式重開後的倉位?)
By Eden
at 2018-12-04T21:53
at 2018-12-04T21:53