Position Size Calculation
31 replies
ssdex
8 years ago #113883
Hello,
I’m trying to figure out how to create a variable to calculate position size.
Example:
Create a variable for risk size
Assign that variable to the quantity for the trade
The problem I’m having is the SL on the trade is calculated, not a hard set number. So, the SL is calculated from the open price to the swing high or low depending on the direction of the trade.
Is there a way to create a variable that would calculate the position size before the trade is opened? This doesn’t seem possible.
ssdex
8 years ago #132495
Hello,
I’m trying to use a multiplier as a “Variable” to my trade size. Does anyone know if the multiplier needs to be a “Double” or should/can it be an “Integer”? Also, what would the difference be if using a Double instead of an Integer?
Thanks.
Regards,
James
seaton
8 years ago #132496
Double will give you more fine grain e.g. 1.25 or 1.75 as opposed to only 1 or 2
I’d go with double in this case
ssdex
8 years ago #132497
Thanks Seaton,
I’m wondering if you could answer another question I have. I’m calculating Pip Value and I don’t see a way to do that with cross rates. Since the account is in USD and calculating the Pip Value with let’s say the EURGBP is would then need to call on the current rate of the USD to get the correct lot size for the trade. Am I thinking right? If so, do you know how this can be done?
Thanks again for your help.
Regards,
James
seaton
8 years ago #132498
I haven’t done this with EA Wizard, but here a code snippet for MT4, MarketInfo should be returning values in deposit currency
double PipValue=(((MarketInfo(Symbol(),MODE_TICKVALUE)*point)/MarketInfo(Symbol(),MODE_TICKSIZE))*LotSize); double PointValue=PipValue/10;
ssdex
8 years ago #132521
Thanks again Seaton. This will help tremendously (if I figure out how to use it). LOL
Regards,
James
ssdex
8 years ago #132876
Thanks again seaton,
I was wondering if you could shed some light on the formula above. Could is use this calculation for calculating Direct Rate, Indirect Rate and Cross Rate pairs?
Or is this only for Cross Rate pairs?
Thanks.
Regards,
James
ssdex
8 years ago #133025
I haven’t done this with EA Wizard, but here a code snippet for MT4, MarketInfo should be returning values in deposit currency
double PipValue=(((MarketInfo(Symbol(),MODE_TICKVALUE)*point)/MarketInfo(Symbol(),MODE_TICKSIZE))*LotSize); double PointValue=PipValue/10;I just had a quick look at EA Wizard and some of the functionality is not implemented, so your best bet is to copy and paste the above into a custom function.
Hello seaton,
I hope you had a great weekend. I’m trying to figure out how to use the above piece of code to get the PipValue for the different rates. I’m getting a couple errors in the MetaEditor (see attached image).
I’m not sure if I need to create a variable for those or not. Or maybe I’m not using it correctly.
Any help would be very appreciated. Thanks for your time and expertise.
Regards,
James
PS-Forgot to upload the screenshot.
seaton
8 years ago #133044
Hi sorry for my late reply I’m currently away so will look at when I get back home next week
tomas262
8 years ago #133058
ssdex, compiler does not know what ‘LotSize’ and ‘Point’ mean, you need to declare those variables in the beginning of your script. Here is the example on how to define a variable http://docs.mql4.com/basis/variables
ssdex
8 years ago #133067
Thanks Tomas262
I declared the variable but I’m not sure if I would need to set the variable to =0 or to something else. I’ll keep messing around and see what I can figure out. Thanks again.
Regards,
James
ssdex
8 years ago #134129
Hello seaton,
Thanks again for the snippet of code above. I have learned a lot from this forum and you guys who help us all out.
I have a Variable that is (PipValue) and all I need to do is assign that to equal the CustomFunction (PipValue)? See screenshot.
If:
CrossRate is True
Then:
AssignVariable: CustomFunction: PipValue=PipValue
Thanks again for all you do here on this forum.
Regards,
James
ssdex
7 years ago #139442
Hello,
Well, I’m back to trying to figure out some position size calculation. I have the EA set on MM risking a set percentage (variable). As I understand if the percentage is set to 0 (zero) it will default to (LotsIfNoMM). I’m looking to have a set $dollar amount for the risk if the percentage option is set to zero.
I have created a few variables:
stop_in_pips
lots_to-trade
I think I got the calculations correct but it seems that no matter what $dollar size I input it always returns a lot size of .01
If anyone can shed a little light on what I’ve got wrong I would be extremely grateful.
Regards,
James
tomas262
7 years ago #139450
Hello,
I see no problem there. Can you upload your project? You can delete all the trading condition not to disclose your system.
Also you can use “Log to Journal” function to write variable values into MT Journal to see their values when the system is running
ssdex
7 years ago #139453
Thanks Tomas,
It’s just a test strategy. I attached what I have so far. Trying to figure out this money thing. I thought I had it but it seems that there is something wrong somewhere. I put some log to journal and it didn’t log anything. I could have got that wrong as well. LOL
Let me know what you think is the problem. Thank you for your time. I have a question regarding the SQ. Can we load a strategy we build in EA Wizard and have it retest and optimize in the SQ software?
Thanks again.
Regards,
James
tomas262
7 years ago #139457
Hello,
you should not use “predefined MM” if you calculate your size manually. Predefined means it follow its own inner rules to compute the size.
Also make sure your broker supports micro-lots otherwise you will need to use MathRound(lots_to_trade, 1)
Yes, new SQ4 will have Wizard included so you will be able to use, test and optimize your own rules