| / | Forum |
|
JPS
2010.11.26 15:35
This might be a dumb question, if yes - I apologize for my lack of know how. I am curious if this is okay code. I'm talking about the while operator at the end where I call the ModifyShorts() again until the result is false. I'm just trying to make sure I'm bug free and that the code completes it's assignment. MetaEditor help states that the return operator should not contain an assignment operator, but void is not an operator. void ModifyShorts() { int totalorders = OrdersTotal(); for(int i=totalorders-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == ExpertNumber && (OrderType() == OP_SELL ))) {result = OrderModify(OrderTicket(), OrderOpenPrice(),ObjectGet ("xTBUpper", OBJPROP_PRICE1),ObjectGet ("xTBLower", OBJPROP_PRICE1),0, CLR_NONE); RefreshRates();} } while (result>0) {ModifyShorts();} } |
|
This article dwells on the ways of transferring an indicator code into an Expert Advisor Code and on writing Expert Advisors with no calling to custom indicators, and with the whole program code for the calculation of necessary indicator values inside the Expert Advisor. This article gives a general scheme of Expert Advisor changing and the idea of building an indicator function based on a custom indicator. The article is intended for readers, already having experience of programming in MQL4 language. |
2030 |
gordon
2010.11.26 15:46
Recursive calls don't work well with the tester so I would avoid such code. Better do it iteratively. |
|
zzuegg
2010.11.26 16:40
maybe i get it wrong. but this should cause a endless loop. the "result" in upper iterations are not modified in a lower level of rekursion. since modify shorts does not return anything and result itself is not modified inside the while loop. Maybe works in mql since i have heard it doesn't use a namespace for variables. But if it works, its not nice to read, nor economic to run. |
|
7bit
2010.11.26 18:09
You can easily shoot yourself into the foot when using recursions, especially when the same code can (and should) be written without recursion. Recursion is usually only¹ used when the problem itself is recursive by its nature, for example iterating over all nodes in a tree (for example all folders and sub-folders and sub-sub-folders, etc). Recursion will heavily use the stack because each function call needs to return eventually and so it must remember each recursive function call to be able to unwind it and return from each and every one of them again at the end if it is done. This can easily lead to a stack overflow if it is not known beforehand or somehow limited how many levels deep it might go. Repeatedly trying to do the same thing until it succeeds is not a recursive problem at all and you should do it in a loop that repeatedly calls the function from the outside and not let the function call itself. Your above code is the wrong solution to the problem! _____ |
|
JPS
2010.12.09 20:24
Thanks guys for you expertise! It did not go unappreciated! :) |