Topics
Replies
gainer
10 Feb 2016, 05:29
RE: RE:
galafrin said:
The is missing factor above , the correct fornula valid for any instrument that gives margin required of minimum volume of symbol in account currency is this:
Symbol.Bid / Symbol.Leverage * Symbol.TickValue / Symbol.TickSize * Symbol.VolumeMin
Surely my fault, but I didn't understand how use your formula
Instead this works well to calculate the max volume given an openMoney
My account is in EUR, of course you can adapt to your currency
protected long maxVolume(double openMoney) { double marginUSD = 0.0; string symbol = Symbol.Code; if (symbol.Substring(0, 3) == "USD") { marginUSD = 1000 / Account.Leverage; } else if (symbol.Substring(3, 3) == "USD") { marginUSD = Symbol.Bid * 1000 / Account.Leverage; } else { Symbol cross = MarketData.GetSymbol("USD" + symbol.Substring(3, 3)); marginUSD = Symbol.Bid / cross.Bid * 1000 / Account.Leverage; } double marginEUR = marginUSD / MarketData.GetSymbol("EURUSD").Bid; long maxVol = Symbol.QuantityToVolume(openMoney / marginEUR); //Print(symbol + " margin is " + marginUSD + " USD = " + marginEUR + " EUR"); //Print(symbol + " maxVol is " + maxVol + " = " + Symbol.NormalizeVolume(maxVol, RoundingMode.Down) + " EUR"); return (maxVol); }
@gainer
gainer
31 Jan 2016, 12:36
( Updated at: 24 Mar 2016, 14:07 )
This post was removed by moderator because it duplicates another post. /forum/calgo-support/6336
@gainer
gainer
24 Jan 2016, 11:50
Hi, I coded this method to calculate the lots from a set openMoney
My account is in EUR so before I translate it to USD and apply the suggested algo, then back to EUR
It's longer, but so it's clearer and you have all the elements you need to adapt it to your exigences
I hope it may be useful!
[Parameter("Open Money (0 = All)", DefaultValue = 0.0)] public double openMoney { get; set; } ..... protected int volume() { double account = 0.0; if (openMoney == 0.0) { account = Account.Balance; } else { account = openMoney; } double marginUSD = 0.0; string symbol = Symbol.Code; if (symbol.Substring(0, 3) == "USD") { marginUSD = 1000 / Account.Leverage; } else if (symbol.Substring(3, 3) == "USD") { marginUSD = Symbol.Bid * 1000 / Account.Leverage; } else { Symbol cross = MarketData.GetSymbol("USD" + symbol.Substring(3, 3)); marginUSD = Symbol.Bid / cross.Bid * 1000 / Account.Leverage; } double marginEUR = marginUSD / MarketData.GetSymbol("EURUSD").Bid; //Print(symbol + " margin is " + marginUSD + " USD = " + marginEUR + " EUR"); return (int)Math.Ceiling(account / marginEUR); }
@gainer
gainer
10 Feb 2016, 08:18
RE: RE: RE:
gainer said:
I forgot... much better a NormalizeVolume at the end !
@gainer