void OnTick() { double currentFastMA = iMA(_Symbol, 0, FastMA, 0, MODE_SMA, PRICE_CLOSE); double currentSlowMA = iMA(_Symbol, 0, SlowMA, 0, MODE_SMA, PRICE_CLOSE);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
// Define input parameters from the original code input double LotSize = 0.1; input int FastMA = 10; input int SlowMA = 20; // Define the CTrade class with strategic trading moves class CTrade { public: void Buy(double lotSize, string symbol, double price, double stopLoss, double takeProfit, string comment) { double profit = lotSize * (takeProfit - price); // Calculate profit Print("Buy trade opened at price: ", price, " Profit: ", profit); } void Sell(double lotSize, string symbol, double price, double stopLoss, double takeProfit, string comment) { double profit = lotSize * (price - takeProfit); // Calculate profit Print("Sell trade opened at price: ", price, " Profit: ", profit); } }; // Define the Expert base class and derived class with Moving Average strategy class CExpertImplementation { public: CTrade trade; double fastMA, slowMA; double ask, askStopLevel, bid, bidStopLevel; CExpertImplementation() { fastMA = iMA(_Symbol, 0, FastMA, 0, MODE_SMA, PRICE_CLOSE); slowMA = iMA(_Symbol, 0, SlowMA, 0, MODE_SMA, PRICE_CLOSE); } void OnTick() { double currentFastMA = iMA(_Symbol, 0, FastMA, 0, MODE_SMA, PRICE_CLOSE); double currentSlowMA = iMA(_Symbol, 0, SlowMA, 0, MODE_SMA, PRICE_CLOSE); double stopLevel = 0.0; double currentStopLevel = 0.0; if (SymbolInfoDouble(_Symbol, SYMBOL_TRADE_STOPS_LEVEL, currentStopLevel)) { stopLevel = currentStopLevel; if (stopLevel != 0) { double currentBid, currentAsk; if (SymbolInfoDouble(_Symbol, SYMBOL_BID, currentBid) && SymbolInfoDouble(_Symbol, SYMBOL_ASK, currentAsk)) { if (currentFastMA < currentSlowMA && fastMA >= slowMA) { bid = currentBid; trade.Sell(LotSize, _Symbol, bid, stopLevel, bid - 100 * _Point, "Sell Signal"); } else if (currentFastMA > currentSlowMA && fastMA <= slowMA) { ask = currentAsk; trade.Buy(LotSize, _Symbol, ask, stopLevel, ask + 100 * _Point, "Buy Signal"); } } } } fastMA = currentFastMA; slowMA = currentSlowMA; } void Deinit() { // Deinit logic here } }; CExpertImplementation ExtExpert; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ void OnTick() { ExtExpert.OnTick(); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ExtExpert.Deinit(); }