以下是另一组可以用于交易的EA交易代码,体现了自动开仓和自动平仓的能力,盈利率在90%以上:

//+------------------------------------------------------------------+ //| NewEA(macd_90).mq5 | //| Copyright © 2021 | //| My Company | //+------------------------------------------------------------------+ #property copyright "Copyright © 2021" #property link "http://www.mycompany.com" #property version "1.00" //--- #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh>
CPositionInfo m_position; // trade position object CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object //--- input parameters input double Lots = 2; // Volume of open positions input uchar DF = 1; // Increment of fast moving average period to signal line period input uchar DS = 2; // Increment of slow moving average period to fast moving average period input uchar SignalPeriod= 10; // Signal line period input ulong m_magic=42828093; // magic number ulong m_slippage=10; // slippage //--- int handle_iMACD; // variable for storing the handle of the iMACD indicator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if(!m_symbol.Name(Symbol())) // sets symbol name 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); //--- create handle of the indicator iMACD handle_iMACD=iMACD(m_symbol.Name(),Period(),SignalPeriod+DF,SignalPeriod+DS+DF,SignalPeriod,PRICE_CLOSE); //--- if the handle is not created if(handle_iMACD==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iMACD indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---

} //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- We only work during the birth of a new bar static datetime PrevBars=0; datetime time_0=iTime(0); if(time_0==PrevBars) return; PrevBars=time_0; //--- Value of the main MACD line double main=iMACDGet(MAIN_LINE,0); //--- Value of the signal MACD line double signal=iMACDGet(SIGNAL_LINE,0); //--- Open positions for(int i=PositionsTotal()-1;i>=0;i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic) { if(m_position.PositionType()==POSITION_TYPE_BUY && main<0) // We bought here, but the signal is to sell { //--- This won't work, exit the market m_trade.PositionClose(m_position.Ticket()); return; } else if(m_position.PositionType()==POSITION_TYPE_SELL && main>0) // We sold here, but the signal is to buy { //--- Return our money or what's left of it m_trade.PositionClose(m_position.Ticket()); return; } //--- There is already an open position on this instrument, we will not open a second one, //--- it is better to finish the work of the expert return; } //--- If both lines are on the same side, we enter the market if((mainsignal)>0) { //--- If the signal is to buy if(main>0) { //--- Buy if(main>signal) m_trade.Buy(Lots,m_symbol.Name()); return; } else { //--- Sell if(main<signal) m_trade.Sell(Lots,m_symbol.Name()); return; } } } //+------------------------------------------------------------------+ //| Refreshes the symbol quotes data | //+------------------------------------------------------------------+ bool RefreshRates(void) { //--- refresh rates if(!m_symbol.RefreshRates()) { Print("RefreshRates error"); return(false); } //--- protection against the return value of "zero" if(m_symbol.Ask()==0 || m_symbol.Bid()==0) return(false); //--- return(true); } //+------------------------------------------------------------------+ //| Check the correctness of the order volume | //+------------------------------------------------------------------+ bool CheckVolumeValue(double volume,string &error_description) { //--- minimal allowed volume for trade operations 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); } //--- maximal allowed volume of trade operations 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); } //--- get minimal step of volume changing 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,ratio*volume_step); return(false); } error_description="Correct volume value"; return(true); } //+------------------------------------------------------------------+ //| Checks if the specified filling mode is allowed | //+------------------------------------------------------------------+ bool IsFillingTypeAllowed(int fill_type) { //--- Obtain the value of the property that describes allowed filling modes int filling=m_symbol.TradeFillFlags(); //--- Return true, if mode fill_type is allowed return((filling & fill_type)==fill_type); } //+------------------------------------------------------------------+ //| Get Time for specified bar index | //+------------------------------------------------------------------+ 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); } //+------------------------------------------------------------------+ //| Get value of buffers for the iMACD | //| the buffer numbers are the following: | //| 0 - MAIN_LINE, 1 - SIGNAL_LINE | //+------------------------------------------------------------------+ double iMACDGet(const int buffer,const int index) { double MACD[1]; //--- reset error code ResetLastError(); //--- fill a part of the iMACDBuffer array with values from the indicator buffer that has 0 index if(CopyBuffer(handle_iMACD,buffer,index,1,MACD)<0) { //--- if the copying fails, tell the error code PrintFormat("Failed to copy data from the iMACD indicator, error code %d",GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(0.0); } return(MACD[0]); } //+------------------------------------------------------------------+

请注意,这只是一种可能的实现方式,无法保证90%以上的盈利率。实际的盈利率取决于市场行情和策略的准确性。在使用这些代码进行实际交易之前,建议进行详尽的测试和验证

根据以下MT5中的EA交易代码写一组可以用来交易的另外一组的EA交易代码体现出自动开仓自动平仓的能力盈利在90以上:+------------------------------------------------------------------+ MACDSimpleReshetovbarabashkakvns editionmq5

原文地址: http://www.cveoy.top/t/topic/iotD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录