Can't get even the most basic thing to compile in metaeditor

 

What follows is just the start of my program. It tells me "initialization expected" about the line:

double meantimefortradereversal[numberofentities][3]={{160, 240, 480}, {160, 240, 480}, {113.3, 170, 340}, {200, 300, 600}, {266.7, 400, 800}, {240, 360, 720}, {370, 555, 1110}, {800, 1200, 2400}, {200, 300, 600}, {200, 300, 600}};

What the hell is wrong with that? It's telling me "initialization expected", and "expression on global scope not allowed", and then to add insult to injury, it has the nerve to claim "unbalanced parentheses" on that line! What the hell! Or is it something in the rest of the program? Also, I don't like how I had to do this:

#define numintraweekthresholds 5
#define numintraweekthresholdsminus1 4

because it wouldn't let me simply declare a double array with numintraweekthresholds-1 entries. Even that produced compiler errors! And then after much frustration I figured out it was objecting to numbers that were less than 1 but didn't have a 0 before the decimal point, so .3 creates a compiler error but 0.3 is ok. This is horrible, how does anyone use this horrible programming language? They ought to call it "C--". Get it? Ha ha, yeah, funny. Well, here is the whole thing, in case you want to copy and paste and see if you get the same errors I get. Hopefully the forum formatting won't screw it up too badly or if it does, pasting it into notepad will make it nice:


//+------------------------------------------------------------------+

//|                                                endgamedevice.mq4 |
//|                                           nooneimportant |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "nooneimportant"
#property link      ""

#define samplespaceallocated1 80640 //Number of spaces allocated to storing history
#define samplespaceallocated5 40320
#define samplespaceallocated15 26880
#define samplespaceallocated60 20160
#define samplespaceallocated240 20160
 int samplespaceallocated[5]={samplespaceallocated1, samplespaceallocated5, samplespaceallocated15, samplespaceallocated60, samplespaceallocated240};
#define numberofentities 10 //Number of different things that are traded or examined
#define maximumtimegapinseconds 361200 //If there is a gap in the data more than this number of seconds, then it throws out all data before that.
 string nameofentities[numberofentities]={"EURUSD", "USDJPY", "GBPUSD", "USDCAD", "AUDUSD", "USDCHF", "NZDUSD", "USDMXN", "XAUUSD", "XAGUSD"};
 bool entitytype[numberofentities]={0 1 0 1 0 1 0 1 0 0};
//Entitytype is 0 if XXXUSD, 1 if USDXXX.
 double lotsize[numberofentities]={100000 100000 100000 100000 100000 100000 100000 100000 100 1000};
//lotsize is quantity of the entity in the numberator in lot. XXX if type 0, USD if type 1.
 double minportionoflot[numberofentities]={0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.1 0.1};
//minportionoflot is the fraction of a "lot" allowed to be traded.

 double pricehistory1[numberofentities][samplespaceallocated1];
 double pricehistory5[numberofentities][samplespaceallocated5];
 double pricehistory15[numberofentities][samplespaceallocated15];
 double pricehistory60[numberofentities][samplespaceallocated60];
 double pricehistory240[numberofentities][samplespaceallocated240];
 int pricehistorylength[numberofentities][5];
 datetime pricehisttimemostrecent[numberofentities][5];
 int positionofmostrecentsample[numberofentities][5];
 datetime startofweekmodulo604800; //When the start of week is determined based on data,
     //this will be set to the actual time index for it.
 double brokersetleveragelimit=50; //It needs to actually observe what the broker sets this to.
     //The maximum leverage the program assumes can't be my limit if the broker sets a lower one.
     //50 is the default value.
