Error 4051 (Code Pasted) - Lots that are not divisible? - page 2

 
DomGilberto:

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!

Why are you talking about SecondTarget_Buy ? it isn't involved in the lots calculation . . .
 
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....?
 
When I am trying to do the calculations on "OrderLots()" it could technically pull any order lot value from any open position at that point, because I have not selected any specific order within the void (see original post)... therefore, I would need to select the correct order before assuming that the double variables that I've assigned to the equations correspond to GBPUSD....?
 
DomGilberto:
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 . .

 
Yea, ok :)

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.

2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lots for: GBPUSD are: 0.03
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lots to close is: 0.03000
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lotstep is: 0.01000
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The minimum lots are: 0.01000
2013.09.19 23:00:16	Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lots to close is: 0.00000 The Second_Target is: 4.00000
 
DomGilberto: "double Target_2 = MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;" ----- See code below with arrows.
Print the variable Second_Target. RaptorUK asked you to print ALL the variables
 
WHRoeder:
Print the variable Second_Target. RaptorUK asked you to print ALL the variables

and all the steps in the formula . . .

 
RaptorUK:

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" ...

 
DomGilberto:


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 . . .

Print("OrderLots(): ", OrderLots(), " Second_Target: ", Second_Target, " Lots/target: ", OrderLots() / Second_Target );

double Target_2 = MathFloor( ( OrderLots() / Second_Target ) / lotStep) * lotStep; 

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.

 
Hey, you're right, sorry for being vague! I will try to be a lot more specific from now on when asking for help. Here are some prints:

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?
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lots for: GBPUSD are: 0.03
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lots to close is: 0.03000
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lotstep is: 0.01000
2013.09.19 21:15:09     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The minimum lots are: 0.01000
2013.09.19 23:00:16     Trend Fishing - ATR Clean V_2 GBPUSD,H1: The Lots to close is: 0.00000 The Second_Target is: 4.00000
2013.09.20 12:00:24     Trend Fishing - ATR Clean V_2 GBPUSD,H1: Formula for Target_2: ((0.03/4.00000)/0.01000)*0.01000

double Target_2 = MathFloor( ( OrderLots() / Second_Target ) / lotStep) * lotStep; 
Reason: