Hello,
I have a problem and can't find solution with my expert adwisor.
Maybe because I'am absolutely green in programing and it is first programing project in my life :)
The problem is, that last operator in code always is TRUE. I'am talking about this: " if(SL!=Sup-0.0005||TP!=Res+0.0005) ". Why is that? At first iteration when order stop levels not equal to NEW stop levels (sets by new support and resistance levels) this operator is realy could be TRUE - and orders are modified. But why at next tic this operator again TRUE when orders allready is modified? At each tic this operator passing control to operator body. Why is that?
When I removing these arithmetical operations (+0.0005;-0.0005) then everything is ok. But I can't remove them, because I need them.
I would be very thankful for your comments.
Your English is fine . . . no problems understanding your question
First some general comments:
. . . don't do this
if (OrderType()!=0) continue; //order is not BUY,continue.
. . . if you are checking for a BUY then use OP_BUY it makes your code easier to understand.
Did your OrderModify() work ? don't you want to know if it did or didn't ? and if it didn't work don't you want to know why and what the values of the related variables were ?
modify_conf=OrderModify(ticket,Ask,SLnew,TPnew,0); //modify it!
read this: What are Function return values ? How do I use them ?
It's very easy for this to be true even when you think it isn't . . .
if(SL != Sup - 0.0005 || TP != Res + 0.0005)
. . . comparing double values has to be done with care and understanding, please read this complete thread: Can price != price ?
OrderOPenPrice can only be modified for pending orders and I would think for pending orders, using Ask would result in an error
modify_conf=OrderModify(ticket,Ask,SLnew,TPnew,0); //modify it!
Your English is fine . . . no problems understanding your question
First some general comments:
. . . don't do this
. . . if you are checking for a BUY then use OP_BUY it makes your code easier to understand.
Did your OrderModify() work ? don't you want to know if it did or didn't ? and if it didn't work don't you want to know why and what the values of the related variables were ?
read this: What are Function return values ? How do I use them ?
It's very easy for this to be true even when you think it isn't . . .
. . . comparing double values has to be done with care and understanding, please read this complete thread: Can price != price ?
Thank you for your operative answer and useful comments. My worst nightmare is coming true - solution is floating somewhere in "can price!=price?" For newbie it will be difficult task to to find it :D
if talk about messages and confirmation to trader about modifying success, I use them. I didn't show it in my code/question. Just wanted to show real problem without "bonus material". By the way - after trying to modify allready modified order I'm receiving error code=1.
NEVER compare double (floating point) values.
== is never true
!= is always true
http://randomascii.wordpress.com/2012/02/11/they-sure-look-equal/
http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I have a problem and can't find solution with my expert adwisor.
Maybe because I'am absolutely green in programing and it is first programing project in my life :)
The problem is, that last operator in code always is TRUE. I'am talking about this: " if(SL!=Sup-0.0005||TP!=Res+0.0005) ". Why is that? At first iteration when order stop levels not equal to NEW stop levels (sets by new support and resistance levels) this operator is realy could be TRUE - and orders are modified. But why at next tic this operator again TRUE when orders allready is modified? At each tic this operator passing control to operator body. Why is that?
When I removing these arithmetical operations (+0.0005;-0.0005) then everything is ok. But I can't remove them, because I need them.
I would be very thankful for your comments.
P.S. Sorry for my english...