#define numintraweekthresholds 5
#define numintraweekthresholdsminus1 4
 double timeofweekcreateleveragelimit[numintraweekthresholds]={0 0 300 0 0};
 double settleovercreateleverageratio=1.4;
 double timeofweekemphasis[numintraweekthresholds]={0 1 1 0 0};
 double timeweekexpdirection[numintraweekthresholdsminus1]={1 1 0 0};
 /*timeweekexpdirection=0 between 2 time thresholds (modulo 604800) T1 and T2 means interpolation is:
     U=leveragelimit(T2)-(leveragelimit(T1)-leveragelimit(T2))/(exp((T1-T2)/meantradetime)-1)
     leveragelimit(time)=U+exp((time-T2)/meantradetime)*(leveragelimit(T2)-U).
   timeweekexpdirection=1 between 2 time thresholds means interpolation is:
     U=leveragelimit(T1)-(leveragelimit(T2)-leveragelimit(T1))/(exp((T1-T2)/meantradetime)-1)
     leveragelimit(time)=U+exp((T1-time)/meantradetime)*(leveragelimit(T1)-U).

     And same with timeofweekemphasis.
 */
 double timeofweekemphasisrunningsum[numberofentities];
     //Since the trade time is different for every entity, the integral of the emphasis over a
     //week isn't fixed. Of course, even if it was a fixed function of emphasis over the course
     //of a week function, the recent weighted emphasis integral would still vary over the week.
 double volatilityequivnumminutsofsamps[numberofentities];
     //With the exponentially weighting and the intraweek variable weighting, this keeps track
     //of the total number of minutes in the volatility matrices. They are mean square values, and
     //the way that is calculated is to have an exponentially weighted sum, but then it has to be
     //divided by the number of minutes in the average to get the mean square change in price in
     //that time. This is that number of minutes. This also will give an idea about the statistical
     //significance of the covariance matrices themselves: the number of minutes in the sum divided
     //by the number of minutes in the time difference of things added together gives a sort of
     //number of samples in the covariance matrix, and how statistically significant the results
     //using that particular covariance matrix are.
 datetime timeofweektimethresholds[5]={0 1800 86400 432000 604800};
     //During the weekend is not a good time to use statistical data! It'll just be a
     //straight-line interpolation! Also, right when the week starts is not a good time to
     //start trading, and it should wind its positions down as the week comes to a close.
 double meantimefortradereversal[numberofentities][3]={{160, 240, 480}, {160, 240, 480}, {113.3, 170, 340}, {200, 300, 600}, {266.7, 400, 800}, {240, 360, 720}, {370, 555, 1110}, {800, 1200, 2400}, {200, 300, 600}, {200, 300, 600} };
     //The mean time after buying an entity that selling ensues, or vice versa.
     //The first is the trade reversal time when it's already 1 standard deviation above the average leverage and buying more (or one std below and selling more), the second is the reversal time at the mean, and the third is the reversal time when it's 1 standard deviation below average, namely closing out outstanding positions, how long until you make them anew again.
 double meansquaretimefortradereversal[numberofentities][3]={{32000, 72000, 288000}, {32000, 72000, 288000}, {16046, 36125, 144500}, {50000, 112500, 450000}, {88889, 2000000, 800000}, {72000, 162000, 648000}, {171125, 385031.25, 1540125}, {800000, 1800000, 7200000}, {50000, 112500, 450000}, {50000, 112500, 450000}};
     //The mean square time after buying an entity that selling ensues, or vice versa.
 double varianceofpositionsowned[numberofentities];
     //To know which mean square time for trade reversal to use: linear interpolation using the
     //current position value relative to the mean (which will be almost 0) in standard deviations.
     //Ideally, it would use a linear interpretation of the log of the time, but the actual values
     //that would be calculated over the mean trade times are also not known except at the values
     //they will be stored at, namely the 3 times. So it will have to be a linear interpolation
     //of the 3 trade recommendation outputs.


int init()
  {



//----
  
//----
   return(0);
  }


int deinit()
  {
//----
  
//----
   return(0);
  }


int start()
  {
//----
  
//----
   return(0);
  }
 

 datetime timeofweektimethresholds[5]={0 1800 86400 432000 604800};

Missing commas?
 
eddy2slow:

 datetime timeofweektimethresholds[5]={0 1800 86400 432000 604800};

Missing commas?
Afraid not. I added this all one line at a time and compiled it each time and it didn't object to that line. It was only when I put in the 2-d array that it started doing that. So it must be ok with no commas like that. Also, I tried it just now again with that line commented out and also with commas in there and no that didn't change a thing.
 
omegamachine:
Afraid not. I added this all one line at a time and compiled it each time and it didn't object to that line. It was only when I put in the 2-d array that it started doing that. So it must be ok with no commas like that. Also, I tried it just now again with that line commented out and also with commas in there and no that didn't change a thing.
Maybe you should read the documentation before complaining about the language.
MQL4 Reference - MQL4 Documentation
  • docs.mql4.com
