[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 228

 
artmedia70:

It all depends on whether this variable is available to all EA functions (well... not all, but some for sure). Then the variable is global.

If it is used only in one function, then it is local.

The question is like "which water to put the flowers in, plain or sweetened water" ... While you were guessing, the flowers became a broom... :))

:о)

I kind of figured those rules out, but in practice my orders didn't work, so while I was looking for the problem, I tried a lot of variants and moved variables to global, like statics, but it all worked, even though I've got one function. Although I'm still not sure if that was the reason. I am confused and decided to ask here. You didn't say anything about statics variables. Maybe we should make them like that? I do not understand, when you reenter the start (on a tick, for example) variables are reset? And statics don't? If so, do My ticks become zero?

PS Damn, started programming closely, I'm writing a grail....., if there's enough grass...., it looks like I'm a regular here now :))

 
drknn:
If your brokerage company has floating spreads, then it is better to use the auto-determination of spread size in the EA's Start function and set the slippage at three spreads, for example. Then the slippage will become dynamically changing.
That is a great idea, I should give it a try. Thank you.
 
artmedia70:
Try making the slippage dependent on volatility first. In a calm market it will be minimal, in a fast market it will spread wider.

I'm afraid when working on H1 it will be difficult to calculate volatility for a single candle, you need to think about how to calculate it.
 
Fam:

:о)

This theory I kind of understood, but in practice my orders didn't work and while searching for the problem, I tried a lot of variants and moved variables to global as static, but it all worked, although the function is the same. Although I'm still not sure if that was the reason. I am confused and decided to ask here. You didn't say anything about statics variables. Maybe we should make them like that? I do not understand, when you reenter the start (on a tick, for example) variables are reset? And statics don't? If so, do My ticks become zero?

PS Damn, started programming closely, I'm writing the grail....., if the grass is enough...., it seems, I'm a regular here now :))


A local variable is a variable declared inside any function. The scope of local variables is the body of the function in which the variable is declared. A local variable can be initialized with a constant or an expression, corresponding to its type.

A global variable is a variable declared outside all functions. The scope of global variables is the entire program. A global variable is not localized at any level. A global variable can be initialized only by a constant corresponding to its type (but not by an expression). Global variables are initialisedonly once before special functions are executed.

If control in a program is inside a function, the values of local variables declared in another function are not available. The value of any global variable is available from any special and user functions.

Static variable

On the physical level, local variables are represented in the temporary memory area of the respective function. There is a way to locate a variable declared within a function in the permanent memory of the program. To do this, when declaring a variable, the modifier static must be specified before the variable type:

Static variables are initialised only once. Each static variable can be initialised with a constant corresponding to its type (unlike a simple local variable, which can be initialised with any expression). If there is no explicit initialisation, a static variable is initialised with zero. Static variables are stored in a permanent area of program memory andtheir values are not lost when the function is ex ited. At the same time, static variables have a limitation inherent to local variables - the scope of a static variable remains the function within which this variable is declared, unlike global variables whose values are accessible from any place in the program.

https://book.mql4.com/ru/variables/types

 
It's all sort of self-explanatory. It turns out, if a static variable is invented, which values are not lost when the function exits, then all other variables we lose values on every tick? (if START is called on every tick)
 
Fam:
It's all kind of clear. It turns out that if we invent a static variable, whose values are not lost on exit from the function, then all the other variables lose their values on every tick? (if START is called on every tick)

Local variables are re-initialised on every tick.

Don't bother - use global to store tickets and forget it. Or make an array (order accounting). All arrays are static by default.

 
Thank you, I did. Just want to know the bottom line. Do you know how to achieve High simulation quality and low chart mismatch? It feels like it's not up to me or the program, but bad weather (or good, need to figure it out). How can the software not simulate well, I don't understand, the "human" factor?
 
ZZZEROXXX:

I'm afraid when working on H1 it will be difficult to calculate volatility for a single candle, we need to think about how to calculate it.
The average amplitude over 18 bars is clear
 

Hi all!

Can you please help me with this question?

I'm trying to get the exact value of opening(Open[i]) or closing(Close[i]) of EURUSD currency pair with five-digit value after zero, but in response I always get rounded value!

 
rounded to how many numbers after zero? If the numbers after zero are removed at all, you are trying to assign a price value to an integer variable, double is needed.
Reason: