hmmm thanks gordon at least i know thats not where my problem lies
I hate to be a pest always asking for help would you mind taking a look at this I cant figure out where I went wrong the code compiles maybe its an error in my own logic
I wrote this fucnction to compare several MA's with one other and checks to see if they crossed it and if they did, to trigger a unique buy or sell signal for each MA (i plan to use that as magic number to identify which MA the order came from).
It puts the previous values of all the MAs to check into an array, Mas_Check at [0,0] through [0,6] and the previous value of line for them all to be compared with at [0,7]
then it puts all the current values of the MA's in the same array at [1,0] through [1,6]and the current value of the line to be compared with at [1,7]
then the following code does comparisons to see if the previous value of the comparison line was higher or lower than each of the MA's and puts 1 or 2 in the array for each MA at indexes [2,0] through [2,6]
(1 if the comparison line was lower 2 if it was higher)
then it does comparisons of the current values of the MA's in the same way and puts 1 or 2 in the array indexes [3,0] through [3,6]
then it compares those last two sets of array indexes to see if there was a line cross or not,
the continue line I mentioned in the last post was in case there is a zero left over from the array initialization it could be carried forward from the previous array index if the values were equal so i want to exit that iteration of the loop at that point and go to the next one my reasoning being at the next tick any zeros would be overwritten when the line values change.
The problem is, the first set of comparisons work and assign the 1s or 2s into the array, the second set of comparisons also work and put 1s or 2s into the array but when there is a 1 from the first set and a 2 from the second set ( array [i,2] compared with [i,3] the last set of comparisons is always putting a zero in [i,4] even when [i,2] and [1,3] are different.
for (int i=0; i<7; i++)
{
Ppr = Mas_Check[7,0]; // Get previous CLine value from array
Cpr = Mas_Check[7,1]; // Get current CLine value from Array
Pclr = Mas_Check[i,0]; // Get all previous MA values from array
Cclr = Mas_Check[i,1]; // Get all current MA values from array
Pres = Mas_Check[i,2]; // Get last CLine vs MA result (1 or 2)
Cres = Mas_Check[i,3]; // Get current CLine vs MA result (1 or 2)
if (Ppr<Pclr) Mas_Check[i,2] = 1; // Previous ComparisonLine was below MA
if (Ppr>Pclr) Mas_Check[i,2] = 2; // Previous ComparisonLine was above MA
if (Cpr == Cclr )
Mas_Check[i,3] = Mas_Check[i,2]; // If current C Line and MA are equal = line didnt yet cross value still same as uncrossed
if (Cpr<Cclr) Mas_Check[i,3] = 1; // Curent CLine is below MA
if (Cpr>Cclr) Mas_Check[i,3] = 2; // Current Cline is above MA
if (Mas_Check[i,3]<1) continue; // Ignore any invalid zero signals ****May be causeing a problem****
if (Pres<Cres) Mas_Check[i,4] = 2; // CLine crossed to above MA (Buy Trigger)
if (Pres>Cres) Mas_Check[i,4] = 1; // CLine crossed to below MA (Sell Trigger)
if (Pres==Cres)Mas_Check[i,4] = 0; // Result is zero if there was no cross
if ((Mas_Check[i,4])>0)
Crossed = ((i*1000)+(Mas_Check[i,4]*100)); // Use array index and crossed signal to create unique buy/sell signals for each MA
I have no idea... But just for general knowledge - if you are comparing doubles then this won't work properly:
if (Cpr == Cclr )
There is a good article that describes how to properly do it -> Working with Doubles in MQL4; you should read part 4 about checking the equality of 2 doubles.
p.s. Next time -
well that (Cpr == Cclr) is not a critical calculation for the function to work, that is just a error prevention in case the chance might arise when the two lines have equal values it substitutes the previous value to it, because the logic behind this function needs them to remain unequal, ie: have not yet crossed
I think I figured it out
Pres = Mas_Check[i,2];
Cres = Mas_Check[i,3];
they are in the wrong place I believe they need to be after the fifth if because their values in the array depend on the results of the comparisons in first five ifs
at least I think thats what the problem is this programming game gets very confusing I'm glad I dont have to do this for a living lol
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is a call to an array considered an operation ?
for instance if the arrray element is less than 1 continue
should be written like this ?
for (int i=0; i<7; i++)
{
if (My_Array[i,3]<1) continue;
//do more stuff;
}
or should it be considered the call to the array is a separate operation so should be in parenthisis like this ?
for (int i=0; i<7; i++)
{
if ((My_Array[i,3])<1) continue;
//do some more stuff;
}
it compiles either way so what is the difference ?
the reason I ask is I have a problem with my code not doing what i intended it to do and I wonder if it is in that statement and others like it because I have been doing it the first way, with only one set of parenthesis because I thought the only operation was the <1 part