Ea macd 金叉 死叉交易
mt4吧
全部回复
仅看楼主
level 1
timeofsky2012 楼主
//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double TakeProfitLevel;
double StopLossLevel;
double minstoplevel=60;//100 point to stop and take
//Alert("Minimum Stop Level=",minstoplevel*Point," points");
double stoploss=NormalizeDouble(Bid-minstoplevel*Point,Digits);
double takeprofit=NormalizeDouble(Bid+minstoplevel*Point,Digits);
//---
// Alert("TakeProfitLevel =",TakeProfitLevel);
// Alert("StopLossLevel =",StopLossLevel);
//Buy(stoploss,takeprofit);
// Alert("Cross =",Macd());
if(Macd()==1){
Buy(stoploss,takeprofit);
}
if(Macd()==0){
Sell(stoploss,takeprofit);
}
}
//+------------------------------------------------------------------+
int Macd(){
float Macd12,Macd26,MacdBar;
int result=2;
MacdBar=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
Macd12=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
Macd26=Macd12-MacdBar;
float perMacdBar=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
float perMacd12=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
float perMacd26=Macd12-MacdBar;
//Alert("MacdBar=",MacdBar,"perMacdBar=",perMacdBar);
//Alert("Macd12=",Macd12,"perMacd12=",perMacd12);
//Alert("Macd26=",Macd26,"perMacd26=",perMacd26);
//Golden cross under water
if(perMacd12<perMacd26&&Macd12>Macd26&&perMacd12<0&&perMacd26<0){
result=1;
}
//Death cross above water
if(perMacd12>perMacd26&&Macd12<Macd26&&perMacd12>0&&perMacd26>0){
result=0;
}
return result;
}
int Buy(double stoploss,double takeprofit ){
int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,stoploss,takeprofit,"My order",16384,0,clrGreen);
Alert("ticket =",ticket);
if(ticket<0)
{
Alert("buy GetLastError() =",GetLastError());
Print("BUY OrderSend failed with error #",GetLastError());
}
else{
Print("OrderSend placed successfully");
}
return ticket;
}
int Sell(double stoploss,double takeprofit ){
int ticket=OrderSend(Symbol(),OP_SELL,1,Bid,3,takeprofit,stoploss,"My sell order",16384,0,clrGreen);
Alert("ticket =",ticket);
if(ticket<0)
{
Alert("GetLastError() =",GetLastError());
Print("OrderSend failed with error #",GetLastError());
}
else{
Print("OrderSend placed successfully");
}
return ticket;
}
//+------------------------------------------------------------------+
2016年06月01日 06点06分 1
level 1
timeofsky2012 楼主
//+------------------------------------------------------------------+
//| practise.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"",110,0,Red);
//OrderSend(Symbol(),OP_BUY,1,Bid,3,0,0,"My order",16384,0,clrGreen);
//---
Alert("total=",OrdersTotal());
Alert("AccountEquity=",AccountEquity());
//get by 0
Alert("Order select",OrderSelect(0,SELECT_BY_POS,MODE_TRADES));
Alert("OrderMagicNumber=",OrderMagicNumber());
Alert("OrderType=",OrderType());
Alert("OP_SELL=",OP_SELL);
Alert("OrderTicket=",OrderTicket());
Alert("profit=",OrderProfit());
Alert("OrderLots()=",OrderLots());
Alert("Close[2]=",Close[2]);
Alert("Open[1]=",Open[1]);
Alert("High[0]=",High[0]);
}
//+------------------------------------------------------------------+
2016年06月02日 09点06分 2
level 1
楼主,要是macd仅仅要15分钟周期的,金叉买进,死叉卖出,
持仓1单,手数自定义,止盈止损不带,要怎么修改呢?
2017年05月22日 13点05分 6
1