[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 18

 
artmedia70:

A similar question has been asked and answered here before (I don't remember who answered it). So that you don't have to look it up, here it is:

-----------------------------------------
How do I calculate, based on available funds and lot, how many points (in points) the price can go negative???
link formula: Lot=Money/(Staples*Tick)
Money - earned/lost
Stoplos - broker's pips
Tick - MarketInfo( MODE_TICKVALUE)
From here, twist as you wish:
Stopplus=Money/(Lot*Tick)
Money=Lot*Stopplus*Tick
-----------------------------------------
Now, based on the above formulas, do what you need...




Thank you. I'll be pondering. More options would be welcome
 
vovan-gogan:

Thank you. I'll be pondering. More options would be welcome

1. The risk per trade was 10 per cent of the deposit,

2. That the 10 percent would fall within the distance of the SL

3. these 10% should be increased by 50% each time a trade is loss making.

For example the deposit is 10,000 USD, the risk for a trade with a certain known SL must be 1,000 USD. If the trade is loss-making, then the next trade must risk 1500, the next 2000, etc. And on the first profitable trade the risk immediately returns to the initial level of the deposit: 10%. How it can be implemented in the program?

We know all three components of the three you need. Now just do the maths and check for admissibility.

1. Do we know the deposit? You can calculate the risk in money: Depo/100*Risk Percentage. Tick is taken from here: Tick = MarketInfo(Symbol(), MODE_TICKVALUE); Stop Loss is known to us.

2) Lot to open position = Risk in money / (Stop Loss in pips * Tick)

3. If you want to increase the risk, recalculate the Risk in money (third point above) by the increased risk percentage...

 
DDFedor:

1. We know that the examples lie in the codebase.

2. We know that library file extension is mqh.

3. Combine, do a search engine query.

4. We get the first result. https://www.mql5.com/ru/code/10344 - I haven't looked through the archive, but for sure there is a library file and a startup file.

Probably the extension of all MQL4 programs is "*.mq4".

"*.mqh" is an extension to the header file of the library, similar to C++. None of this matters, though. "*.mqh" compiles as well.

 
Good evening. Can you tell me if a number of int type is initially 0?
 

Can you please advise me at some point to enable stop loss in my EA, which is located in the middle between the current price and the open price

middleSL=OrderOpenPrice()+(Close[0]-OrderOpenPrice())/MIDDLESL;
When the price goes up, it pulls up, but never down

I saw that close[0] which ends on an even number and Close[0]-1*Point(odd), in the formula, produce the same middleSL, and include the same command to OrderModify, what should I do in the code to avoid this happening, thank you.

P.S. MIDDLESL is a variable, now it is 2, but with the help of optimizer, will find a more favorable value

 
nadya:
good evening. can you tell me if a number of int type is initially 0?

Yes, when you define a variable as an integer, it initially has the value 0
 
Thank you, Denis!
 
nadya:
good evening. can you tell me if an int type number initially equals 0?

A strange assumption and an equally strange answer.

In general this is always the case, but there are damaging moments when variables are not zeroed out.

anecdote to that effect:

A programmer goes home sad and things are not going well at work. He decided to have a drink in a bar on the way. He's sitting there all sad, drinking, thinking about the code that doesn't work. A local hooker sits down with him. Tries to start a conversation. He's sluggishly talking. Then he asks her:
- What's your name?
- Whoever wants to call you, calls you what he wants to call you.
The programmer (patting himself on the forehead):
- That's right! The default value should be given!!!
And happily ran home to finish the code.

Moral - always initialize variables with a value!

 
LazarevDenis:

Can you please advise me at some point to enable stop loss in my EA, which is located in the middle between the current price and the open price

When the price goes up, it pulls up, but never down

I saw that close[0] which ends on an even number and Close[0]-1*Point(odd), in the formula, produce the same middleSL, and include the same command to OrderModify, what should I do in the code to avoid this happening, thank you.

P.S. MIDDLESL is a variable, now it is 2, but with the help of optimizer, will find a more favorable value

When middleSL is sent to the stop loss it is normalized, i.e. it is rounded to a certain sign, when divided by 2 this will happen, it is inevitable
 
sergeev:

A strange assumption and an equally strange answer.

In general this is always the case, but there are damaging moments when variables are not reset to zero.

A related anecdote:

The programmer goes home sad, something is not going well at work. On the way he decided to have a drink in a bar. He's sitting there all sad, drinking, thinking about the code that doesn't work. A local hooker sits down with him. Tries to start a conversation. He's stalling. Then asks her:
- What's your name?
- Whoever wants to call you, calls you what he wants to call you.
Programmer (patting himself on the forehead):
- That's right! The default value must be given!!!
And happily ran home to finish the code.

Moral - always initialize variables with a value!

and if I write it as a global variable, do I assign the value directly there?
Reason: