This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please visit upgrade to a browser that supports web standards. It's free and painless.

MT4外匯智能交易系統-網賺理財小舖 會員登入 會員註冊

« 上一篇 | 下一篇 »

這是小唐我最近在測試的程式
這是利用在一分鐘線的交易程式自動買及平倉
這程式的缺點目前在於下殺的情況下還無法判斷
所以如果有高手願意賜教 我會非常歡迎您唷
歡迎加入論壇一起討論
 
 

 


//+------------------------------------------------------------------+
//|
http://www.olmcmall.com |
//| 無傭致贏外匯交易 MT4 智能交易系統 |
//| 測試版 V1.0 小唐 歡迎大家一起研究 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2006、OKwh "
#property link ""
#define MAGICMA 200610011231
//+------------------------------------------------------------------+
//| 注意沒有指標檔案那些property |
//+------------------------------------------------------------------+
extern int whichmethod = 3; //1~4 種下單方式
extern double TakeProfit = 3; // 賺三點就平倉
extern double StopLoss = 20; //止損20
extern double MaximumRisk = 0.05; //根據可用保證金計算首筆開倉手數,0.05代表5%的保證金風險;0.3
extern double TrailingStop =25; //追蹤止損
extern int maxOpen = 3; //最多持倉限制 3
extern double maxLots = 0.1; //最多單倉限制 5
extern int bb = 0; //非零就跟蹤止贏
extern double MATrendPeriod=26;//使用26均線

int i,p2,xxx,p1,res;
double Lots;
datetime lasttime;
int init() //初始化
{
Lots = 1;
lasttime = NULL;
return(0);
}
int deinit() { return(0); } //反初始化
//主程序
int start()
{
CheckForOpen();
if (bb>0) CTP(); //跟蹤止贏
return(0);
}
//+------下面是各子程序--------------------------------------------+
double LotsOptimized() //確定下單量,開倉調用
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//MarketInfo(Symbol(),MODE_MINLOT);
//MarketInfo(Symbol(),MODE_MAXLOT);
//MarketInfo(Symbol(),MODE_LOTSTEP);
lot=NormalizeDouble(MaximumRisk * AccountBalance()/AccountLeverage(),1);
if(lot<0.1) lot=0.1;
if(lot>maxLots) lot=maxLots;
return(lot);
}

//平倉持有的買單
void CloseBuy()
{
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i<0;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
Sleep(1000);
}
}
}
}


//平倉持有的賣單
void CloseSell()
{
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i<0;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
Sleep(10000);
}
}
}
}


// 抓最後一筆訂單的價錢

double GetLastOrderPrice()

{

double LastOrderPrice;

if (OrdersTotal() > 0 )

{

OrderSelect(OrdersTotal()-1, SELECT_BY_POS);

LastOrderPrice = OrderOpenPrice();

}

return(LastOrderPrice);

}

//+............................

//判斷是否買或賣或平倉
int buyorsell() //在這個函數計算設置你的交易信號
{
double MacdCurrent,MacdPrevious,SignalCurrent;
double SignalPrevious,MaCurrent,MaPrevious;
double Macdnew,LastPrice;



Macdnew=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); //目前macd值
MacdCurrent=iStochastic(NULL,0,9,9,8,MODE_SMA,0,MODE_MAIN,0); //目前stoch值
//MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious=iStochastic(NULL,0,9,9,8,MODE_SMA,0,MODE_MAIN,1);


//SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalCurrent=iStochastic(NULL,NULL,0,9,9,8,PRICE_CLOSE,MODE_SIGNAL,0);

//SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious=iStochastic(NULL,NULL,0,9,9,8,PRICE_CLOSE,MODE_SIGNAL,1);

MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);

//strMain = iStochastic(NULL,0,9,9,8,MODE_SMA,0,MODE_MAIN,0);

LastPrice = GetLastOrderPrice()-0.03;


//if(MacdCurrent<20 && MacdCurrent>SignalCurrent && Bid<123.50) //設定stoch<25且價位需低於123.5
if(MacdCurrent<22 && Macdnew<-0.005 && Bid<122 && LastPrice<Bid) //macd值小於-0.002且價位低於123.5買進

return (1); // 買 Ma在上升,Macd在0線上,並且兩線上交叉
Sleep(3000);

if(MacdCurrent>80 && MacdCurrent<SignalCurrent)

