OrderModify problem

To add comments, please log in or register
mkowal
22
mkowal  
hi,

I have a problem with an EA, which instead of opening just only one position, keeps opening positions with each tick....
After evaluation of the code, I suspect, that the only part which might cause the problem is Trailing Stop modification section, which looks like that:

if(Selling==0 && SellStartCondition)
{ Selling=1; // if condition is met set the Selling Status = 1 ticket=OrderSend(Symbol(), OP_SELL,Lots,Bid,3,TrStop,Bid-100*Point,"Selling !!!", 54321,0,Green);

...

return(0); } if(Selling==1 && Trailer(TSDparam,TrStop)>0) //Trailing Stop modification { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true) { OrderModify(OrderTicket(),OrderOpenPrice(),TrStop,OrderTakeProfit(),0,Green); } else Print("OrderSelect returned the error of ",GetLastError()); }

if(Selling==1 && SellStopCondition) //we have been selling and now we want to stop it
{

Selling=0; // if condition is met set the Selling Status = 0

OrderClose(OrderTicket(),Lots,Bid,3,Violet);

...

return(0); }



now the questions:

1. if I modify an order should I use OrderModify with all the argument as it is above, or can I omit the not important agruments, like that:
OrderModify(OrderTicket(),,TrStop);

2. if in my EA there is only one open position possible at the same time, do I need to use OrderSelect prior to OrderModify ?

thanx in advance,

CoVal

RickD
1226
RickD  
1. All the parameters required. In case you have no intention to change StopLoss value for example, use OrderStopLoss() function.
2. The best of all would be using of OrderSelect function.
mkowal
22
mkowal  
Thanx Rick,
in the mean time I have made some experiments and well, it looks like it is the best solution to use all of the parameters.

but there is another problem - this time with variable declaration:

if I declare a variable before the start() function (right after the extern fuctions declaration) it can be seen from any function and it's value is not re-initialized each time the start function is called.

But how about the static variable ? as I understand the manual, if I give it initial value within the start() function and than I change it's value, next time the start() is called the variable is not re-initialized and the last given value should be still assigned to it.

But - somehow it doesn't work: in the above example, the Buying variable was declared as a static int in start() function.
It was supposed to prevent the EA from opening more than 1 position at the same time (the Buying==1).
but it sometimes kept the value, and sometimes lost it.... no idea why.... moving the variable declaration outside the start() function helped.

should I declare all of the important variables in the section ?
what the static variables are finally for ?

best regards,

CoVal
To add comments, please log in or register