EMPTY_VALUE issue for buffer.

ArAsh Sohi
19
ArAsh Sohi  
Hi, I will be very thankful if someone helps me with this.

I'm not a coder, I use only *** software for creating my EA.

I need MACD divergence and I use the below code with icustom Indicator. When this indicator creates an arrow the divergence happens and the number of each buffer (mode0 and mode2) should be changed. But as you can see it gives me Empty Value (Attach image).

How can I fix this?






//+------------------------------------------------------------------+
//|                                     FX5_MACD_Divergence_V1.1.mq4 |
//|                                                              FX5 |
//|                                                    hazem@uk2.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, FX5"
#property link      "hazem@uk2.net"
//----
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_color3 clrMagenta
#property indicator_color4 clrBlue
//----
#define arrowsDisplacement 0.0001
//---- input parameters
extern string separator1="*** MACD Settings ***";
extern int    fastEMA = 12;
extern int    slowEMA = 26;
extern int    signalSMA=9;
extern string separator2="*** Indicator Settings ***";
extern bool   drawIndicatorTrendLines=true;
extern bool   drawPriceTrendLines=true;
extern bool   displayAlert=true;
//---- buffers
double bullishDivergence[];
double bearishDivergence[];
double macd[];
double signal[];
//----
static datetime lastAlertTime;
static string   indicatorName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
//----   
   SetIndexBuffer(0,bullishDivergence);
   SetIndexBuffer(1,bearishDivergence);
   SetIndexBuffer(2,macd);
   SetIndexBuffer(3,signal);
//----   
   SetIndexArrow(0,233);
   SetIndexArrow(1,234);
//----
   indicatorName="FX5_MACD_Divergence_v1.1("+fastEMA+", "+
                 slowEMA+", "+signalSMA+")";
   SetIndexDrawBegin(3,signalSMA);
   IndicatorDigits(Digits+2);
   IndicatorShortName(indicatorName);

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   for(int i=ObjectsTotal()-1; i>=0; i--)
     {
      string label=ObjectName(i);
      if(StringSubstr(label,0,19)!="MACD_DivergenceLine")
         continue;
      ObjectDelete(label);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int countedBars=IndicatorCounted();
   if(countedBars<0)
      countedBars=0;
   CalculateIndicator(countedBars);
//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateIndicator(int countedBars)
  {
   int limit=Bars-countedBars;
   if(countedBars==0) limit-=slowEMA;
   for(int i=limit; i>=0; i--)
     {
      CalculateMACD(i);
      CatchBullishDivergence(i+2);
      CatchBearishDivergence(i+2);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateMACD(int i)
  {
   macd[i]=iMACD(NULL,0,fastEMA,slowEMA,signalSMA,
                 PRICE_CLOSE,MODE_MAIN,i);

   signal[i]=iMACD(NULL,0,fastEMA,slowEMA,signalSMA,
                   PRICE_CLOSE,MODE_SIGNAL,i);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CatchBullishDivergence(int shift)
  {
   if(IsIndicatorTrough(shift)==false)
      return;
   int currentTrough=shift;
   int lastTrough=GetIndicatorLastTrough(shift);
//----   
   if((lastTrough>=0 && lastTrough<Bars) && macd[currentTrough]>macd[lastTrough] && Low[currentTrough]<Low[lastTrough])
     {
      bullishDivergence[currentTrough]=macd[currentTrough]-
                                       arrowsDisplacement;
      //----
      if(drawPriceTrendLines==true)
         DrawPriceTrendLine(Time[currentTrough],Time[lastTrough],
                            Low[currentTrough],
                            Low[lastTrough],Green,STYLE_SOLID);
      //----
      if(drawIndicatorTrendLines==true)
         DrawIndicatorTrendLine(Time[currentTrough],
                                Time[lastTrough],
                                macd[currentTrough],
                                macd[lastTrough],
                                Green,STYLE_SOLID);
      //----
      if(displayAlert==true)
         DisplayAlert("Classical bullish divergence on: ",
                      currentTrough);
     }
//----   
   if((lastTrough>=0 && lastTrough<Bars) && macd[currentTrough]<macd[lastTrough] && Low[currentTrough]>Low[lastTrough])
     {
      bullishDivergence[currentTrough]=macd[currentTrough]-
                                       arrowsDisplacement;
      //----
      if(drawPriceTrendLines==true)
         DrawPriceTrendLine(Time[currentTrough],Time[lastTrough],
                            Low[currentTrough],
                            Low[lastTrough],Green,STYLE_DOT);
      //----
      if(drawIndicatorTrendLines==true)
         DrawIndicatorTrendLine(Time[currentTrough],
                                Time[lastTrough],
                                macd[currentTrough],
                                macd[lastTrough],
                                Green,STYLE_DOT);
      //----
      if(displayAlert==true)
         DisplayAlert("Reverse bullish divergence on: ",
                      currentTrough);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CatchBearishDivergence(int shift)
  {
   if(IsIndicatorPeak(shift)==false)
      return;
   int currentPeak=shift;
   int lastPeak=GetIndicatorLastPeak(shift);
//----   
   if((lastPeak>=0 && lastPeak<Bars) && macd[currentPeak]<macd[lastPeak] && High[currentPeak]>High[lastPeak])
     {
      bearishDivergence[currentPeak]=macd[currentPeak]+
                                     arrowsDisplacement;

      if(drawPriceTrendLines==true)
         DrawPriceTrendLine(Time[currentPeak],Time[lastPeak],
                            High[currentPeak],
                            High[lastPeak],Red,STYLE_SOLID);

      if(drawIndicatorTrendLines==true)
         DrawIndicatorTrendLine(Time[currentPeak],Time[lastPeak],
                                macd[currentPeak],
                                macd[lastPeak],Red,STYLE_SOLID);

      if(displayAlert==true)
         DisplayAlert("Classical bearish divergence on: ",
                      currentPeak);
     }
   if((lastPeak>=0 && lastPeak<Bars) && macd[currentPeak]>macd[lastPeak] && High[currentPeak]<High[lastPeak])
     {
      bearishDivergence[currentPeak]=macd[currentPeak]+
                                     arrowsDisplacement;
      //----
      if(drawPriceTrendLines==true)
         DrawPriceTrendLine(Time[currentPeak],Time[lastPeak],
                            High[currentPeak],
                            High[lastPeak],Red,STYLE_DOT);
      //----
      if(drawIndicatorTrendLines==true)
         DrawIndicatorTrendLine(Time[currentPeak],Time[lastPeak],
                                macd[currentPeak],
                                macd[lastPeak],Red,STYLE_DOT);
      //----
      if(displayAlert==true)
         DisplayAlert("Reverse bearish divergence on: ",
                      currentPeak);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsIndicatorPeak(int shift)
  {
   if(macd[shift]>=macd[shift+1] && macd[shift]>macd[shift+2] && 
      macd[shift]>macd[shift-1])
      return(true);
   else
      return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsIndicatorTrough(int shift)
  {
   if(macd[shift]<=macd[shift+1] && macd[shift]<macd[shift+2] && 
      macd[shift]<macd[shift-1])
      return(true);
   else
      return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetIndicatorLastPeak(int shift)
  {
   for(int i=shift+5;(i<Bars-3) && (i>1); i++)
     {
      if(signal[i] >= signal[i+1] && signal[i] >= signal[i+2] &&
         signal[i] >= signal[i-1] && signal[i] >= signal[i-2])
        {
         for(int j=i;(j<Bars-3) && (j>1); j++)
           {
            if(macd[j] >= macd[j+1] && macd[j] > macd[j+2] &&
               macd[j] >= macd[j-1] && macd[j] > macd[j-2])
               return(j);
           }
        }
     }
   return(-1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int shift)
  {
   for(int i=shift+5;(i<Bars-3) && (i>1); i++)
     {
      if(signal[i] <= signal[i+1] && signal[i] <= signal[i+2] &&
         signal[i] <= signal[i-1] && signal[i] <= signal[i-2])
        {
         for(int j=i;(j<Bars-3) && (j>1); j++)
           {
            if(macd[j] <= macd[j+1] && macd[j] < macd[j+2] &&
               macd[j] <= macd[j-1] && macd[j] < macd[j-2])
               return(j);
           }
        }
     }
   return(-1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DisplayAlert(string message,int shift)
  {
   if(shift<=2 && Time[shift]!=lastAlertTime)
     {
      lastAlertTime=Time[shift];
      Alert(message,Symbol()," , ",Period()," minutes chart");
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawPriceTrendLine(datetime x1,datetime x2,double y1,
                        double y2,color lineColor,double style)
  {
   string label="MACD_DivergenceLine_v1.0# "+DoubleToStr(x1,0);
   ObjectDelete(label);
   ObjectCreate(label,OBJ_TREND,0,x1,y1,x2,y2,0,0);
   ObjectSet(label,OBJPROP_RAY,0);
   ObjectSet(label,OBJPROP_COLOR,lineColor);
   ObjectSet(label,OBJPROP_STYLE,style);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawIndicatorTrendLine(datetime x1,datetime x2,double y1,
                            double y2,color lineColor,double style)
  {
   int indicatorWindow=WindowFind(indicatorName);
   if(indicatorWindow<0)
      return;
   string label="MACD_DivergenceLine_v1.0$# "+DoubleToStr(x1,0);
   ObjectDelete(label);
   ObjectCreate(label,OBJ_TREND,indicatorWindow,x1,y1,x2,y2,
                0,0);
   ObjectSet(label,OBJPROP_RAY,0);
   ObjectSet(label,OBJPROP_COLOR,lineColor);
   ObjectSet(label,OBJPROP_STYLE,style);
  }
//+------------------------------------------------------------------+

Nagisa Unada
715
Nagisa Unada  

There is nothing to fix.

Maybe it's a problem with the iCustom program.
ArAsh Sohi
19
ArAsh Sohi  
Nagisa Unada:

There is nothing to fix.

Maybe it's a problem with the iCustom program.
Thanks for respond.
I need to close my position whenever divergence happens in that indicator. Any suggestion for this?
William Roeder
23772
William Roeder  
ArAsh Sohi: I'm not a coder, I use only *** software for creating my EA.
EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, FOREXEADVISOR STRATEGY BUILDER, FX EA Builder, fxDreema, FxPro, Molanis, Octa-FX Meta Editor, Online Forex Expert Advisor Generator, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.
  1. Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.
    We are willing to HELP you when you post your attempt (using SRC) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  2. EA builder makes bad code counting up while closing multiple orders.
    EA builder makes bad code Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
    EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
    EA builder makes bad code, not adjusting for ECN brokers. pre-Build 500)
    EA builder makes bad code, not checking return codes.

  3. EATree uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

  4. FX EA Builder makes bad code, not checking return codes.
    FX EA Builder makes bad code, loosing open tickets on terminal restart. No recovery (crash/power failure.)
    FX EA Builder makes bad code, not adjusting stops for the spread.
    FX EA Builder makes bad code, using OrdersTotal directly.

  5. FOREXEADVISOR STRATEGY BUILDER makes bad code, non-updateing global variables.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, compilation errors.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, not checking return codes.

Learn to code it, or pay someone (Freelance) someone to code it.
          Hiring to write script - General - MQL5 programming forum #1 2019.08.21

Mehmet Bastem
2214
Mehmet Bastem  
ArAsh Sohi:
Hi, I will be very thankful if someone helps me with this.

I'm not a coder, I use only *** software for creating my EA.

I need MACD divergence and I use the below code with icustom Indicator. When this indicator creates an arrow the divergence happens and the number of each buffer (mode0 and mode2) should be changed. But as you can see it gives me Empty Value (Attach image).

How can I fix this?







  


void CalculateIndicator(int countedBars)
  {
   int limit=Bars-countedBars;
   if(countedBars==0) limit-=slowEMA;
   for(int i=limit; i>=0; i--)
     {
      CalculateMACD(i);
      CatchBullishDivergence(i+2);
      CatchBearishDivergence(i+2);
     }
  }

// Change this code as follows.
void CalculateIndicator(int countedBars)
  {
   int limit=Bars-countedBars;
   if(countedBars==0) limit-=slowEMA;
   for(int i=limit; i>=0; i--)
     {
      CalculateMACD(i);
      CatchBullishDivergence(i); // i+2
      CatchBearishDivergence(i); // i+2
     }
  }

First, change the code in the indicator as above.

If to call in the expert

void OnTick()
  {
//---
// BUY  -0.0003175743130248264     2147483647.0
// SELL  2147483647.0     0.0001000130913693219


    double Buy =iCustom(Symbol(),0,"FX5_MACD_Divergence_V1.1",0,0);
    double Sell=iCustom(Symbol(),0,"FX5_MACD_Divergence_V1.1",1,0);
     if(Buy!=2147483647.0 ) Alert("BUY");
     if(Sell!=2147483647.0)  Alert("SELL");
     
  }
ArAsh Sohi
19
ArAsh Sohi  
Mehmet Bastem:

  


First, change the code in the indicator as above.

If to call in the expert


Thank you Mehmet!!!! Now it fixed !!!!

ArAsh Sohi
19
ArAsh Sohi  
William Roeder:
EA builder, EA Builder Pro, EATree, Etasoft forex generator, Forex Strategy Builder, FOREXEADVISOR STRATEGY BUILDER, FX EA Builder, fxDreema, FxPro, Molanis, Octa-FX Meta Editor, Online Forex Expert Advisor Generator, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.
  1. Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
    If we tell you what you need, you can't code it.
    If we give you the code, you don't know how to integrate it into yours.
    We are willing to HELP you when you post your attempt (using SRC) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

  2. EA builder makes bad code counting up while closing multiple orders.
    EA builder makes bad code Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
    EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
    EA builder makes bad code, not adjusting for ECN brokers. pre-Build 500)
    EA builder makes bad code, not checking return codes.

  3. EATree uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

  4. FX EA Builder makes bad code, not checking return codes.
    FX EA Builder makes bad code, loosing open tickets on terminal restart. No recovery (crash/power failure.)
    FX EA Builder makes bad code, not adjusting stops for the spread.
    FX EA Builder makes bad code, using OrdersTotal directly.

  5. FOREXEADVISOR STRATEGY BUILDER makes bad code, non-updateing global variables.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, compilation errors.
    FOREXEADVISOR STRATEGY BUILDER makes bad code, not checking return codes.

Learn to code it, or pay someone (Freelance) someone to code it.
          Hiring to write script - General - MQL5 programming forum #1 2019.08.21

Thank you William for your explanation. Sure you're right.