return (-1); // 賣
return (0); //不交易
}
int nowbuyorsell = 0;
void CheckForOpen()
{
if (Time[0] == lasttime ) return; //每時間週期檢查一次
lasttime = Time[0];
nowbuyorsell = buyorsell(); //獲取買賣信號

if (nowbuyorsell == 1) //買 先結束已賣的
CloseSell();


if (nowbuyorsell == -1) //賣 先結束已買的
CloseBuy();


//if (TimeDayOfWeek(CurTime()) == 1)
//{
//if (TimeHour(CurTime()) < 3 ) return; //週一早8點前不做
//}
//if (TimeDayOfWeek(CurTime()) == 5)
//{
//if (TimeHour(CurTime()) > 19 ) return; //週五晚11點後不做
//}

if (OrdersTotal( ) >= maxOpen) return ;
//如果已持有開倉數達到最大,不做
if (nowbuyorsell==0) return; //不交易
TradeOK(); //去下單交易
}
void TradeOK() //去下單交易
{
int error ;
if (nowbuyorsell == 1) //買
{
switch (whichmethod)
{
case 1: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);break;
case 2: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-StopLoss*Point,0,"",MAGICMA,0,Blue); break;
case 3: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);break;
case 4: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);break;
default : res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);break;
}
if (res <=0)
{
error=GetLastError();
if(error==134)Print("Received 134 Error after OrderSend() !! "); // not enough money
if(error==135) RefreshRates(); // prices have changed
}
Sleep(10000);
return ;
}
if (nowbuyorsell == -1) //賣
{
switch (whichmethod)
{
case 1: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); break;
case 2: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+StopLoss*Point,0,"",MAGICMA,0,Red); break;
case 3: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,Bid-TakeProfit*Point,"",MAGICMA,0,Red); break;
case 4: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red); break;
default : res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); break;
}
if (res <=0)
{
error=GetLastError();
if(error==134) Print("Received 134 Error after OrderSend() !! "); // not enough money
if(error==135) RefreshRates(); // prices have changed
}
Sleep(10000);
return ;
}
}




void CTP() //跟蹤止贏
{
bool bs = false;
for (int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (OrderType() == OP_BUY)
{
if ((Bid - OrderOpenPrice()) > (TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT)))
{
if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT))
{
bs = OrderModify(OrderTicket(),OrderOpenPrice(),Bid - TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),0,Green);
}
}
}
else if (OrderType() == OP_SELL)
{
if ((OrderOpenPrice() - Ask) > (TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT)))
{
if ((OrderStopLoss()) > (Ask + TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT)))
{
bs = OrderModify(OrderTicket(),OrderOpenPrice(),
Ask + TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),0,Tan);
}
}
}
}
}

發表回應
  1. Re: FXDD-這是我最近在測試的智能交易系統 [回覆]

    要如何設定智能交易系統啊!!
    可以請教一下前輩嗎 ?

    ANDY 回應於 07 七月, 2009 14:53

  2. Re: FXDD-這是我最近在測試的智能交易系統 [回覆]

    你好
    請問有再幫人寫程式或是做智能交易測試的嗎
    如果方便可以和您聯絡嗎?

    邦 回應於 10 十月, 2009 14:40

  3. Re: FXDD-這是我最近在測試的智能交易系統 [回覆]

    請問有在代工寫MT4程式嗎?

    syej 回應於 27 十一月, 2009 23:15

  4. Re: FXDD-這是我最近在測試的智能交易系統 [回覆]

    請問可以一下,怎麼跟您聯絡呢?想多多瞭解外匯保證金~

    明德 回應於 04 三月, 2010 01:23

  5. Re: FXDD-這是我最近在測試的智能交易系統 [回覆]

    您的部落格有很不錯的資訊喔!也歡迎來紅財神外匯套利研究學院
    ,這是外匯套利自動交易者的共同學習園地。「穩定獲利、降低風險、財務自由、幫助他人」是我們研究外匯的核心精神與目標。這裡沒有短期的驚人績效,也沒有神奇的技術指標,只有長期穩定獲利的套利自動交易系統(月績效5%~20%),如果你想一夜致富,那你就來錯地方了。紅財神(Ganapati)又稱象鼻財神,是印度非常有名的財神。希望有緣來這裡的人,都能得到紅財神的照顧,財富資糧俱足,身心健康,人生如意圓滿
    http://ganapati.pixnet.net/blog

    紅財神外匯套利研究學院 回應於 24 三月, 2010 22:22