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

 
DomGilberto:
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?
I don't know why it appears not to have worked for 0.58 lots . . . you need all the variables and calculation steps for that lot value to understand what is going on, add the prints, run it in the Strategy Tester, find a lots value of 0.58 and look at the other variables and calculation steps to understand what is wrong . . . if you don't have the values of the variables at the time you can't understand what is going on, you can guess, maybe.

Of course there are many ways to handle 0.3 lots, but you are the best person to understand your strategy and what fits best within the strategy, coding comes later . . . figure out what you want to do to handle this instance that will also work with all other scenarios . . . think about it some more to make sure you haven't missed something . . . then, eventually, code it.
 

Ok cool.

I already know exactly what I want in terms of how the positioning should be closed. Problem is, I do not know how to write the code. Here's an example:

Lots: 0.33

First target (1:1): 0.33 / 4 = 0.0825 -- Does my code round that to 0.08?

Second Target(2:1): 0.25 / 1.5 = 0.166666... --- Again, will this close 0.16?

Third Exit (Close below EMA): 0.09 / 2 = 0.045 --- Close 0.04?

Rest closes out from a trailing stop... assuming these positions closed in consecutive order. The areas in bold are user defined.

The question is, the formula "double Target_2 = MathFloor( ( OrderLots() / Second_Target ) / lotStep) * lotStep;" from the first page, does this technically work on numbers like I have mentioned in the example above?

   double minLot=MarketInfo(Symbol(),MODE_MINLOT); <<<< 0.01
    //Print("The minimum lots are: ",DoubleToStr(minLot,Digits));
   double lotStep=MarketInfo(Symbol(),MODE_LOTSTEP);  <<<<<< 0.01
    //Print("The Lotstep is: ",DoubleToStr(lotStep,Digits));
   double Target_2 = MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;    <<<<<<------ "Second_Target" is "4" in the global area. 
    //Print("The Lots to close is: ",DoubleToStr(Target_2,Digits));

 
Assuming that the code above was functioning as it should, would it be able to work with numbers to the decimal place like the example above? Or do I need to write it another way?
 
Any suggestions?
Reason: