You only need the "::" if you have local variables of the same name.
The global variable "VL" does not exist.
You are updating the global variable "VOL", but you are using the variable "buyorderVL" when placing the trade.
Updating "VOL" will not automatically update " buyorderVL" just because you initially set it to "VOL".
Your function is called "VOLdoubling", but you are calling "LOTdoubling" in the OnTick() event handler.
There is no need to normalise a given price quote. Ask, Bid and other price quote data are already normalised.
In fact, you should avoid using NormalizeDouble() when calculating prices and instead properly adjust price calculations based on tick size instead.
You should also be adjusting your volume lots, based on the contract specifications of volume minimum, maximum and step size.
Obviously, that is not your proper code. The code you posted is incomplete and cannot be compiled and tested. If you are serious about getting help, then post your proper code.
PS! And please learn to format/style your code properly or use the "Styler" in MetaEditor.
Sorry for the mistake, here is all of my code. Still it is not changing the value of global variable "VL". Even though the function LOTdoubling is called before making any trades.
35117153: Sorry for the mistake, here is all of my code. Still it is not changing the value of global variable "VL". Even though the function LOTdoubling is called before making any trades.
You did not correct the mistakes I pointed before. Pay attention next time please, or I will not help any further.
Here are the primary points that you will need to fix first:
You only need the "::" if you have local variables of the same name.
You are updating the global variable "VL", but you are using the global variables "buyorderVL"/"sellorderVL" when placing the trade.
Updating "VL" will NOT automatically update "buyorderVL"/"sellorderVL" just because you initially set it to "VL".
Learn to format/style your code properly or use the "Styler" in MetaEditor.
Fix the above points first and re-post your new code.
Here is a second list of points that you will also need to fix going forward:
There is no need to normalise a given price quote. Ask, Bid and other price quote data are already normalised.
In fact, you should avoid using NormalizeDouble() when calculating prices and instead properly adjust price calculations based on tick size instead.
You should also be adjusting your volume lots, based on the contract specifications of volume minimum, maximum and step size.
Fix them as well.
Below is a possible solution, but maybe not, because I do not know what you want to achieve. You have not explained it, so I just made some assumptions.
I only fixed some of the points. The rest is up to you.
You did not correct the mistakes I pointed before. Pay attention next time please, or I will not help any further.
Here are the primary points that you will need to fix first:
You only need the "::" if you have local variables of the same name.
You are updating the global variable "VL", but you are using the global variables "buyorderVL"/"sellorderVL" when placing the trade.
Updating "VL" will NOT automatically update "buyorderVL"/"sellorderVL" just because you initially set it to "VL".
Learn to format/style your code properly or use the "Styler" in MetaEditor.
Fix the above points first and re-post your new code.
Here is a second list of points that you will also need to fix going forward:
There is no need to normalise a given price quote. Ask, Bid and other price quote data are already normalised.
In fact, you should avoid using NormalizeDouble() when calculating prices and instead properly adjust price calculations based on tick size instead.
You should also be adjusting your volume lots, based on the contract specifications of volume minimum, maximum and step size.
Fix them as well.
Below is a possible solution, but maybe not, because I do not know what you want to achieve. You have not explained it, so I just made some assumptions.
I only fixed some of the points. The rest is up to you.
Thank you for your help and patience. The main issue was your 3rd point which is now fixed. The trade volumes are now being changed, but not as I desired.
What I want to achieve is to multiply the volume (VL) by "x" and for the while loop to add +1 to "x" for each time the balance increases by 10000 and thus also automatically decreasing the multiplication of "VL" from 3 to 2 if the balance falls from say 30000 to 28000.
The following function is to be called before making each trade but in this "x" seems to get very large values of above 36000, I do not understand how this is happening.
Thank you for your help and patience. The main issue was your 3rd point which is now fixed. The trade volumes are now being changed, but not as I desired.
What I want to achieve is to multiply the volume (VL) by "x" and for the while loop to add +1 to "x" for each time the balance increases by 10000 and thus also automatically decreasing the multiplication of "VL" from 3 to 2 if the balance falls from say 30000 to 28000.
The following function is to be called before making each trade but in this "x" seems to get very large values of above 36000, I do not understand how this is happening.
That is because you are multiplying on every single loop iteration. You probably want the following:
Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk. Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.
You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
PS! And please learn to format/style your code properly or use the "Styler" in MetaEditor.
Sorry for the mistake, here is all of my code. Still it is not changing the value of global variable "VL". Even though the function LOTdoubling is called before making any trades.
You did not correct the mistakes I pointed before. Pay attention next time please, or I will not help any further.
Below is a possible solution, but maybe not, because I do not know what you want to achieve. You have not explained it, so I just made some assumptions.
I only fixed some of the points. The rest is up to you.
You did not correct the mistakes I pointed before. Pay attention next time please, or I will not help any further.
Below is a possible solution, but maybe not, because I do not know what you want to achieve. You have not explained it, so I just made some assumptions.
I only fixed some of the points. The rest is up to you.
Thank you for your help and patience. The main issue was your 3rd point which is now fixed. The trade volumes are now being changed, but not as I desired.
What I want to achieve is to multiply the volume (VL) by "x" and for the while loop to add +1 to "x" for each time the balance increases by 10000 and thus also automatically decreasing the multiplication of "VL" from 3 to 2 if the balance falls from say 30000 to 28000.
The following function is to be called before making each trade but in this "x" seems to get very large values of above 36000, I do not understand how this is happening.
Thank you for your help and patience. The main issue was your 3rd point which is now fixed. The trade volumes are now being changed, but not as I desired.
What I want to achieve is to multiply the volume (VL) by "x" and for the while loop to add +1 to "x" for each time the balance increases by 10000 and thus also automatically decreasing the multiplication of "VL" from 3 to 2 if the balance falls from say 30000 to 28000.
The following function is to be called before making each trade but in this "x" seems to get very large values of above 36000, I do not understand how this is happening.
That is because you are multiplying on every single loop iteration. You probably want the following:
Which can be rewritten as follows:
However, this can be simplified and made more efficient as follows:
You should however, be checking for the contract conditions for volume:
However, this is all wrong and dangerous for your account. Learn to properly calculate risk and volume:
That is because you are multiplying on every single loop iteration. You probably want the following:
Which can be rewritten as follows:
However, this can be simplified and made more efficient as follows:
Everything is working as expected now. I thank you sincerely for the help