MQL4 Reference - MQL4 Documentation
 
omegamachine:
Afraid not. I added this all one line at a time and compiled it each time and it didn't object to that line. It was only when I put in the 2-d array that it started doing that. So it must be ok with no commas like that. Also, I tried it just now again with that line commented out and also with commas in there and no that didn't change a thing.
I have added the commas and it seems to be ok.
 
lost89:
I have added the commas and it seems to be ok.

Interesting that worked for you. Adding the commas in did not work for me. For me, it didn't even care whether the commas were there or not, but it DID care about something your compiler didn't care about, isn't that weird? Well, the mystery is solved. I couldn't post until now because that rotten and arrogant troll of an admin who had nothing useful to say and simply told me to go read the book again locked my account simply because I asked him not to clog the thread with unproductive comments. I don't know if it's my version of metaeditor, or some interaction with my computer, but it turns out that it absolutely refuses to accept nested brackets {{0, 0}, {0, 0}}; - if I want to declare an array with 2 or more indices and initialize it, it ONLY works with me if I do it all inline, {0, 0, 0, 0}; as if I was declaring a variable with 1 index but 4 entries. If I put in nested brackets, I get a large quantity of compiler errors that don't make sense, "unmatched parentheses" included.

Which is NOT what the documentation says Mr. Angryvoyeur, what I had was exactly what the documentation said I should have and it still didn't work. You sir are dead wrong and arrogant to assume I need to go back and read the stupid useless thing again and to dismiss my problem without even looking at it as something that would certainly be solved by the information contained in that stupid book, wronger still for deleting my comment and banning me for a time merely for insisting you post something useful or not post anything, something completely NOT in the documentation was the problem, so asking me to read the documentation was BAD advice any way around it, and you know what, I'll never show deference to a bully and I don't care what admin abilities you have, I don't care if you have the power to jump straight out of my computer screen and slap me in the face, you can delete this comment too and I can't stop you, all you'll be doing is proving me right and depriving the world of the answer to a problem, if someone else has the same problem I did in the future, and no it is not "abusive" or "offensive" to object to someone else just trying to be insulting in the process of providing nothing of any use, no more than it's "assault" to use karate against a mugger who is pointing a gun at me.

Anyway. So for anyone like me in the future, in the unlikely event my comments aren't deleted for standing up for myself against a bully with power he shouldn't have, we have a list of things to remember which are NOT in the documentation now, things that wasted a LOT of my time trying to track down. Maybe they're problems for you, maybe not:

1. Always put in a leading 0 before a decimal expression for a number less than 1. In other words, don't use .6 in your code, use 0.6 because .6 will cause compiler errors.

2. Don't initialize multivariable arrays with nested brackets. Declare and initialize a m by n by p array with a single inline sequence of m*n*p entries. So {0, 0, 0, 0} instead of {{0, 0}, {0, 0}}. Unfortunately, it isn't obvious which one is the most significant and no it is NOT explained in the documentation, in other words, if I want it to be all 0's except for m=1, n=p=0, where I want it to be 1, would I initialize it as {0, 0, 0, 0, 1, 0, 0, 0}, as {0, 0, 1, 0, 0, 0, 0, 0} or as {0, 1, 0, 0, 0, 0, 0, 0}? I don't know. Fortunately most of the things I want to explicitly initialize with my declarations are square symmetric matrices so it's the same either way since it equals its own transpose.

Well, I'm done with this place. If there's any head admin who reads this, I suggest you show more discretion over who you give admin powers to.

 
omegamachine:...

This time I will not delete your post, so everyone can see by itself.

So you post here for the first time and you are thinking you can do and write all what you want without any problem. You are lacking the most obvious politeness.

I pointed you on the right direction : the documentation. Do I have to read it for you ? The answer to your problem IS on the documentation. There is no problem with ".6" notation or nested brackets.

2 other users wrote you where the problem is. But it seems it's more important for you to insult people.

I am banning you for 1 more week. Next time, will be forever.

Initialization of Variables - MQL4 Documentation
  • docs.mql4.com
Initialization of Variables - MQL4 Documentation
Reason: