MACD in Debugging Mode and not plotting the oscillator

MACD in Debugging Mode and not plotting the oscillator

Manage alerts

Loading saved threads...

Heli · External communityPost link
External question — Stack Overflow Stack Exchange Author: Heli Original post: https://stackoverflow.com/questions/79582459 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I’m developing an MQL5 Expert Advisor based on MACD crossovers //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ input double lotSize = 0.1; input int macdFastEMA = 12; input int macdSlowEMA = 26; input int macdSignalSMA = 9; int macdHandle; double macdMain[], macdSignal[]; bool positionOpened = false; //+------------------------------------------------------------------+ int OnInit() { macdHandle = iMACD(_Symbol, _Period, macdFastEMA, macdSlowEMA, macdSignalSMA, PRICE_CLOSE); if(macdHandle == INVALID_HANDLE) { Print("خطا در گرفتن هندل MACD"); return(INIT_FAILED); } ArraySetAsSeries(macdMain, true); ArraySetAsSeries(macdSignal, true); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnTick() { if(!CopyBuffer(macdHandle, 0, 0, 3, macdMain) || !CopyBuffer(macdHandle, 1, 0, 3, macdSignal)) { Print("خطا در کپی کردن دیتا از MACD"); return; } double prevMacd = macdMain[1]; double prevSignal = macdSignal[1]; double currMacd = macdMain[0]; double currSignal = macdSignal[0]; // بررسی تقاطع صعودی if(prevMacd < prevSignal && currMacd > currSignal && !PositionSelect(_Symbol)) { OpenTrade(ORDER_TYPE_BUY); } // بررسی تقاطع نزولی if(prevMacd > prevSignal && currMacd < currSignal && !PositionSelect(_Symbol)) { OpenTrade(ORDER_TYPE_SELL); } } //+------------------------------------------------------------------+ void OpenTrade(ENUM_ORDER_TYPE type) { double price = (type == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID); double sl = 0, tp = 0; trade.Buy(lotSize, _Symbol, price, sl, tp, NULL); if(type == ORDER_TYPE_SELL) trade.Sell(lotSize, _Symbol, price, sl, tp, NULL); } //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> CTrade trade; In the corner of the chart, next to the oscillator name, it says Debugging as you can see in the following image What am I missing to display the MACD oscillator on the chart?
Quote
Report
Forex Coder · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Forex Coder Original post: https://stackoverflow.com/a/79645965 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You need to call the chart indicator add with the # of the window to add the indicator as its the macd and its in a new window. The total number of indicator windows will suffice for that. Then on deInit you must release and remove the indicator as well. Here is a reference code : int myMacdWindow=0; //+------------------------------------------------------------------+ int OnInit() { macdHandle = iMACD(_Symbol, _Period, macdFastEMA, macdSlowEMA, macdSignalSMA, PRICE_CLOSE); if(macdHandle == INVALID_HANDLE) { Print("خطا در گرفتن هندل MACD"); return(INIT_FAILED); }else{ ResetLastError(); if(!ChartIndicatorAdd(0,(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL),macdHandle)){ Print("Error #"+IntegerToString(GetLastError())); }else{ myMacdWindow=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL)-1; ChartRedraw(0); } } ArraySetAsSeries(macdMain, true); ArraySetAsSeries(macdSignal, true); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ if(macdHandle!=INVALID_HANDLE){ IndicatorRelease(macdHandle); ChartIndicatorDelete(0,myMacdWindow,"MACD("+IntegerToString(macdFastEMA)+","+IntegerToString(macdSlowEMA)+","+IntegerToString(macdSignalSMA)+")"); } } As for the debugging , when you click the blue or the green play buttons on the IDE it goes into debugging mode . Click compile and just drag the ea file from the navigator on a chart.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Forex Coder Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/a/79645965 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You need to call the chart indicator add with the # of the window to add the indicator as its the macd and its in a new window. The total number of indicator windows will suffice for that. Then on deInit you must release and remove the indicator as well. Here is a reference code : int myMacdWindow=0; //+------------------------------------------------------------------+ int OnInit() { macdHandle = iMACD(_Symbol, _Period, macdFastEMA, macdSlowEMA, macdSignalSMA, PRICE_CLOSE); if(macdHandle == INVALID_HANDLE) { Print("خطا در گرفتن هندل MACD"); return(INIT_FAILED); }else{ ResetLastError(); if(!ChartIndicatorAdd(0,(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL),macdHandle)){ Print("Error #"+IntegerToString(GetLastError())); }else{ myMacdWindow=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL)-1; ChartRedraw(0); } } ArraySetAsSeries(macdMain, true); ArraySetAsSeries(macdSignal, true); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ if(macdHandle!=INVALID_HANDLE){ IndicatorRelease(macdHandle); ChartIndicatorDelete(0,myMacdWindow,"MACD("+IntegerToString(macdFastEMA)+","+IntegerToString(macdSlowEMA)+","+IntegerToString(macdSignalSMA)+")"); } } As for the debugging , when you click the blue or the green play buttons on the IDE it goes into debugging mode . Click compile and just drag the ea file from the navigator on a chart.

Cancel quote

Checking account access…