How to solve it?

 
//+------------------------------------------------------------------+
//|                                               for lim indi 2.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
                
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 White

input int Length = 50;
input bool ShowReg = true;
input color RegPhColor = Red;
input color RegPlColor = Green;
input bool ShowMiss = true;
input color MissPhColor = Red;
input color MissPlColor = Green;

int LabelCounter;
double PivotHigh[];
double PivotLow[];
double FollowMax[];
double FollowMin[];
double GhostLevel[];
int FollowMaxX[];
int FollowMinX[];
int MaxX[];
int MinX[];
int Zigzag[];
double Px1[];
double Py1[];

int OnCalculate(int index)

{
int n = index;
PivotHigh[index] = iHigh(NULL,0,Length,Length);
PivotLow[index] = iLow(NULL,0,Length,Length);

FollowMax[index] = MathMax(iHigh(NULL,0,Length,0),FollowMax[index-1]);
FollowMin[index] = MathMin(iLow(NULL,0,Length,0),FollowMin[index-1]);

if (FollowMax[index] > FollowMax[index-1])
{
FollowMaxX[index] = n-Length;
FollowMin[index] = iLow(NULL,0,Length,0);
}
if (FollowMin[index] < FollowMin[index-1])
{
FollowMinX[index] = n-Length;
FollowMax[index] = iHigh(NULL,0,Length,0);
}

if (FollowMin[index] < FollowMin[index-1])
FollowMinX[index] = n-Length;
if (FollowMax[index] > FollowMax[index-1])
FollowMaxX[index] = n-Length;

if (PivotHigh[index] == 0)
return 0;

if (ShowMiss)
{
if (PivotHigh[index-1] == 0)
{
LabelCounter++;
LabelCounter = min(LabelCounter,499);
ObjectCreate("MissedLow"+LabelCounter,OBJ_LABEL,0,MinX[index-1],PivotLow[index-1]-0.5Point,MinX[index-1]+100,PivotLow[index-1]+0.5Point);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_COLOR,MissPlColor);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_BACK,false);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_LEVELCOLOR,RGBA(0,0,0,0));
ObjectSet("MissedLow"+LabelCounter,OBJPROP_LEVELSTYLE,STYLE_DASHDOT);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_TEXT, DoubleToStr(Low[i],Digits));

double pivothigh=0.0;
double pivotlow=0.0;
double max=0.0,min=0.0;
double follow_max=0.0,follow_min=0.0;
int max_x1=0,min_x1=0,follow_max_x1=0,follow_min_x1=0;
int length=50;
bool show_reg=true;
color reg_ph_css=clrRed;
color reg_pl_css=clrGreen;
bool show_miss=true;
color miss_ph_css=clrRed;
color miss_pl_css=clrGreen;
color label_css=clrWhite;
int n=0;
double os=0.0,py1=0.0,px1=0.0;

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    for(n=0; n<rates_total; n++)
    {
        pivothigh=iPivot(high, n, length, length, PRICE_HIGH);
        pivotlow=iPivot(low, n, length, length, PRICE_LOW);

        max=MathMax(high[n],max);
        min=MathMin(low[n],min);
        follow_max=MathMax(high[n],follow_max);
        follow_min=MathMin(low[n],follow_min);

        if(max>max[1])
        {
            max_x1=n-length;
            follow_min=low[n];
        }
        if(min<min[1])
        {
            min_x1=n-length;
            follow_max=high[n];
        }

        if(follow_min<follow_min[1])
            follow_min_x1=n-length;
        if(follow_max>follow_max[1])
            follow_max_x1=n-length;

        if(pivothigh!=0)
        {
            if(show_miss)
            {
                if(os[1]==1)
                {
                    ObjectCreate("missed_low_"+n, OBJ_LABEL,0, min_x1, min, Label("👻", min_x1, min, label_css));
                    ObjectSet("missed_low_"+n, OBJPROP_STYLE, STYLE_LABEL_UP);
                    ObjectSet("missed_low_"+n, OBJPROP_TOOLTIP, DoubleToStr(min,5));
                    ObjectSet("missed_low_"+n, OBJPROP_SIZE, SIZE_SMALL);

                    ObjectCreate("zigzag_"+n, OBJ_TREND,0, px1, py1, min_x1, min);
                    double ObjectSet("MissedLow"+LabelCounter, OBJPROP_STYLE, STYLE_DOT);
double AverageTrueRange(int symbol, int timeframe, int period) {
// function code here
}
{
double sum = 0.0;
int i;
for (i = 0; i < period; i++)
{
sum += TrueRange(symbol, timeframe, i);
}
return (sum / period);
} 


have three problem which is,

#property' - semicolon expected line 35

'}' - unexpected end of program line 182

'{' - unbalanced parentheses line 65



 
mt4 money:
Property should at first of program
 
#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 Red

#property indicator_color2 Green

int OnCalculate(const int rates_total,



                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])
like this??
 
mt4 money #:
You should read this link first https://www.mql5.com/en/articles/37
 
//+------------------------------------------------------------------+
//|                                               for lim indi 2.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
                
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 White

input int Length = 50;
input bool ShowReg = true;
input color RegPhColor = Red;
input color RegPlColor = Green;
input bool ShowMiss = true;
input color MissPhColor = Red;
input color MissPlColor = Green;

int LabelCounter;
double PivotHigh[];
double PivotLow[];
double FollowMax[];
double FollowMin[];
double GhostLevel[];
int FollowMaxX[];
int FollowMinX[];
int MaxX[];
int MinX[];
int Zigzag[];
double Px1[];
double Py1[];

int OnCalculate(int index)

{
int n = index;
PivotHigh[index] = iHigh(NULL,0,Length,Length);
PivotLow[index] = iLow(NULL,0,Length,Length);

FollowMax[index] = MathMax(iHigh(NULL,0,Length,0),FollowMax[index-1]);
FollowMin[index] = MathMin(iLow(NULL,0,Length,0),FollowMin[index-1]);

if (FollowMax[index] > FollowMax[index-1])
{
FollowMaxX[index] = n-Length;
FollowMin[index] = iLow(NULL,0,Length,0);
}
if (FollowMin[index] < FollowMin[index-1])
{
FollowMinX[index] = n-Length;
FollowMax[index] = iHigh(NULL,0,Length,0);
}

if (FollowMin[index] < FollowMin[index-1])
FollowMinX[index] = n-Length;
if (FollowMax[index] > FollowMax[index-1])
FollowMaxX[index] = n-Length;

if (PivotHigh[index] == 0)
return 0;

if (ShowMiss)
{
if (PivotHigh[index-1] == 0)
{
LabelCounter++;
LabelCounter = min(LabelCounter,499);
ObjectCreate("MissedLow"+LabelCounter,OBJ_LABEL,0,MinX[index-1],PivotLow[index-1]-0.5Point,MinX[index-1]+100,PivotLow[index-1]+0.5Point);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_COLOR,MissPlColor);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_BACK,false);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_LEVELCOLOR,RGBA(0,0,0,0));
ObjectSet("MissedLow"+LabelCounter,OBJPROP_LEVELSTYLE,STYLE_DASHDOT);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_TEXT, DoubleToStr(Low[i],Digits));

double pivothigh=0.0;
double pivotlow=0.0;
double max=0.0,min=0.0;
double follow_max=0.0,follow_min=0.0;
int max_x1=0,min_x1=0,follow_max_x1=0,follow_min_x1=0;
int length=50;
bool show_reg=true;
color reg_ph_css=clrRed;
color reg_pl_css=clrGreen;
bool show_miss=true;
color miss_ph_css=clrRed;
color miss_pl_css=clrGreen;
color label_css=clrWhite;
int n=0;
double os=0.0,py1=0.0,px1=0.0;

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    for(n=0; n<rates_total; n++)
    {
        pivothigh=iPivot(high, n, length, length, PRICE_HIGH);
        pivotlow=iPivot(low, n, length, length, PRICE_LOW);

        max=MathMax(high[n],max);
        min=MathMin(low[n],min);
        follow_max=MathMax(high[n],follow_max);
        follow_min=MathMin(low[n],follow_min);

        if(max>max[1])
        {
            max_x1=n-length;
            follow_min=low[n];
        }
        if(min<min[1])
        {
            min_x1=n-length;
            follow_max=high[n];
        }

        if(follow_min<follow_min[1])
            follow_min_x1=n-length;
        if(follow_max>follow_max[1])
            follow_max_x1=n-length;

        if(pivothigh!=0)
        {
            if(show_miss)
            {
                if(os[1]==1)
                void OnStart()
{
int n = LabelCounter;
double min_x1 = ObjectGet("MissedLow" + n, OBJPROP_X1);
double min = ObjectGet("MissedLow" + n, OBJPROP_Y1);
string label_css = "Arial,14,0";

ObjectCreate("missed_low_" + n, OBJ_LABEL, 0, min_x1, min, Label("👻", min_x1, min, label_css));
ObjectSet("missed_low_" + n, OBJPROP_STYLE, STYLE_LABEL_UP);
ObjectSet("missed_low_" + n, OBJPROP_TOOLTIP, DoubleToStr(min, 5));
ObjectSet("missed_low_" + n, OBJPROP_SIZE, SIZE_SMALL);

double px1 = ObjectGet("zigzag_" + n, OBJPROP_X1);
double py1 = ObjectGet("zigzag_" + n, OBJPROP_Y1);

ObjectCreate("zigzag_" + n, OBJ_TREND, 0, px1, py1, min_x1, min);
ObjectSet("MissedLow" + n, OBJPROP_STYLE, STYLE_DOT);
}

double AverageTrueRange(int symbol, int timeframe, int period)
{
double sum = 0.0;
int i;
for (i = 0; i < period; i++)
{
sum += TrueRange(symbol, timeframe, i);
}
return (sum / period);
}

AFTER CHANGE, IT WILL BE
OnCalculate function not found in custom indicator

'{' - unbalanced parentheses

'}' - unexpected end of program


Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.02.04
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
  1. mt4 money #:

    AFTER CHANGE, IT WILL BE

    OnCalculate function not found in custom indicator

    '{' - unbalanced parentheses

    '}' - unexpected end of program

    Please edit your original post and last post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor


  2. You can have only one OnCalculate.

  3. You can not have OnStart and OnCalculate.
  4. if (ShowMiss)
    {
    if (PivotHigh[index-1] == 0)
    {
    Where are those closing braces?
 
//+------------------------------------------------------------------+
//|                                               for lim indi 2.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
                
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 White

double buffer[];
int OnInit()
{
    SetIndexBuffer(0, buffer, INDICATOR_DATA);
   #define INIT_SUCCESS true
}   

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

{
    // Your calculation logic goes here

    return(rates_total);
}

input int Length = 50;
input bool ShowReg = true;
input color RegPhColor = Red;
input color RegPlColor = Green;
input bool ShowMiss = true;
input color MissPhColor = Red;
input color MissPlColor = Green;

int LabelCounter;
double PivotHigh[];
double PivotLow[];
double FollowMax[];
double FollowMin[];
double GhostLevel[];
int FollowMaxX[];
int FollowMinX[];
int MaxX[];
int MinX[];
int Zigzag[];
double Px1[];
double Py1[];

int OnCalculate(int index)

{
int n = index;
PivotHigh[index] = iHigh(NULL,0,Length,Length);
PivotLow[index] = iLow(NULL,0,Length,Length);

FollowMax[index] = MathMax(iHigh(NULL,0,Length,0),FollowMax[index-1]);
FollowMin[index] = MathMin(iLow(NULL,0,Length,0),FollowMin[index-1]);

if (FollowMax[index] > FollowMax[index-1])
{
FollowMaxX[index] = n-Length;
FollowMin[index] = iLow(NULL,0,Length,0);
}
if (FollowMin[index] < FollowMin[index-1])
{
FollowMinX[index] = n-Length;
FollowMax[index] = iHigh(NULL,0,Length,0);
}

if (FollowMin[index] < FollowMin[index-1])
FollowMinX[index] = n-Length;
if (FollowMax[index] > FollowMax[index-1])
FollowMaxX[index] = n-Length;

if (PivotHigh[index] == 0)
return 0;

if (ShowMiss)
{
if (PivotHigh[index-1] == 0)
{
LabelCounter++;
LabelCounter = min(LabelCounter,499);
ObjectCreate("MissedLow"+LabelCounter,OBJ_LABEL,0,MinX[index-1],PivotLow[index-1]-0.5Point,MinX[index-1]+100,PivotLow[index-1]+0.5Point);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_COLOR,MissPlColor);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_BACK,false);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_LEVELCOLOR,RGBA(0,0,0,0));
ObjectSet("MissedLow"+LabelCounter,OBJPROP_LEVELSTYLE,STYLE_DASHDOT);
ObjectSet("MissedLow"+LabelCounter,OBJPROP_TEXT, DoubleToStr(Low[i],Digits));

double pivothigh=0.0;
double pivotlow=0.0;
double max=0.0,min=0.0;
double follow_max=0.0,follow_min=0.0;
int max_x1=0,min_x1=0,follow_max_x1=0,follow_min_x1=0;
int length=50;
bool show_reg=true;
color reg_ph_css=clrRed;
color reg_pl_css=clrGreen;
bool show_miss=true;
color miss_ph_css=clrRed;
color miss_pl_css=clrGreen;
color label_css=clrWhite;
int n=0;
double os=0.0,py1=0.0,px1=0.0;

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

{
    for(n=0; n<rates_total; n++)
    {
        pivothigh=iPivot(high, n, length, length, PRICE_HIGH);
        pivotlow=iPivot(low, n, length, length, PRICE_LOW);

        max=MathMax(high[n],max);
        min=MathMin(low[n],min);
        follow_max=MathMax(high[n],follow_max);
        follow_min=MathMin(low[n],follow_min);

        if(max>max[1])
        {
            max_x1=n-length;
            follow_min=low[n];
        }
        if(min<min[1])
        {
            min_x1=n-length;
            follow_max=high[n];
        }

        if(follow_min<follow_min[1])
            follow_min_x1=n-length;
        if(follow_max>follow_max[1])
            follow_max_x1=n-length;

        if(pivothigh!=0)
        {
            if(show_miss)
            {
                if(os[1]==1)
                void OnStart()
{
int n = LabelCounter;
double min_x1 = ObjectGet("MissedLow" + n, OBJPROP_X1);
double min = ObjectGet("MissedLow" + n, OBJPROP_Y1);
string label_css = "Arial,14,0";

ObjectCreate("missed_low_" + n, OBJ_LABEL, 0, min_x1, min, Label("👻", min_x1, min, label_css));
ObjectSet("missed_low_" + n, OBJPROP_STYLE, STYLE_LABEL_UP);
ObjectSet("missed_low_" + n, OBJPROP_TOOLTIP, DoubleToStr(min, 5));
ObjectSet("missed_low_" + n, OBJPROP_SIZE, SIZE_SMALL);

double px1 = ObjectGet("zigzag_" + n, OBJPROP_X1);
double py1 = ObjectGet("zigzag_" + n, OBJPROP_Y1);

ObjectCreate("zigzag_" + n, OBJ_TREND, 0, px1, py1, min_x1, min);
ObjectSet("MissedLow" + n, OBJPROP_STYLE, STYLE_DOT);
}

double AverageTrueRange(int symbol, int timeframe, int period)
{
double sum = 0.0;
int i;
for (i = 0; i < period; i++)
{
sum += TrueRange(symbol, timeframe, i);
}
return (sum / period);
}

After that, the other 3 questions are,

{
double sum = 0.0;
int i;
for (i = 0; i < period; i++)
{
sum += TrueRange(symbol, timeframe, i);
}
return (sum / period);
}

'}' - unexpected end of program 
{
int n = index;
PivotHigh[index] = iHigh(NULL,0,Length,Length);
PivotLow[index] = iLow(NULL,0,Length,Length);

FollowMax[index] = MathMax(iHigh(NULL,0,Length,0),FollowMax[index-1]);
FollowMin[index] = MathMin(iLow(NULL,0,Length,0),FollowMin[index-1]);

if (FollowMax[index] > FollowMax[index-1])

'{' - unbalanced parentheses    
{
    SetIndexBuffer(0, buffer, INDICATOR_DATA);
   #define INIT_SUCCESS true
}  

'}' - not all control paths return a value      
 
mt4 money #:

After that, the other 3 questions are,

Hello . Let's start with the basics are you feeding the suggestions made here to chatGPT ? There is no shame in that just it looks like you are asking it to change things based on the advice here .

I could be wrong , i have 30mins before the  ⚽️ i'll take a look . 

But if you used chatGPT you will send it the correct code as well , if you don't mind.

(sorry for the abysmal order of words , i'm having the 1st coffee now)

EDIT : This code is not workable , i'm sorry . What is the indicator supposed to do ? 

 

I said (#5.2) you can't have two OnCalculate's. Yet you reposted code that has exactly that. Why are you asking if you are not going to fix your code. You are wasting everyone's time. How RUDE.

 
Lorentzos Roussos #:

Hello . Let's start with the basics are you feeding the suggestions made here to chatGPT ? There is no shame in that just it looks like you are asking it to change things based on the advice here .

I could be wrong , i have 30mins before the  ⚽️ i'll take a look . 

But if you used chatGPT you will send it the correct code as well , if you don't mind.

(sorry for the abysmal order of words , i'm having the 1st coffee now)

EDIT : This code is not workable , i'm sorry . What is the indicator supposed to do ? 

Pivot Points High/Low, sometimes referred to as "Bar Count Reversals" allows highlighting market prices local tops and bottoms. This method compares the price value at a certain index within a user-specified window length and tests whether it is the highest ( pivot high) or lowest ( pivot low).
 
mt4 money #:
Pivot Points High/Low, sometimes referred to as "Bar Count Reversals" allows highlighting market prices local tops and bottoms. This method compares the price value at a certain index within a user-specified window length and tests whether it is the highest ( pivot high) or lowest ( pivot low).

So fractals in essence . 

And just out of curiosity how did you ask ChatGPT for it ?

It is "cute" it tried to have 2 oncalculate functions as it understood theres 2 separate calculations , i think .  

Reason: