|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
Dynamically calculating lot size |
Fx18
|
Post subject: Dynamically calculating lot size |
Post rating: 0
|
Posted: Wed 26 Feb, 2014, 11:25
|
|
User rating: 2
Joined: Wed 29 Jan, 2014, 10:18 Posts: 30 Location: Austria,
|
I'd like to dynamically calculate the lot size for a buy or sell order dependent on equity, stop loss and risk: double calculateLotSize(Instrument instrument, IContext context, double entryPrice, double stopLoss, int risk) {
double stopLossPips = Math.abs(stopLoss-entryPrice) / instrument.getPipValue(); double riskPercentage = (double) risk / 100; double RiskAmount = context.getAccount().getEquity() * riskPercentage; double PipValue = 100000 * instrument.getPipValue(); // calculated for 1 standard lot double lotSize = RiskAmount / (stopLossPips * PipValue);
return lotSize; } Is my code above is correct? if not, is there any better example for how to do this? Thanks
|
|
|
|
 |
hebasto
|
Post subject: Re: Dynamically calculating lot size |
Post rating: 1
|
Posted: Wed 26 Feb, 2014, 11:30
|
|
User rating: 96
Joined: Mon 09 Sep, 2013, 07:09 Posts: 287 Location: Ukraine, SHostka
|
1 lot = 1000000 (a million) currency units, not 100000.
|
|
|
|
 |
Fx18
|
Post subject: Re: Dynamically calculating lot size |
Post rating: 1
|
Posted: Wed 26 Feb, 2014, 11:42
|
|
User rating: 2
Joined: Wed 29 Jan, 2014, 10:18 Posts: 30 Location: Austria,
|
hebasto wrote: 1 lot = 1000000 (a million) currency units, not 100000. Sorry, I don't agree Basically, in forex a standard trading contract equates to 100,000 units of the base currency. This means that 1 standard lot has a value of roughly $10 per pip (depending on the currency pair you are trading). A mini lot is equal to 10,000 units of currency. A micro lot is equal to 1,000 units of currency.
|
|
|
|
 |
hebasto
|
Post subject: Re: Dynamically calculating lot size |
Post rating: 1
|
Posted: Wed 26 Feb, 2014, 13:03
|
|
User rating: 96
Joined: Mon 09 Sep, 2013, 07:09 Posts: 287 Location: Ukraine, SHostka
|
|
|
|
 |
Fx18
|
Post subject: Re: Dynamically calculating lot size |
Post rating: 0
|
Posted: Wed 26 Feb, 2014, 13:22
|
|
User rating: 2
Joined: Wed 29 Jan, 2014, 10:18 Posts: 30 Location: Austria,
|
hebasto wrote: Aha! I see your point. So 1 standard lot in Metatrader is actually 0,1 lot in JForex Thank you!
|
|
|
|
 |
Fx18
|
Post subject: Re: Dynamically calculating lot size |
Post rating: 0
|
Posted: Wed 26 Feb, 2014, 13:44
|
|
User rating: 2
Joined: Wed 29 Jan, 2014, 10:18 Posts: 30 Location: Austria,
|
Fx18 wrote: I'd like to dynamically calculate the lot size for a buy or sell order dependent on equity, stop loss and risk: double calculateLotSize(Instrument instrument, IContext context, double entryPrice, double stopLoss, int risk) {
double stopLossPips = Math.abs(stopLoss-entryPrice) / instrument.getPipValue(); double riskPercentage = (double) risk / 100; double RiskAmount = context.getAccount().getEquity() * riskPercentage; double PipValue = 1000000 * instrument.getPipValue(); // calculated for 1 standard lot double lotSize = RiskAmount / (stopLossPips * PipValue);
return lotSize; } Is my code above is correct? if not, is there any better example for how to do this? Thanks instead of double PipValue = 1000000 * instrument.getPipValue(); I think, it would be better to use convertPipToCurrency method: PipValue = context.getUtils().convertPipToCurrency(instrument, context.getAccount().getCurrency());
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|