Topics
Replies
ctrader.guru
06 Dec 2019, 16:12
( Updated at: 21 Dec 2023, 09:21 )
cTrader Guru
Hi all,
we are the first and only Italian reference for cTrader, we offer assistance in Italian and English for cTrader and for all our paid and open source products.
@ctrader.guru
ctrader.guru
03 Sep 2019, 10:01
Broker : ICMARKETS
cTrader : 3.5
cBot : https://gist.github.com/cTraderGURU/24c5ef3c715b514f3f1c9086036becf5
@ctrader.guru
ctrader.guru
02 Feb 2019, 23:53
Use Account.PreciseLeverage instead of Symbol.DynamicLeverage[0].Leverage obviously adapt the method to your needs :
double marginEURUSD = _calculateMargin("EURUSD", 1, Account.Currency, Account.PreciseLeverage);
if the symbol is not managed, zero is returned
@ctrader.guru
ctrader.guru
01 Feb 2019, 12:22
RE: RE: Best way for me ...
ctrader.guru said:
ctrader.guru said:
Hi all,
some of our customers asked us how to correctly calculate the required margin, this is an example to follow
private bool _symbolExist(string symbolCode) { return MarketData.GetSymbol(symbolCode) != null; } private double _symbolRate(string symbolCode) { return (_symbolExist(symbolCode)) ? MarketData.GetSymbol(symbolCode).Bid : 0; } private double _calculateMargin( string symbolCode, double lots, string currency, double leverage ) { double margin = 0.0; if (!_symbolExist(symbolCode) || symbolCode.Length != 6) return margin; currency = currency.ToUpper(); double symbolRate = _symbolRate(symbolCode); if (symbolRate == 0) return margin; string baseCurrency = symbolCode.Substring(0, 3).ToUpper(); string subaCurrency = symbolCode.Substring(3, 3).ToUpper(); if (currency.Equals(baseCurrency)) { margin = lots * 100000 / leverage; } else if (currency.Equals(subaCurrency)){ margin = lots * 100000 / leverage * symbolRate; } else { symbolRate = _symbolRate(baseCurrency + currency); if (symbolRate == 0) { symbolRate = _symbolRate(currency + baseCurrency); if (symbolRate == 0) return margin; symbolRate = 1 / symbolRate; } margin = lots * 100000 / leverage * symbolRate; } return (margin > 0) ? Math.Round( margin, 2 ) : 0; }
Like this :
protected override void OnStart() { // --> TEST double marginEURUSD = _calculateMargin("EURUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginGBPUSD = _calculateMargin("GBPUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginAUDUSD = _calculateMargin("AUDUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginUSDJPY = _calculateMargin("USDJPY", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginCADJPY = _calculateMargin("CADJPY", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); _printExcep("EURUSD : " + marginEURUSD.ToString()); _printExcep("GBPUSD : " + marginGBPUSD.ToString()); _printExcep("AUDUSD : " + marginAUDUSD.ToString()); _printExcep("USDJPY : " + marginUSDJPY.ToString()); _printExcep("CADJPY : " + marginCADJPY.ToString()); Stop(); }
Sorry _printExcep is my method
protected override void OnStart() { // --> TEST double marginEURUSD = _calculateMargin("EURUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginGBPUSD = _calculateMargin("GBPUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginAUDUSD = _calculateMargin("AUDUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginUSDJPY = _calculateMargin("USDJPY", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginCADJPY = _calculateMargin("CADJPY", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); Print("EURUSD : " + marginEURUSD.ToString()); Print("GBPUSD : " + marginGBPUSD.ToString()); Print("AUDUSD : " + marginAUDUSD.ToString()); Print("USDJPY : " + marginUSDJPY.ToString()); Print("CADJPY : " + marginCADJPY.ToString()); Stop(); }
Admin, why can't edit post ?
@ctrader.guru
ctrader.guru
01 Feb 2019, 12:19
RE: Best way for me ...
ctrader.guru said:
Hi all,
some of our customers asked us how to correctly calculate the required margin, this is an example to follow
private bool _symbolExist(string symbolCode) { return MarketData.GetSymbol(symbolCode) != null; } private double _symbolRate(string symbolCode) { return (_symbolExist(symbolCode)) ? MarketData.GetSymbol(symbolCode).Bid : 0; } private double _calculateMargin( string symbolCode, double lots, string currency, double leverage ) { double margin = 0.0; if (!_symbolExist(symbolCode) || symbolCode.Length != 6) return margin; currency = currency.ToUpper(); double symbolRate = _symbolRate(symbolCode); if (symbolRate == 0) return margin; string baseCurrency = symbolCode.Substring(0, 3).ToUpper(); string subaCurrency = symbolCode.Substring(3, 3).ToUpper(); if (currency.Equals(baseCurrency)) { margin = lots * 100000 / leverage; } else if (currency.Equals(subaCurrency)){ margin = lots * 100000 / leverage * symbolRate; } else { symbolRate = _symbolRate(baseCurrency + currency); if (symbolRate == 0) { symbolRate = _symbolRate(currency + baseCurrency); if (symbolRate == 0) return margin; symbolRate = 1 / symbolRate; } margin = lots * 100000 / leverage * symbolRate; } return (margin > 0) ? Math.Round( margin, 2 ) : 0; }
Like this :
protected override void OnStart() { // --> TEST double marginEURUSD = _calculateMargin("EURUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginGBPUSD = _calculateMargin("GBPUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginAUDUSD = _calculateMargin("AUDUSD", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginUSDJPY = _calculateMargin("USDJPY", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); double marginCADJPY = _calculateMargin("CADJPY", 1, Account.Currency, Symbol.DynamicLeverage[0].Leverage); _printExcep("EURUSD : " + marginEURUSD.ToString()); _printExcep("GBPUSD : " + marginGBPUSD.ToString()); _printExcep("AUDUSD : " + marginAUDUSD.ToString()); _printExcep("USDJPY : " + marginUSDJPY.ToString()); _printExcep("CADJPY : " + marginCADJPY.ToString()); Stop(); }
@ctrader.guru
ctrader.guru
01 Feb 2019, 12:14
Best way for me ...
Hi all,
some of our customers asked us how to correctly calculate the required margin, this is an example to follow
private bool _symbolExist(string symbolCode) { return MarketData.GetSymbol(symbolCode) != null; } private double _symbolRate(string symbolCode) { return (_symbolExist(symbolCode)) ? MarketData.GetSymbol(symbolCode).Bid : 0; } private double _calculateMargin( string symbolCode, double lots, string currency, double leverage ) { double margin = 0.0; if (!_symbolExist(symbolCode) || symbolCode.Length != 6) return margin; currency = currency.ToUpper(); double symbolRate = _symbolRate(symbolCode); if (symbolRate == 0) return margin; string baseCurrency = symbolCode.Substring(0, 3).ToUpper(); string subaCurrency = symbolCode.Substring(3, 3).ToUpper(); if (currency.Equals(baseCurrency)) { margin = lots * 100000 / leverage; } else if (currency.Equals(subaCurrency)){ margin = lots * 100000 / leverage * symbolRate; } else { symbolRate = _symbolRate(baseCurrency + currency); if (symbolRate == 0) { symbolRate = _symbolRate(currency + baseCurrency); if (symbolRate == 0) return margin; symbolRate = 1 / symbolRate; } margin = lots * 100000 / leverage * symbolRate; } return (margin > 0) ? Math.Round( margin, 2 ) : 0; }
@ctrader.guru
ctrader.guru
24 Aug 2018, 11:06
( Updated at: 21 Dec 2023, 09:20 )
RE:
ctrader.guru said:
Amazing Price Action absolutely free download now and start your strategy with good direction
Two Amazing Price Action red for 7 period and blue for 8 period
@ctrader.guru
ctrader.guru
15 Jun 2021, 08:47
RE:
Spotware said:
❤
@ctrader.guru