Fast and Slow program structure

 

Do we need to think about the speed of functions in our program structure? If code uses Trade Functions between the the part of the code that makes the decision to trade and the code that actually makes the trade, then speed could matter. In a fast moving market would the following program be too slow? 

if ( tradeSetup() == true ) // should I enter the trade now?
{
   ... OrderSelect(somthing) ... ; // slow
   ... OrdersTotal(somthing) ... ; // slow
   ... OrderLots(somthing) ... ; // slow
}
doTrade(); // hope this was not too late!
 

 

 Would the program be more reliable if we call the Trading Functions ahead of these time sensitive parts of code and assign them to variables like this? So the code uses faster variables in time sensitive sections.

OrderSelect(somthing); // slow
y = OrdersTotal(somthing); // slow
z = OrderLots(somthing); // slow
if ( tradeSetup() == true ) // should I enter the trade now?
{
   ... y ...
   ... z ...
}
doTrade(); // much faster
 

 What do you think?

 
OrderSelect, OrdersTotal, OrderLots are fast. They read data, which is already fetched. You should worry only about OrderSend and OrderModify, that wait for server response.
 
MisterDog:

Do we need to think about the speed of functions in our program structure? If code uses Trade Functions between the the part of the code that makes the decision to trade and the code that actually makes the trade, then speed could matter. In a fast moving market would the following program be too slow? 

 

 Would the program be more reliable if we call the Trading Functions ahead of these time sensitive parts of code and assign them to variables like this? So the code uses faster variables in time sensitive sections.

 What do you think?

 

Using a variable will always be quicker than calling a function,  do you really need the speed ?  are you happy you can be sure your variable is current and not holding a value that is now out of date ?  I would suggest that first you make your code work as you want it to,  then if it needs it optimize it for performance. 
 
Ovo:

Only OrderSend and OrderModify wait for the server. This is good to know. Perhaps speed was not my program issue -- just sloppy coding.
 
RaptorUK:
Using a variable will always be quicker than calling a function,  do you really need the speed ?  are you happy you can be sure your variable is current and not holding a value that is now out of date ?  I would suggest that first you make your code work as you want it to,  then if it needs it optimize it for performance. 


Since most of the Order functions don't call on the server then I do see your point. -- thanks.
 
MisterDog:

Only OrderSend and OrderModify wait for the server. This is good to know. Perhaps speed was not my program issue -- just sloppy coding.
And OrderClose(), OrderCloseBy() and OrderDelete()  also some other functions may also wait for the server to respond.
 
Ovo: You should worry only about OrderSend and OrderModify, that wait for server response.
RaptorUK: And OrderClose(), OrderCloseBy() and OrderDelete()  also some other functions may also wait for the server to respond.
Agreed. Those and calls that download history (different pair/TF) (iTime, etc/ArrayCopyRates)



Reason: