![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
I have tried that...
Lots are 0.58
Current Order selected is GBPUSD
Lot step is: 0.01
SecondTarget_Buy: 1.34584 & yen prices!
FirstTarget_Buy: 1.34254 & yen prices!
Because even if I had the lots right, it wouldn't be able to close at the right price anyway... I cannot figure out why the lots calculation is returning 0.00000.... I am printing everything, but nothing is staring back at me telling where I am going wrong....?
This thread is about the error 4051 and the lots calculation, lets stay on topic and resolve one issue at a time.
Are you printing everything ? all the steps in the calculation ? all the variables ? Can you copy/paste the prints here please . .
Right, so basically I was playing around with it earlier, and accidently changed some of the code so it ended up closing out multiple halves consecutively... so a little frustrated - It's only a demo account, and I kind of needed to play with it there and then anyway... it's hard to replicate this situation....
So... Now the lot sizing of GBPUSD is 0.03... and the Lots to close is actually 0.03000 now... The code is precisely the same as the one I originally posted.
Print the variable Second_Target. RaptorUK asked you to print ALL the variables
and all the steps in the formula . . .
and all the steps in the formula . . .
All the steps in the formula are printed out... would it make much difference printing out the formula... after-all, you can see the parts I am using? (I have updated the prints above...)
Oh and its now saying lots to close is "0.00000" ...
All the steps in the formula are printed out... would it make much difference printing out the formula... after-all, you can see the parts I am using? (I have updated the prints above...)
Oh and its now saying lots to close is "0.00000" ...
If you have all the information printed then you can see what is wrong . . . you haven't printed all the information I asked for so I can't see what is wrong. You have all the info you need so fix your code or ID a bug, produce a script/indicator to demonstrate the issue and report it to the Service Desk.
Perhaps you can explain something, I always have trouble understanding. You ask for help, I try and help, I ask you to do something to helps identify the issue but you are reluctant to do it . . . what is your motivation to hinder the people you are asking to help you ? why do you want to make it harder for people ? perhaps you don't see the point of what I asked for . . . .
Break it down, print each step, find what is going wrong . . . there is always an explanation. For example . . .
etc, print every variable and each part of the workings in the Target_2 calculation so you can see where it is going wrong . . .
I'm not 100% certain what the variables are in your print above, I assume OrderLots() is 0.03, Seond_Target is 4 so OrderLots()/Second target = 0.03/4 = 0.0075 and this, 0.0075/0.01 = 0.75 this rounded down to the nearest integer is 0 so your code is doing what it should. Perhaps it is not doing what you wanted but that is a different issue . . .
If you want to be able to divide your position size by 4 it must be at least 4 times the lotstep and probably 4 times the min lot . . . so when you start out with 3 times the lotstep you are obviously going to have issues.
In connection to your last line above^ - Why would it not close out the correct lot sizing when my lots open were 0.58...? Also, if I had 0.03 lots open, and I am trying to divide by 4, is there a way to create a formula so that it closes the closest plausible lot value ? I.e. rounding it up?