Dynamic Lot Amount Variable question

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Dynamic Lot Amount Variable question

Postby tjohnsonfx » Thu Jun 13, 2013 9:32 am

Hello,

I am trying to find code that will allow my strategy to determine the amount of mini lots it is able to use to open a position, based off a user defined MMR (balance/MMR). I am thinking something like LotAmount = (balance/MMR) And have this update with each period. Also, how important is it to have the LotAmount variable be a Double rather than an integer? Will order entry look at the integer value and truncate it to a whole number? Or will it not even recognize it? If it is important how can I convert a integer to a double? Can anyone provide any input to any of these questions for me? Any help would be appreciated.

Thanks,
tjohnsonfx
 
Posts: 4
Joined: Wed May 08, 2013 12:48 am

Re: Dynamic Lot Amount Variable question

Postby Victor.Tereschenko » Fri Jun 14, 2013 5:57 am

tjohnsonfx wrote:Hello,

I am trying to find code that will allow my strategy to determine the amount of mini lots it is able to use to open a position, based off a user defined MMR (balance/MMR). I am thinking something like LotAmount = (balance/MMR) And have this update with each period. Also, how important is it to have the LotAmount variable be a Double rather than an integer? Will order entry look at the integer value and truncate it to a whole number? Or will it not even recognize it? If it is important how can I convert a integer to a double? Can anyone provide any input to any of these questions for me? Any help would be appreciated.

Thanks,

Code: Select all
        local emr = core.host:execute("getTradingProperty", "EMR", instrument, account_id);
        local account = core.host:findTable("accounts"):find("AccountID", account_id);
        local lots = math.floor(account.UsableMargin / emr);
        local max_amount = math.max(1, lots) * base_unit_size;
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 144
Joined: Fri Nov 19, 2010 8:55 am

Re: Dynamic Lot Amount Variable question

Postby tjohnsonfx » Thu Jul 04, 2013 12:00 pm

Thanks Victor, this worked. Although I did not use the "max amount" code, can you tell me what this part of the code was intended for?
tjohnsonfx
 
Posts: 4
Joined: Wed May 08, 2013 12:48 am

Re: Dynamic Lot Amount Variable question

Postby Victor.Tereschenko » Thu Jul 04, 2013 10:03 pm

I have forgot to remove the max (copied from one of my strategies).
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 144
Joined: Fri Nov 19, 2010 8:55 am

Re: Dynamic Lot Amount Variable question

Postby datasos » Tue Nov 21, 2023 3:51 pm

Similar but different :)

for example, I am ready to use 10% of the usable margin at the time of opening the position. if 10% = $100 and the MMR of that instrument is 5, that means I will open 50/5 = 10 lots. If the position was profitable +7$, the next position that is opened automatically is calculated 57/5 = 11.xx ie 11. etc.

These numbers are just for clarity. if possible, an example that I can use. tnx ;)
datasos
 
Posts: 5
Joined: Wed Sep 01, 2010 5:22 pm


Return to Discussions

Who is online

Users browsing this forum: No registered users and 15 guests