Is it possible to avoid many "ors" (||) in conditions causing the same action? - page 4

 

borilunad:

The most complex calculations do not slow down as much as functions that check the various necessary market data and open positions on every tick.

Holy truth, MarketInfo is one of the worst testing problems. I usually write in two blocks for such cases if possible, making "real" queries only for real trading mode. This is especially effective for unmeasured (in the tester) data, for example:

int spread;

int init()
{
...

   if(IsTesting())
   {
      spread = MarketInfo(Symbol(),MODE_SPREAD);
   }

...
 
}

int start()
{
...

   if (!IsTesting())
   {
      spread = MarketInfo(Symbol(),MODE_SPREAD);
   }

...
}

You can also send in block if(!IsTesting()) all sorts of RefreshRates(), queries to MODE_BID and MODE_ASK (replacing them with quick Bid and Ask) and so on.

 
alsu:

Holy truth, MarketInfo is one of the worst testing problems. I usually write in two blocks for such cases if possible, making "real" queries only for real trading mode. This is especially effective for unmeasured (in the tester) data, for example:

You can also send in block if(!IsTesting()) all sorts of RefreshRates(), queries to MODE_BID and MODE_ASK (replacing them with quick Bid and Ask) and so on.

I do not mean the MarketInfo function that I have at the beginning of my start-up, but the functions that check various parameters of the market and open positions that are specified in the conditions necessary for taking actions. Moreover, I don't need MODE_BID and MODE_ASK, because I always use Bid and Ask.
 
pako:

Thank you very much, Pako! How did I not guess, it's so easy! I'll have dinner now and do what I can and check the speed of the passage.

And this I don't understand what you mean. Where did you get those numbers from? And if you're interested in short variable names, I prefer short ones to long ones. Or what else? Yes, just noticed that you added two brackets before clo and at the end after clo to my formula. That's not necessary at all, it disturbs the calculation. But thank you all the same!

<--- 10,444 = 8,087 > 3,908 is that in what language?

Made, checked, it worked, but the result has not pleased me yet, practically did not reduce the time of the run! Tomorrow I'll try to do everything I can, maybe then there will be some difference.

But anyway the main thing is that thanks to you, Pako, Aleksey, Victor and others I've learned another important method of code writing, for which I'm extremely grateful!

 

I use a function in such cases.

For example:

...
if (Request()) Action;

bool Request()
{
 if (A) return(true);
 if (B) return(true);
 if (C) return(true);
 if (D) return(true);
 return(false);
}
 
borilunad:
I always use Bid and Ask.

Then you do need RefreshRates()))
 
icas:

I use a function in such cases.

For example:

As I understand it, you have a variant for fulfilling all conditions, while for me only one condition is enough, and even if more conditions are fulfilled, which is unlikely, because they are very different, it will not come to that, because one condition will work. If I've got it wrong, justify it! I'm always happy to hear something new! Thanks!
 
alsu:

Then you do need RefreshRates()))
Yes, I have RefreshRates() at the start, or is that not enough?
 
borilunad:
Yes, I have RefreshRates() at the start, or is that not enough?
It all depends on how long the calculation takes to execute. There can be a situation, when during this period the price has updated, and hence Ask and Bid become irrelevant. Therefore it is better to call RefreshRates() additionally before executing trades (more precisely, before price calculation for them).
 
borilunad:
Yes, I have RefreshRates() at the start of Start, or is that not enough?
There is no point in using RefreshRates at the start of Start, as Ask and Bid have not yet become obsolete.
 
alsu:
It all depends on how long the calculations take to run. There may be a situation where the price has updated during this period, and hence Ask and Bid become irrelevant. That's why it's better to call RefreshRates() additionally before executing trades (or rather, before calculating prices for them).

So you need RefreshRates() before each series of conditions? Because I thought there's also RefreshRates() in each executing function, where it checks for errors, to repeat the order, and that's enough. Then I'll try putting more RefreshRates() and see what happens! Thanks!

And Pap'e Yozh my thanks as well!