From where this code is run ? (from which event handle). What is the initial value of volume and where it is in the code ?
Beside that, you should not rely that the last deal by index is the last deal out.
It runs in OnTick function. the initial value of volume is 0.01 it is global variable declared on top
Alain Verleyen #:
It changes nothing, You are right it is useless. what I am trying to do is that I declare static variable volume, this function runs in the OnTick function, and when the condition is true, it continues increasing volume to infinite. I need to modify it so that the action happens only once before for example ticket number is the same, but after the ticket number changes, it will increase only once and not unlimited time.
I don't need any info, I'm trying to make you think about your code.
What are you thinking this code is doing ?
I got the answer. Can you delete this post? Thanks!
Alain Verleyen #:
There is no reason to delete it and if you have an answer you should provide it.
A forum is not a place to get personal help and then delete it, it's a place to share.
I modified only this:
if(lastDealProfit < 0) { if(lastdealticket != historyDealTicket) // in where the lastdealticket is a static variable { volume = volume * RR; lastdealticket = historyDealTicket; }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello.
There is a simple code. The idea is next, trading volume will increase after there was a losing trade to recover losses.
What I am trying to do is that if for example trading volume was 0.01 and there was a loss trade, it becomes 0.02 and resets once there is a winning trade.
The problem is that instead of 0.01, 0.02, 0.04, 0.08, etc. after a series of loss trades, it just stays at 0.02. its value changes only once.
Can someone explain how to retain the changed value?