I am getting Error '[' - array required.

 

I am trying to set conditions for long and Short

longCond = (Source1 > filt[i] && Source1 > Source1[i - 1] && upward[i] > 0) || (Source1 > filt[i] && Source1 < Source1[i - 1] && upward[i] > 0);
shortCond = (Source1 < filt[i] && Source1 < Source1[i - 1] && downward[i] > 0) || (Source1 < filt[i] && Source1 > Source1[i - 1] && downward[i] > 0);

In this code, Source1 is an input and its set to close.

input ENUM_APPLIED_PRICE Source1 = PRICE_CLOSE;

All others are Array. Declared as follows.

double filt[];
double upward[];
double downward[];
double CondIni[];
bool longCond, shortCond;

The problem is when i compile it shows Error at" Source1[i-1] ".

 Can Anyone help me to solve this error. I am a newbie to MQL5.

 
suresh2276: Can Anyone help me to solve this error. I am a newbie to MQL5.
input ENUM_APPLIED_PRICE Source1

You already know what the problem is. You haven't declared Source1 as an array. Source1 is the constant zero (PRICE_CLOSE).

Use your Source1, to read the current and previous price.

 
You are right, an array is needed here, but Source1 is not an array.

Also the value PRICE_CLOSE is not a double price, it is just an enumeration.
 
suresh2276:

I am trying to set conditions for long and Short

In this code, Source1 is an input and its set to close.

input ENUM_APPLIED_PRICE Source1 = PRICE_CLOSE;

All others are Array. Declared as follows.

The problem is when i compile it shows Error at" Source1[i-1] ".

 Can Anyone help me to solve this error. I am a newbie to MQL5.

It seems that you do not understand well how to distinguish data types

Read the basics again

You can compare an array data type with a normal data type in MQL5 programming language by using the ArrayCompare function. This function returns the result of comparing two arrays of simple types or custom structures without complex objects³. 


I hope this helps!

(1) Array Functions - MQL5 Reference - Reference on algorithmic/automated .... https://www.mql5.com/en/docs/array.

(2) Data Types - Language Basics - MQL5 Reference - Reference on .... https://www.mql5.com/en/docs/basis/types.

(3) Structures, Classes and Interfaces - Data Types - MQL5. https://www.mql5.com/en/docs/basis/types/classes.

 
Comments that do not relate to this topic, have been moved to "Off-topic posts".