I think current direction always is 0
you return always 0
I think current direction always is 0
you return always 0
yes I think so but why i dose not change
why you need last direction
int crossed (double line1 , double line2) { static int currentDirection = 0 ; if (line1>line2)currentDirection=1;// up if (line1<line2)currentDirection=2;// down return(currentDirection ); }
If you change ...
currentDirection = lastDirection;
To ...
lastDirection = currentDirection;
it 99% will work ...
I think this is your mistake because it is logically the crossed( ) function is used to detect when the cross is happened while you didn't updated the direction status correctly when the new direction is changed.
So, I believe if you replaced it with the following, it will work ...
int Crossed (double line1 , double line2){ static int last_direction = 0; static int current_direction = 0; if(line1>line2)current_direction = 1; // UP if(line1<line2)current_direction = 2; // DOWN if(current_direction != last_direction){ last_direction = current_direction; return (last_direction); } else{ return (0); } }
Yes that what I'm talking about
also he didn't need Last direction
simply he can return current direction
If you change ...
To ...
it 99% will work ...
I think this is your mistake because it is logically the crossed( ) function is used to detect when the cross is happened while you didn't updated the direction status correctly when the new direction is changed.
So, I believe if you replaced it with the following, it will work ...
yes it works
thank you very mutch
Yes that what I'm talking about
also he didn't need Last direction
simply he can return current direction
yes you are right
but i want to know how to make it work as Mr.Osama did.
and thanks for helping me
what i understand is the error was
currentDirection = lastDirection;
it mean i take the result of direction which is (1or 2) and made it equal to last direction which is always(0)
and when i use
lastDirection = currentDirection ;
i made lastDirection equal to (1or 2) as currentDirection
so Mr Omar was right when said it always return 0
and Mr Osama declared why it return 0
Exacly Mazen.
Omar was right. Me said how to correct the mistake.
Happy that it works now.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi i made this expert with function and it is not work
but without fuction it work very well
so i want to know the wrong in this function