根据以下MT5中的EA交易代码写一组可以用来交易的另外一组的EA交易代码:+------------------------------------------------------------------+ MACDSimpleReshetovbarabashkakvns editionmq5 Co
以下是一组可用于交易的EA交易代码:
//+------------------------------------------------------------------+ //| MACDSimpleReshetov(barabashkakvn's edition).mq5 | //| Copyright © 2006, Yury V. Reshetov | //| http://reshetov.xnet.uz/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Yury V. Reshetov ICQ: 282715499" #property link "http://reshetov.xnet.uz/" #property version "1.000"
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
CPositionInfo  m_position;
CTrade         m_trade;
CSymbolInfo    m_symbol;
input double   Lots        = 2;
input uchar    DF          = 1;
input uchar    DS          = 2;
input uchar    SignalPeriod= 10;
input ulong    m_magic=42828093;
ulong          m_slippage=10;
int handle_iMACD;
int OnInit() {
if(!m_symbol.Name(Symbol())) return(INIT_FAILED); RefreshRates();
string err_text=""; if(!CheckVolumeValue(Lots,err_text)) { Print(err_text); return(INIT_PARAMETERS_INCORRECT); }
m_trade.SetExpertMagicNumber(m_magic);
if(IsFillingTypeAllowed(SYMBOL_FILLING_FOK)) m_trade.SetTypeFilling(ORDER_FILLING_FOK); else if(IsFillingTypeAllowed(SYMBOL_FILLING_IOC)) m_trade.SetTypeFilling(ORDER_FILLING_IOC); else m_trade.SetTypeFilling(ORDER_FILLING_RETURN);
m_trade.SetDeviationInPoints(m_slippage);
handle_iMACD=iMACD(m_symbol.Name(),Period(),SignalPeriod+DF,SignalPeriod+DS+DF,SignalPeriod,PRICE_CLOSE);
if(handle_iMACD==INVALID_HANDLE) { PrintFormat("Failed to create handle of the iMACD indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); return(INIT_FAILED); }
return(INIT_SUCCEEDED); }
void OnDeinit(const int reason) {
}
void OnTick() {
static datetime PrevBars=0; datetime time_0=iTime(0); if(time_0==PrevBars) return; PrevBars=time_0;
double main=iMACDGet(MAIN_LINE,0); double signal=iMACDGet(SIGNAL_LINE,0);
for(int i=PositionsTotal()-1;i>=0;i--) if(m_position.SelectByIndex(i)) if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic) { if(m_position.PositionType()==POSITION_TYPE_BUY && main<0) { m_trade.PositionClose(m_position.Ticket()); return; } else if(m_position.PositionType()==POSITION_TYPE_SELL && main>0) { m_trade.PositionClose(m_position.Ticket()); return; } return; }
if((main*signal)>0) { if(main>0) { if(main>signal) m_trade.Buy(Lots,m_symbol.Name()); return; } else { if(main<signal) m_trade.Sell(Lots,m_symbol.Name()); return; } } }
bool RefreshRates(void) {
if(!m_symbol.RefreshRates()) { Print("RefreshRates error"); return(false); }
if(m_symbol.Ask()==0 || m_symbol.Bid()==0) return(false);
return(true); }
bool CheckVolumeValue(double volume,string &error_description) {
double min_volume=m_symbol.LotsMin(); if(volume<min_volume) { error_description=StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume); return(false); }
double max_volume=m_symbol.LotsMax(); if(volume>max_volume) { error_description=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume); return(false); }
double volume_step=m_symbol.LotsStep(); int ratio=(int)MathRound(volume/volume_step); if(MathAbs(ratiovolume_step-volume)>0.0000001) { error_description=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f", volume_step,ratiovolume_step); return(false); } error_description="Correct volume value"; return(true); }
bool IsFillingTypeAllowed(int fill_type) { int filling=m_symbol.TradeFillFlags(); return((filling & fill_type)==fill_type); }
datetime iTime(const int index,string symbol=NULL,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT) { if(symbol==NULL) symbol=m_symbol.Name(); if(timeframe==0) timeframe=Period(); datetime Time[1]; datetime time=0; int copied=CopyTime(symbol,timeframe,index,1,Time); if(copied>0) time=Time[0]; return(time); }
double iMACDGet(const int buffer,const int index) { double MACD[1]; ResetLastError(); if(CopyBuffer(handle_iMACD,buffer,index,1,MACD)<0) { PrintFormat("Failed to copy data from the iMACD indicator, error code %d",GetLastError()); return(0.0); } return(MACD[0]);
原文地址: https://www.cveoy.top/t/topic/ios0 著作权归作者所有。请勿转载和采集!