Viewing 15 posts - 1 through 15 (of 32 total)
• #113883 |
Customer
87 Posts

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.

#131107
Customer
484 Posts

The SL has its own separate rule, and is placed after the trade is opened, correct?

#131115
Customer
87 Posts

Thanks for the reply Threshold.

Yes, at this time. The reason is that I have options to turn on a dynamic SL or to use a static SL. I’m thinking I could put these both into a rule then assign a variable then put the variable into the SL on the entry order.

Do you have any experience with doing something like this?

Regards,

James

#131116
Customer
484 Posts

I’ve run into the same problem before. I’d like to know a money management solution to stop losses placed after a trade is opened as well.

#131121
Moderator
1559 Posts

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.

Based on what rules do you want to calculate your position size?

To adjust SL you could use ‘Move SL To’ to move stop-loss anytime after your entry. Is that what you meant?

#131122
Customer
87 Posts

I’m not sure it is possible since I have an option for either use a static SL or the last swing HL. Currently I have the static set as variables and those set in the entry order. If they are set to zero(0) and the “swingHL” boolean is “true” then the SL is a rule of its own and gets applied after the order is taken.

If I remove the static option then I can use the stop loss as a formula in the order entry. I’m trying to keep the options available.

I wanted to have the trade to risk a specific dollar amount or a percentage of the account. With the options it doesn’t seem possible (how I’m thinking of the order).

I’m a little stuck at the moment. Thanks for any help.

Regards,

James

#131134
Moderator
1559 Posts

I am not sure I understand correctly.

If you get a trade signal (trigger) you can determine distance between bar close / next bar open and the last swing low before entering a trade. So you know (and you should always know before you enter a trade) how far your stop-loss will be placed. Since you know the distance and the amount of money you want to risk (let’s say maximum risk is 3% of your account balance) you can get position size calculated just before entering the trade like this:

Position Size = Account Balance * 0.03 / Calculated stop Loss (in money)

Now you can create order with that calculated position size and set calculated stop-loss for the order which will be placed below swing lows.

#131211
Customer
87 Posts

Thanks Tomas262.

The problem is I have multiple options for SL. I figured out that I can create a SL variable and then call on the SL options. This should work.

#131268
Customer
87 Posts

I’ve changed the options for the SL input so now it works well.

I’m having an issue though figuring out how to calculate the LotSize from a fixed dollar amount. It seems that I will need to create a variable that will do the calculation depending on tick size (.0001 or .001). Do any of you know if my thinking is correct? Of am I over thinking this and there is an easy way to calculate lot size from a fixed dollar amount risked.

Example: USD based pairs

Risk: \$10

SL: 20 pips

Lot Size: 0.5

My belief is that “Indirect Rates” and “Cross Rates” will be different.

Regards,

James

#132220
Customer
87 Posts

I am not sure I understand correctly.

If you get a trade signal (trigger) you can determine distance between bar close / next bar open and the last swing low before entering a trade. So you know (and you should always know before you enter a trade) how far your stop-loss will be placed. Since you know the distance and the amount of money you want to risk (let’s say maximum risk is 3% of your account balance) you can get position size calculated just before entering the trade like this:

Position Size = Account Balance * 0.03 / Calculated stop Loss (in money)

Now you can create order with that calculated position size and set calculated stop-loss for the order which will be placed below swing lows.

Hello Tomas262

It’s been a while since I’ve been able to work on the EA. With the calculation above I’m able to create. I’m having a problem with taking the dollar amount and then converting it into a lot size.

Example:

Position Size = Account Balance * 0.01 / Stop loss in pips

\$1000 * 0.01 / 30 (SL pips) = 0.33 cents

I need that to be turned into a Lot Size for the “Quantity” on the order. I’m not sure but I think the calculation would be different for Yen based pairs.

Regards,

James

#132231
Customer
87 Posts

Tomas262,

Here is a screenshot of the variable I have “LotsToTrade”. So, on the first trade the MM setting is being used and on the second trade I’m looking to multiply the risk. The SL and entry is correct but the issue is getting the LotSize to be correct.

#132260
Moderator
1559 Posts

hi, i will try to make an Wizard example to be sure about it and post it here

#132263
Customer
87 Posts

Thanks Tomas262,

This is a piece that has stumped me for a while. Thanks for your time.

Regards,

James

#132348
Moderator
1559 Posts

Hi,

made a simple example on how to calculate a position size based on variable stop-loss (using ATR indicator in my example).

Basically what you need to do is to calculate risk per pip for each of your trade and then divide it by pip value for 1 lot to get proper size for the trade. Example:

You have 10000 USD, max 500 USD risk per trade. Your next trade needs stop-loss of 30 pips. Then you know your risk per pip is going to be 500 / 30 = 16.6 USD per pip. Consider pip value for your selected market to be 10 USD. Now you know you can trade basically 1.6 lots to keep risk below the max allowed risk of 5% of equity.

If your risk per pip is going to be 5 USD then you know you can play only half lot.

Hope this is what you needed

Attachments in this forum are visible only for registered users.
#132358
Customer
87 Posts

Tomas262,

Thanks for the example. I will go through it and figure out how to get the pip value calculated. Thanks again for your time and help.

Regards,

James

Viewing 15 posts - 1 through 15 (of 32 total)

You must be logged in to reply to this topic.