A little confused

To add comments, please log in or register
GrumpyDuckMan
734
GrumpyDuckMan  

Hello everyone,

I don't understand what I have done to course error  - constant expression required.

Please enlighten me

double  MAW= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_WEIGHTED, SHIFT);
double  MAT= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_TYPICAL,  SHIFT);
double  MAM= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_MEDIAN,   SHIFT);
double  MAC= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_CLOSE,    SHIFT);
double  MAO= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_OPEN,     SHIFT);
double  MAH= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_HIGH,     SHIFT);
double  MAL= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_LOW,      SHIFT);

double security[]={MAW,MAT,MAM,MAC,MAO,MAH,MAL};

int CC= CopyClose(Security,Timeframe,start_position,Count,CloseCopy); 
int CT= CopyTime (Security,Timeframe,start_position,Count,TimeCopy);
int CO= CopyOpen (Security,Timeframe,start_position,Count,OpenCopy);
int CH= CopyHigh (Security,Timeframe,start_position,Count,HighCopy);
int CL= CopyLow  (Security,Timeframe,start_position,Count,LowCopy);

int PRICE[]={CC,CT,CO,CH,CL};
whroeder1
17926
whroeder1  
double security[]={MAW,MAT,MAM,MAC,MAO,MAH,MAL};
int    PRICE[]   ={CC,CT,CO,CH,CL};
Those are not constants, they are variables. Size your array and assign to the individual elements.
GrumpyDuckMan
734
GrumpyDuckMan  
double  MAW= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_WEIGHTED, SHIFT); MA[0][0]=MAW;
double  MAT= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_TYPICAL,  SHIFT); MA[0][1]=MAT;
double  MAM= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_MEDIAN,   SHIFT); MA[0][2]=MAM;
double  MAC= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_CLOSE,    SHIFT); MA[0][3]=MAC;
double  MAO= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_OPEN,     SHIFT); MA[0][4]=MAO;
double  MAH= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_HIGH,     SHIFT); MA[0][5]=MAH;
double  MAL= iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,PRICE_LOW,      SHIFT); MA[0][6]=MAL;

Hello again,

I came up with this so far.

GrumpyDuckMan
734
GrumpyDuckMan  

Hello again,

Appears that the last element in the array is identified first.

nicholi shen
2261
nicholi shen  
GrumpyDuckMan:

Hello again,

Appears that the last element in the array is identified first.

It's unclear what you're trying to accomplish. No offense, but what is clear is that you're spinning your wheels and would greatly benefit from learning some programming basics and generic design patterns instead of this trial-> error-> post to forum-> repeat cycle. This is some tough love buddy... find one of many free beginner tutorials and practice mql along with it.  

...But just to help you out in the short-term, at very minimum your code could improve by using simple structs, but it could be way better with properly implemented objects. And D.R.Y. !!! :)


   double ma[7];
   for(int i=0;i<7;i++) 
      ma[i] = iMA(Security,Timeframe,Preiod,MA_Shift,MODE_SMMA,i, SHIFT);
  
   MqlRates rates[];
   int total = CopyRates(Security,Timeframe,start_position,Count,rates);
GrumpyDuckMan
734
GrumpyDuckMan  
Mark Watkins:

It's unclear what you're trying to accomplish. No offense, but what is clear is that you're spinning your wheels and would greatly benefit from learning some programming basics and generic design patterns instead of this trial-> error-> post to forum-> repeat cycle. This is some tough love buddy... find one of many free beginner tutorials and practice mql along with it.  

...But just to help you out in the short-term, at very minimum your code could improve by using simple structs, but it could be way better with properly implemented objects. And D.R.Y. !!! :)


Hello again,

I am trying program resistance and support.

 "but it could be way better with properly implemented objects."

Why do I need an object?

I am not using an angle, or drawing a line.

nicholi shen
2261
nicholi shen  
GrumpyDuckMan:

Hello again,

I am trying program resistance and support.

 "but it could be way better with properly implemented objects."

Why do I need an object?

I am not using an angle, or drawing a line.

In programming, "objects" are instances of classes. 

GrumpyDuckMan
734
GrumpyDuckMan  
Mark Watkins:

In programming, "objects" are instances of classes. 

Please explain. Objects have nothing to do with data. They present data. Clarify your comments please.

Anthony Garot
2139
Anthony Garot  
GrumpyDuckMan:

Please explain. Objects have nothing to do with data. They present data. Clarify your comments please.

The term "object" applies to at least two different constructs in MQL.

1. Programming objects, as @Mark Watkins points out, are instances of classes. This is an OOP concept that has been around much longer than MQL.

2. "MQL Graphic Objects" are used for creating arrows, lines, labels, and a host of other interesting goodies. See:
https://www.mql5.com/en/docs/constants/objectconstants/enum_object

@Mark Watkins' advice is sound—you would benefit greatly from going through a few tutorials to bring you to up to speed on programming fundamentals.
GrumpyDuckMan
734
GrumpyDuckMan  

Hello again,

 I'm a little puzzled why both Mark Watkins and Anthony Garot talk about objects on this thread.  I am not creating any objects.

The question was answered in post #1.

Very helpful post, it did take a while for me to understand it.

Anthony Garot
2139
Anthony Garot  
GrumpyDuckMan:

Hello again,

 I'm a little puzzled why both Mark Watkins and Anthony Garot talk about objects on this thread.  I am not creating any objects.

The question was answered in post #1.

Very helpful post, it did take a while for me to understand it.

Well, I cannot speak for @Mark Watkins, but I can say that, in his responses on this forum, he often looks beyond the immediate question for a better way of doing things.

As for me, your statements:

"Objects have nothing to do with data. They present data."

suggested that you did not realize the difference between programming objects (which can and often do have something to do with data) and MQL graphical objects.

To add comments, please log in or register