Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
ginevra2016: " CExpert :: Processing - cannot access protected member fuction "
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor -
CExpert ExtExpert; class CSampleExpert { bool Processing(void); ⋮ if(ExtExpert.Processing())
You created a CSampleExpert:Processing() but are calling CExpert:Processing(). The two classes have nothing to do with each other.
-
void OnStart () ⋮ void OnTick(void)
OnStart is for scripts only.
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor -
You created a CSampleExpert:Processing() but are calling CExpert:Processing(). The two classes have nothing to do with each other.
-
OnStart is for scripts only.
thank you very much , but I have corrected these errors and 28 more have been reported to me ;
this is the code correct , could you tell me what I did wrong ?
class CSampleExpert { bool Processing (void); { if (ExtExpert.Processing()) //--- refresh rates if(!m_symbol.RefreshRates()) return(false); //--- refresh indicatori if ( CopyBuffer (m_handle_ema,0,0,2,m_buff_EMA) !=2) return(false); // m_indicators.Refresh(); //--- to simplify the coding and speed up access //--- data are put into internal variables m_ema_current = m_buff_EMA {0]; m_ema_previous = m_buff_EMA [1]; //--- it is important to enter the market correctly, //--- but it is more important to exit it correctly... //--- first check if position exists - try to select it if(m_position.Select(Symbol())) { if(m_position.PositionType()==POSITION_TYPE_BUY) { //--- try to close or modify long position if(LongModified()) return(true) ; } } //--- no opened position identified else { //--- check for long position (BUY) possibility if(LongOpened()) return(true); //--- check for short position (SELL) possibility if(ShortOpened()) return(true); } //--- exit without position processing return(false); } } }
Hi, recently i am approaching the mql5 language and this is first code I produce m, but the error " CExpert :: Processing - cannot access protected member fuction " is reported to me , I cannot understand how to solve it as the code module it is pactically the same as that of a system already installed in the program ;
Could you tell me how to solve it, thank you in advance ;
this is the code :
***
I have attached your code as a file. Also a tip: do not try to create your first Expert Advisor based on CExpert. Start with the minimum. Create an Expert Advisor template using the MQL5 Wizard and start filling this template.
Ho allegato il tuo codice come file. Anche un consiglio: non provare a creare il tuo primo Expert Advisor basato su CExpert. Inizia con il minimo. Crea un modello Expert Advisor utilizzando la procedura guidata MQL5 e inizia a compilare questo modello.
h, I opened the file and compile , but the error is still reported
I just collected your text into an advisor file and threw out all the extra lines. Why don't you read the advice they give you? Do not use CExpert - it is very, very early for you. Start from the very beginning - create a template using the MQL5 Wizard and start gradually filling this template with code.
Forum on trading, automated trading systems and testing trading strategies
"cannot access protected member fuction "
ginevra2016, 2021.08.05 08:23
I have recently approached programming in mql5 and this is my first system , but the error is reported to me :
" CExpert :: Processing - cannot access protected member fuction "
could you tell me things to solve it ?
this is the code:
//+------------------------------------------------------------------+ //| MediaMobile.mq5 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #define MA_MAGIC 123456789; //+------------------------------------------------------------------+ //| Include | //+------------------------------------------------------------------+ #include <Expert\Expert.mqh> //--- available signals #include <Expert\Signal\SignalMA.mqh> //--- available trailing #include <Expert\Trailing\TrailingFixedPips.mqh> //--- available money management #include <Expert\Money\MoneyFixedLot.mqh> #include <Trade\Trade.mqh> //--- global expert CExpert ExtExpert; //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ //--- inputs for expert input string Expert_Title ="MediaMobile"; // Document name ulong Expert_MagicNumber =28888; // bool Expert_EveryTick =false; // //--- inputs for main signal input double InpLots =0.1; // Lotsi input int Signal_ThresholdOpen =10; // Signal threshold value to open [0...100] input int Signal_ThresholdClose =10; // Signal threshold value to close [0...100] input double Signal_PriceLevel =0.0; // Price level to execute a deal input double Signal_StopLevel =50.0; // Stop Loss level (in points) input double Signal_TakeLevel =50.0; // Take Profit level (in points) input int Signal_Expiration =4; // Expiration of pending orders (in bars) input int Signal_MA_PeriodMA =12; // Moving Average(12,0,...) Period of averaging input int Signal_MA_Shift =0; // Moving Average(12,0,...) Time shift input ENUM_MA_METHOD Signal_MA_Method =MODE_SMA; // Moving Average(12,0,...) Method of averaging input ENUM_APPLIED_PRICE Signal_MA_Applied =PRICE_CLOSE; // Moving Average(12,0,...) Prices series input double Signal_MA_Weight =1.0; // Moving Average(12,0,...) Weight [0...1.0] //--- inputs for trailing input int Trailing_FixedPips_StopLevel =30; // Stop Loss trailing level (in points) input int Trailing_FixedPips_ProfitLevel=50; // Take Profit trailing level (in points) //--- inputs for money input double Money_FixLot_Percent =10.0; // Percent input double Money_FixLot_Lots =0.1; // Fixed volume //+------------------------------------------------------------------+ //| Global expert object | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ void OnStart() { int oggi= 0 ; int ieri = 1 ; MqlRates rate [] ; CopyRates(Symbol(), PERIOD_D1, ieri, 1, rate) ; Print("ieri :1 =", rate [1].open, "C=", rate [1].close); CopyRates(Symbol(), PERIOD_D1, oggi, 1, rate); Print("ieri 0= ", rate [0].open, "C=", rate [0].close); } //+------------------------------------------------------------------+ //| Initialization function of the expert | //+------------------------------------------------------------------+ class CSampleExpert { protected: double m_adjusted_point; // point value adjusted for 3 or 5 points CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object CPositionInfo m_position; // trade position object CAccountInfo m_account; // account info wrapper //--- indicators int m_handle_macd; // MACD indicator handle int m_handle_ema; // moving average indicator handle //--- indicator buffers double m_buff_EMA[]; // EMA indicator buffer //--- indicator data for processing double m_signal_current; double m_signal_previous; double m_ema_current; double m_ema_previous; //--- double m_traling_stop; double m_take_profit; public: CSampleExpert(void); ~CSampleExpert(void); bool Init(void); void Deinit(void); bool Processing(void); protected: bool InitCheckParameters(const int digits_adjust); bool InitIndicators(void); bool LongModified(void); bool ShortModified(void); bool LongOpened(void); bool ShortOpened(void); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CSampleExpert::CSampleExpert(void) : m_adjusted_point(0), m_handle_ema(INVALID_HANDLE), m_signal_current(0), m_signal_previous(0), m_ema_current(0), m_ema_previous(0), m_traling_stop(0), m_take_profit(0) { ArraySetAsSeries(m_buff_EMA,true); } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CSampleExpert::~CSampleExpert(void) { } //+------------------------------------------------------------------+ //| Initialization and checking for input parameters | //+------------------------------------------------------------------+ bool CSampleExpert::Init(void) { //--- initialize common information m_symbol.Name(Symbol()); // symbol m_trade.SetMarginMode(); m_trade.SetTypeFillingBySymbol(Symbol()); //--- tuning for 3 or 5 digits int digits_adjust=1; if(m_symbol.Digits()==3 || m_symbol.Digits()==5) digits_adjust=10; m_adjusted_point=m_symbol.Point()*digits_adjust; //--- set default deviation for trading in adjusted points m_traling_stop = Signal_StopLevel*m_adjusted_point; m_take_profit = Signal_TakeLevel *m_adjusted_point; //--- set default deviation for trading in adjusted points m_trade.SetDeviationInPoints(3*digits_adjust); //--- if(!InitCheckParameters(digits_adjust)) return(false); if(!InitIndicators()) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Checking for input parameters | //+------------------------------------------------------------------+ bool CSampleExpert::InitCheckParameters(const int digits_adjust) { //--- initial data checks if(Signal_TakeLevel * digits_adjust < m_symbol.StopsLevel()) { printf("Take Profit must be greater than %d",m_symbol.StopsLevel()); return(false); } if(Signal_TakeLevel *digits_adjust<m_symbol.StopsLevel()) { printf("Trailing Stop must be greater than %d",m_symbol.StopsLevel()); return(false); } //--- check for right lots amount if(InpLots<m_symbol.LotsMin() || InpLots>m_symbol.LotsMax()) { printf("Lots amount must be in the range from %f to %f",m_symbol.LotsMin(),m_symbol.LotsMax()); return(false); } if(MathAbs(InpLots/m_symbol.LotsStep()-MathRound(InpLots/m_symbol.LotsStep()))>1.0E-10) { printf("Lots amount is not corresponding with lot step %f",m_symbol.LotsStep()); return(false); } //--- warning if(Signal_TakeLevel <= Signal_StopLevel) printf("Warning: Trailing Stop must be less than Take Profit"); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Initialization of the indicators | //+------------------------------------------------------------------+ bool CSampleExpert::InitIndicators(void) { //--- create EMA indicator and add it to collection if(m_handle_ema==INVALID_HANDLE) if((m_handle_ema=iMA(NULL,0,Signal_MA_PeriodMA,0,MODE_EMA,PRICE_CLOSE))==INVALID_HANDLE) { printf("Error creating EMA indicator"); return(false); } //--- succeed return(true); } //+------------------------------------------------------------------+ //| Check for long position modifying | //+------------------------------------------------------------------+ bool CSampleExpert::LongModified(void) { bool res=false; //--- check for trailing stop if(Signal_TakeLevel >0) { if(m_symbol.Bid()-m_position.PriceOpen()>m_adjusted_point*Signal_StopLevel) { double sl=NormalizeDouble(m_symbol.Bid()-m_traling_stop,m_symbol.Digits()); double tp=m_position.TakeProfit(); if(m_position.StopLoss()<sl || m_position.StopLoss()==0.0) { //--- modify position if(m_trade.PositionModify(Symbol(),sl,tp)) printf("Long position by %s to be modified",Symbol()); else { printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment()); printf("Modify parameters : SL=%f,TP=%f",sl,tp); } //--- modified and must exit from expert res=true; } } } //--- result return(res); } //+------------------------------------------------------------------+ //| Check for short position modifying | //+------------------------------------------------------------------+ bool CSampleExpert::ShortModified(void) { bool res=false; //--- check for trailing stop if(Signal_StopLevel >0) { if((m_position.PriceOpen()-m_symbol.Ask())>(m_adjusted_point*Signal_StopLevel)) { double sl=NormalizeDouble(m_symbol.Ask()+m_traling_stop,m_symbol.Digits()); double tp=m_position.TakeProfit(); if(m_position.StopLoss()>sl || m_position.StopLoss()==0.0) { //--- modify position if(m_trade.PositionModify(Symbol(),sl,tp)) printf("Short position by %s to be modified",Symbol()); else { printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment()); printf("Modify parameters : SL=%f,TP=%f",sl,tp); } //--- modified and must exit from expert res=true; } } } //--- result return(res); } //+------------------------------------------------------------------+ //| Check for long position opening | //+------------------------------------------------------------------+ bool CSampleExpert::LongOpened(void) { MqlRates rate [] ; bool res=false; //--- check for long position (BUY) possibility if(m_ema_current < rate[0].close) if(rate[0].open < rate[0].close && rate[1].open > rate[1].close) if(m_ema_current > m_ema_previous) if(rate[1].close == rate[0].open) { double price=m_symbol.Ask(); double tp =m_symbol.Bid()+m_take_profit; //--- check for free money if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_BUY,InpLots,PRICE_CLOSE)<0.0) printf("We have no money. Free Margin = %f",m_account.FreeMargin()); else { //--- open position if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,PRICE_CLOSE,0.0,tp)) printf("Position by %s to be opened",Symbol()); else { printf("Error opening BUY position by %s : '%s'",Symbol(),m_trade.ResultComment()); printf("Open parameters : price=%f,TP=%f",PRICE_CLOSE,tp); } } //--- in any case we must exit from expert res=true; } //--- result return(res); } //+------------------------------------------------------------------+ //| Check for short position opening | //+------------------------------------------------------------------+ bool CSampleExpert::ShortOpened(void) { MqlRates rate [] ; bool res=false; //--- check for short position (SELL) possibility if(m_ema_current > rate[0].open) if(rate[0].open > rate[0].close && rate[1].open < rate[1].close) if(m_ema_current<m_ema_previous) if(rate[1].open == rate[0].close) { double price=m_symbol.Bid(); double tp =m_symbol.Ask()-m_take_profit; //--- check for free money if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_SELL,InpLots,PRICE_CLOSE <0.0)) printf("We have no money. Free Margin = %f",m_account.FreeMargin()); else { //--- open position if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,InpLots,PRICE_CLOSE,0.0,tp)) printf("Position by %s to be opened",Symbol()); else { printf("Error opening SELL position by %s : '%s'",Symbol(),m_trade.ResultComment()); printf("Open parameters : price=%f,TP=%f",PRICE_CLOSE,tp); } } //--- in any case we must exit from expert res=true; } //--- result return(res); } //+------------------------------------------------------------------+ //| main function returns true if any position processed | //+------------------------------------------------------------------+ bool CSampleExpert::Processing(void) { //--- refresh rates if(!m_symbol.RefreshRates()) return(false); //--- refresh indicatori if( CopyBuffer(m_handle_ema,0,0,2,m_buff_EMA) !=2) return(false); // m_indicators.Refresh(); //--- to simplify the coding and speed up access //--- data are put into internal variables m_ema_current =m_buff_EMA[0]; m_ema_previous =m_buff_EMA[1]; //--- it is important to enter the market correctly, //--- but it is more important to exit it correctly... //--- first check if position exists - try to select it if(m_position.Select(Symbol())) { if(m_position.PositionType()==POSITION_TYPE_BUY) { //--- try to close or modify long position if(LongModified()) return(true); } } //--- no opened position identified else { //--- check for long position (BUY) possibility if(LongOpened()) return(true); //--- check for short position (SELL) possibility if(ShortOpened()) return(true); } //--- exit without position processing return(false); } //+------------------------------------------------------------------+ //| Expert new tick handling function | //+------------------------------------------------------------------+ void OnTick(void) { static datetime limit_time=0; // last trade processing time + timeout //--- don't process if timeout if(TimeCurrent()>=limit_time) { //--- check for data if(Bars(Symbol(),Period())>2* Signal_MA_PeriodMA) { //--- change limit time by timeout in seconds if processed if(ExtExpert.Processing()) limit_time=TimeCurrent(); } } } //+--------------
Please do not try to use the CExpert class - you have to read and learn a lot. At the very least, you need to know about inheritance and polymorphism.
Recommend: forget (for a while) about the CExpert class. Create a template using the MQL5 Wizard and gradually fill your template with code!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, recently i am approaching the mql5 language and this is first code I produce m, but the error " CExpert :: Processing - cannot access protected member fuction " is reported to me , I cannot understand how to solve it as the code module it is pactically the same as that of a system already installed in the program ;
Could you tell me how to solve it, thank you in advance ;
this is the code :
***