//+------------------------------------------------------------------+
//| @My05613828 |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "@Π.EA 大树My05613828"
#property link "https://www.eahub.cn/space-uid-8564.html"
#property version "1.0"
#property strict
input double lot_=0.01;//手数
input int magic_number=12365;
input string macd_path ="双线MACD";//macd路径
input int fast=12,slow=26,macd=9;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
OnTick();
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double dif0 = 求自定义指标值(Symbol(),PERIOD_CURRENT,macd_path,fast,slow,macd,0,0);
double dif1 = 求自定义指标值(Symbol(),PERIOD_CURRENT,macd_path,fast,slow,macd,0,1);
double dif2 = 求自定义指标值(Symbol(),PERIOD_CURRENT,macd_path,fast,slow,macd,0,2);
double dea0 = 求自定义指标值(Symbol(),PERIOD_CURRENT,macd_path,fast,slow,macd,1,0);
double dea1 = 求自定义指标值(Symbol(),PERIOD_CURRENT,macd_path,fast,slow,macd,1,1);
double dea2 = 求自定义指标值(Symbol(),PERIOD_CURRENT,macd_path,fast,slow,macd,1,2);
bool open_long = dif1>dea1 && dif2<dea2;
bool close_long = dif1<dea1 && dif2>dea2;
if(close_long)
平多(Symbol(),magic_number);
if(open_long)
做多(Symbol(),lot_,0,0,magic_number,"open_sell");
//+------------------------------------------------------------------+
bool open_short = dif1<dea1 && dif2>dea2;
bool close_short = dif1>dea1 && dif2<dea2;
if(close_short)
平空(Symbol(),magic_number);
if(open_short)
做空(Symbol(),lot_,0,0,magic_number,"open_sell");
//----
Comment("dif: "+(string)dif0,"\ndea: "+(string)dea0);
}
//+------------------------------------------------------------------+//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
template<typename u,typename v,typename w>
double 求自定义指标值(string 币种,ENUM_TIMEFRAMES 图表周期,string 自定义指标路径,u 参数1,v 参数2,w 参数3,int 缓存=0,int 序号=0)
{
double 返回值= iCustom(币种,图表周期,自定义指标路径,参数1,参数2,参数3,缓存,序号);
return 返回值;
}
//+------------------------------------------------------------------+
void 平多(string 币种,int magic)
{
bool result=false;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)&&持仓类型())
{
if(OrderTicket()>0)
{
if(OrderSymbol()==币种&&OrderMagicNumber()==magic)
{
switch(OrderType())
{
case OP_BUY:
result=OrderClose(OrderTicket(),OrderLots(),卖价(OrderSymbol()),(int)deviation(-1,币种),Yellow);
break;
}
}
}
}
}
}
//+------------------------------------------------------------------+
void 平空(string 币种,int magic)
{
bool result=false;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)&&持仓类型())
{
if(OrderTicket()>0)
{
if(OrderSymbol()==币种&&OrderMagicNumber()==magic)
{
switch(OrderType())
{
case OP_SELL:
result=OrderClose(OrderTicket(),OrderLots(),买价(OrderSymbol()),(int)deviation(-1,币种),Red);
break;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
bool 持仓类型()
{
bool 检测=OrderType()==OP_BUY||OrderType()==OP_SELL;
return 检测;
}
//+------------------------------------------------------------------+
int 做多(string 币种,double 手数,double 止损点数,double 止盈点数,int magic,string 注释)
{
double 止损价格=买价(币种)-止损点数*点值(币种);
double 止盈价格=买价(币种)+止盈点数*点值(币种);
if(止损点数==0||止损点数==1||止损点数==2)
止损价格=0;
if(止盈点数==0||止盈点数==1||止盈点数==2)
止盈价格=0;
int 多=OrderSend(币种,0,手数,买价(币种),(int)deviation(-1,币种),止损价格,止盈价格,注释,magic,0,Violet);
if(多<0)
多=OrderSend(币种,0,手数,买价(币种),(int)deviation(-1,币种),止损价格,止盈价格,注释,magic,0,Violet);
if(多<0)
{
Print("OrderSend 做多 with error #",GetLastError());
return 多;
}
return 多;
}
//+------------------------------------------------------------------+
int 做空(string 币种,double 手数,double 止损点数,double 止盈点数,int magic,string 注释)
{
double 止损价格=卖价(币种)+止损点数*点值(币种);
double 止盈价格=卖价(币种)-止盈点数*点值(币种);
if(止损点数==0||止损点数==1||止损点数==2)
止损价格=0;
if(止盈点数==0||止盈点数==1||止盈点数==2)
止盈价格=0;
int 空=OrderSend(币种,1,手数,卖价(币种),(int)deviation(-1,币种),止损价格,止盈价格,注释,magic,0,Violet);
if(空<0)
空=OrderSend(币种,1,手数,卖价(币种),(int)deviation(-1,币种),止损价格,止盈价格,注释,magic,0,Violet);
if(空<0)
{
Print("OrderSend 做空 with error #",GetLastError());
return 空;
}
return 空;
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double 买价(string 币种="")
{
double 价=SymbolInfoDouble(币种,SYMBOL_ASK);
return(价);
}
//----------
double 卖价(string 币种="")
{
double 价=SymbolInfoDouble(币种,SYMBOL_BID);
return(价);
}
//+------------------------------------------------------------------+
double 点值(string 币种="")
{
double 点=MarketInfo(币种,MODE_POINT)*系数(币种);
return(点);
}
//+------------------------------------------------------------------+
long deviation(long dev,string symbol)
{
if(dev<0)
dev=SymbolInfoInteger(symbol,SYMBOL_SPREAD);
return dev;
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double 系数(string symbol,bool 国际点差自适应=true)
{
double 系数=1;
if(
MarketInfo(symbol,MODE_DIGITS)==3
|| MarketInfo(symbol,MODE_DIGITS)==5
|| (StringFind(symbol,"XAU",0)==0 && MarketInfo(symbol,MODE_DIGITS)==2)
||(StringFind(symbol,"GOLD",0)==0&&MarketInfo(symbol,MODE_DIGITS)==2)
||(StringFind(symbol,"Gold",0)==0&&MarketInfo(symbol,MODE_DIGITS)==2)
|| (StringFind(symbol,"USD_GLD",0)==0 && MarketInfo(symbol,MODE_DIGITS)==2)
)
系数=10;
if(StringFind(symbol,"XAU",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)
系数=100;
if(StringFind(symbol,"GOLD",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)
系数=100;
if(StringFind(symbol,"Gold",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)
系数=100;
if(StringFind(symbol,"USD_GLD",0)==0 && MarketInfo(symbol,MODE_DIGITS)==3)
系数=100;
系数=系数*0.1;
if(StringFind(AccountInfoString(ACCOUNT_SERVER),"Exness")!=-1||StringFind(AccountInfoString(ACCOUNT_SERVER),"EXNESS")!=-1||StringFind(AccountInfoString(ACCOUNT_SERVER),"exness")!=-1)
系数=系数*0.1;
if(国际点差自适应==false)
return(1);
return(系数);
}
//+------------------------------------------------------------------+
楼主,改成多空都做了,免费不收钱 |