Comprehensive lot size calculation function for mql4

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
313
JD4 2015.06.28 19:13 #
 
strontiumDog:

Thirteen, I put in your fractional lot size function and now my functions are coming out as (eg) 337.01 instead of 0.337.  Can you tell me why this might be please?
Not sure where in your code this is happening, as I am still trying to wrap my mind around MQL4 programming.  What programming knowledge I have is from Java, not C++, but judging by this post, your decimal place got skewed by 3 places (1 thousand multiplied in there somewhere, somehow).  The point that this miscalculation is not popping out to me from your code.
avatar
4
pt007 2015.09.02 11:31 #
 
strontiumDog:

Thirteen, thanks for your input.


I varied my calculation due to http://www.babypips.com/school/undergraduate/senior-year/position-sizing/calculating-position-sizes.html which suggests different calculations based on different scenarios. I've been hacking around with mql4 for a few months now, but it sounds from your post that there is a way to get round these differences.  Surely having different ways of calculating lot size mentioned on the above URL, I need to represent this in code? 

Good point about rounding down - I should be doing that.  Also good point about maxlot, which I need to change.  I also see in your code about the SL calc as an amount rather than a number of pips.  Cheers


What do you think about WHRoeder's modification of your code in his most recent post?  That's quite a significant difference.

strontiumDog, how did your code work out? I'm struggling with similar code and have been surprised how little discussion there is on the correct coding of this. The position size calculator code out there don't take into account the base currency and also how spread affects R/R and lot size (in low time frames).

Can you share your finished code? My code has got too knotted, so I'm going to start with yours again!



avatar
4
pt007 2015.09.02 11:43 #
 
pt007:

strontiumDog, how did your code work out? I'm struggling with similar code and have been surprised how little discussion there is on the correct coding of this. The position size calculator code out there don't take into account the base currency and also how spread affects R/R and lot size (in low time frames).

Can you share your finished code? My code has got too knotted, so I'm going to start with yours again!



I just worked out that...

   double UnitCost = MarketInfo(Symbol(), MODE_TICKVALUE);

is the tick value in the deposit currency. So that's how we don't need to do the extra base currency conversion. I simply do all the calculations in the deposit currency!

Back to topics list   | 1 2  

To add comments, please log in or register