Problems 2 buffers indicators divide

 
Hi, I'm new to programming, so far I have been able to overcome everything but I have been blocked for a month. the indicator stops working for me and I think this is when I try to split 2 buffers. I would be very grateful if you can help me I put a code that does not work for me

Thanks

#property copyright "Your copyright"
#property link "Link to your website"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color3 Red
#property indicator_width3 2
// exported variables
// local variables
string LF = "\n";  // use this in custom or utility blocks where you need line feeds
int ObjCount = 0;  // count of all objects created on the chart, allows creation of objects with unique names
int current = 0; // variable points to current bar
double Buffer4[];
double Buffer3[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
    if (false) ObjectsDeleteAll();      // clear the chart
    IndicatorShortName("Indicator name");
    IndicatorDigits(Digits+1);
    IndicatorBuffers(3);
    SetIndexBuffer(0, Buffer4);
    SetIndexBuffer(1, Buffer3);
    SetIndexBuffer(2, Buffer2);
    SetIndexStyle(2, DRAW_LINE, STYLE_SOLID);
     return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
    if (false) ObjectsDeleteAll();     
    return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator start function                                  |
//+------------------------------------------------------------------+
int start()
{
    OnEveryTick1();    
    return(0);
}
//+------------------------------------------------------------------+
void OnEveryTick1()
{    
    int i;
    int counted_bars = IndicatorCounted();
    if(counted_bars < 0) return(-1);
    if(counted_bars > 0) counted_bars--;
    i = Bars - counted_bars;
    // main calculation loop
    while (i >= 0)
    {
        current = i;
        Calculation4();
        Calculation3();
        ChartLine2();       
        i--;
    }
}
void Calculation4()
{
    Buffer4[current]= iATR(NULL, PERIOD_CURRENT,10,current);    
}
void Calculation3()
{
    Buffer3[current]= iATR(NULL, PERIOD_CURRENT,30,current);    
}
void ChartLine2()
{
    Buffer2[current]=  Buffer3[current]/ Buffer4[current];    
}


 
Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Also please remove all the unnecessary empty lines, it will be easier for others to read.


 
Keith Watford:
Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Also please remove all the unnecessary empty lines, it will be easier for others to read.


Yes, you are absolutely right
now it's easier to read

Thank you so much
 
void OnEveryTick1()
{    
    int i;
    int counted_bars = IndicatorCounted();
    if(counted_bars < 0) return(-1);
I tried debug your code, the issue lies here 
if(counted_bars < 0) return(-1);

A void function should not return any value except void.



I think it would help with the issue if the -1 is removed

if(counted_bars < 0) return;


2nd issue:

i = Bars - counted_bars;

Fix:

i = Bars - counted_bars -1;


3rd issue:

Zero division error, I will leave it to you.

void ChartLine2()
{
    Buffer2[current]=  Buffer3[current]/ Buffer4[current];    
}


You can always see the error code from the Terminal > Expert and learn to fix them one by one.

Files:
Capture.PNG  30 kb
 

Thank you so much, now no warnings in the compilation

Searching in the forum i find this and works ok


from this


void ChartLine2()
{
    Buffer2[current]=  Buffer3[current]/ Buffer4[current];    
}


To this


void ChartLine2()
{

if(Buffer3[current]>0)
if(Buffer4[current]>0)

    Buffer2[current]=  Buffer3[current]/ Buffer4[current];    
}
 
martivielha:
Hi, I'm new to programming, so far I have been able to overcome everything but I have been blocked for a month. the indicator stops working for me and I think this is when I try to split 2 buffers. I would be very grateful if you can help me I put a code that does not work for me

Thanks



int init()
{
    if (false) ObjectsDeleteAll();      // clear the chart
    IndicatorShortName("Indicator name");
    IndicatorDigits(Digits+1);
    IndicatorBuffers(3);
    SetIndexBuffer(0, Buffer4);
    SetIndexBuffer(1, Buffer3);
    SetIndexBuffer(2, Buffer2);
    SetIndexStyle(2, DRAW_LINE, STYLE_SOLID);
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
    SetIndexEmptyValue(2,0.0);
    
     return(0);
}
   void ChartLine2()
     {
      if(Buffer3[current]!=EMPTY_VALUE && Buffer4[current]!=EMPTY_VALUE &&  Buffer4[current]!=0)
         Buffer2[current]=  Buffer3[current]/ Buffer4[current];
     }

  } 
 

many Thanks

now work perfect