Correction of lot size
-
Please help me .In grid trading when trades executed with lot size first trade 0.1,second trade 0.2,third trade 0.3 .Then if due to elctricity failour system closes and then start again robot starts but now instead next trade should have lot size 0.4 robot start executes 0.1 again .Please help me how I can remove this so that robot will start next trade of lot size 0.4. thanks
-
couple of choices, save as a terminal variable, or get the last value from the last trade. But both of these have there own nuances, terminal (global) is most similar to a normal variable but is saved on your computer so does not delete on power cut.
-
Just curious. How will the bot know that it needs to take the terminal variable value after the power cut? How can the EA know that was the reason and not just the bot being removed from the chart?
-
I t will always use it if that is used, you may need other blocks that reset this value at times, but this is a strategy specific setup.
-
@iftikhar123ali If your sequence is adding 0.1 every time, maybe try Martingale in the settings. I know Martingale sounds scary and not what you describe, but I added so much settings over there that you can change the behavior completely.
Otherwise, when we base our next lot size on the previous one, it's always better to get the information from the trades directly. Get the lot size of the last trade, calculate the lot size of the next and so on. So, if MetaTrader restarts for whatever reason, we are fine, we know what the last lot size was and we can continue.
But there is an issue here. How do we know if we are in the middle of the sequence, or we want to start with the initial lot? Well, it depends. Maybe the value of the last lot size can tell us that. If we want to have a sequence of 0.1 - 0.2 - 0.3 - 0.4 and then start over, then if the last lot size is 0.4, it's obvious that it's time to reset and start with 0.1 again. If we cannot use the lot sizes, then the next best would be to use the comment property of the trades... although you really have to double check if whatever information you put there, stays there. Or those Terminal (Global) Variables, but I'm not sure if they work properly in case of electricity failure. One more way of storing data I can think of is some object on the chart... and again, I'm not sure if they stay on the chart on energy failure. -
@l-andorrà Global Variables (of the Terminal) are stored in a file called gvariables.dat for persistence. But MetaTrader updates this file when it closes normally. I just tried it. I added a new variable, hard-reset the computer, opened MetaTrader again... new variable gone. The same with objects on the chart.
-
Interesting, a hard reset must change the folder value. Previously I use this and it works, a computer though is not a battery backed up laptop, so this may be what saves the value from being deleted.
-
you have to read last opened position and then add your marti or add lot value
-
Very interesting info! Thank you.
