Quick and easy question

 

I am a beginner.

In the example of code below I have a "for" loop after the first "if" statement and another "if" statement further down.

Let us say in the first two loops the following test

(Close[i] < Open[i])

is true. What happens if in the next loop (the third one) "Close" is not smaller than "Open" (making the "if" statement false), will the total of four loops be completed or will the code jump to the next statement or operator?

Here is the piece of code

          if (nBarHighNo == 5)
            {
             nBullRevBars = 0;
             nBearRevBars = 0;
              for (i = 4; i >= 1; i--)
                 { 
                  RefreshRates();
                  if (Close[i] < Open[i]) nBullRevBars = nBullRevBars + 1;
                 }
             }
 

The if statement in there has no relevance whatsover on the "for" loop. The loop makes 4 cycles, that's it.

If you had if(bal bla) {code1; continue; } that would interfere with your for loop.

The 2 repeating loop controllers are continue; and break; they're quite selfexplanatory.

 
forexCoder:

The if statement in there has no relevance whatsover on the "for" loop. The loop makes 4 cycles, that's it.

If you had if(bal bla) {code1; continue; } that would interfere with your for loop.

The 2 repeating loop controllers are continue; and break; they're quite selfexplanatory.


Thanks a lot forexCoder for clearing that up for me!
 

You probably don't need Refreshrates in your loop and could possibly add some confusion to whatever you are trying to achieve.

If you refreshrates and this then shifts the timeseries up mid loop then result is confused. The open and close values will be fixed for time you are running the EA and to get the result you are looking for should remain fixed IMO.

 
Good to be aware of
RefreshRates()


but it will only affect the current bar values, i.e. anything with [0] or [i] where i=0, and it will be a performance hit

So in the code posted, RefreshRates() will not change anything as i never gets to 0

Save it for when you need it just before order handling or before a price-level triggered decision, etc

-BB-

 

Thank you very much guys for pointing that out to me.

BarrowBoy your explanation of "anything with [0] or [i] where i=0," made the light come on!

I taking it out of this loop!

 
BarrowBoy:
So in the code posted, RefreshRates() will not change anything as i never gets to 0
Completely wrong, looking at C[0] is irrelevant. You only need refreshRates if there are multiple server calls (e.g. multiple OrderClose) or if the EA doesn't return from start or takes long time to calculate.
 

Hmm.

If I understood correctly, he meant that RefreshRates() changes and updates the Close[0] to the last known price. You want to say that it doesn't?

 

(Cough!) - what happens if the refreshrates happens at the same time a new bar is created?

EA is suspended during an OrderSend() OrderModify - if timing is slow or order errors occur then refreshrates is then needed to handle breakdown/slowdown in client - server comunication errors.

Stratergy for coping with communcation breakdown situation needs to be defined and coded. IMHO

 
Yep, it should be :) but this doesnt mean that throwing RefreshRates throughout your code will help you in doing that. It will actually do the opposite. To many of ANY calls is a performace hit.
 
forexCoder:
If I understood correctly, he meant that RefreshRates() changes and updates the Close[0] to the last known price. You want to say that it doesn't?

Close[0] IS the last know price and refresh will do nothing, UNLESS, there's a server call (takes time) or long calculation, or non-returning EA (i.e. Sleep), etc.

Ticks come in (EURUSD) about 100/min or less. That's one per 50 milliseconds. Most codes will evaluate and return in sub-millisecond time. Nothing is changing.

Reason: