Topics
13 Nov 2019, 16:23
 3
 1097
 1
10 Oct 2019, 12:02
 4
 1130
 1
04 Sep 2019, 08:56
 1
 942
 2
01 Jul 2019, 17:26
 0
 1053
 1
20 Jun 2019, 08:51
 2
 1058
 1
19 Mar 2019, 12:48
 3071
 6
04 Feb 2019, 08:52
 0
 906
 1
Replies

TonNcie
21 Nov 2019, 10:54

it's calculated in Backtesting and Optimization so it;s there. Just make it public. I'd say this is a quick win for CTDN


@TonNcie

TonNcie
21 Nov 2019, 10:52

or just let cTrader automatically save it's progress/reults and continue where it left if it was cancelled somehow.


@TonNcie

TonNcie
21 Nov 2019, 10:44

also copy line with ctrl-c and ctrl-v would be nice

also copy line with ctrl-c and ctrl-v would be nice


@TonNcie

TonNcie
12 Nov 2019, 11:41

RE:

Yep and that's why I now have a requiredmargin function that is closer to the real taken margin than the requiredmargin function i used before :-)
Thanks.


@TonNcie

TonNcie
12 Nov 2019, 11:17 ( Updated at: 21 Dec 2023, 09:21 )

RE:

Hi Panagiotis,
Well That is where my question started. I needed to know what the difference (Look at the drop in free margin) was

 


@TonNcie

TonNcie
12 Nov 2019, 10:44

RE:

Hi Panagiotis
I need to know the 'taken margin' because for me it is important to know how much my margin drops when i place an order. That is the real margin an order will cost you.
As you can see in my example the margin does not drop with the amount you circled but with 68.59 which is about 3.6% more.
if you have a freemargin of 67.00 and you use your calculation which says that you only need 66.21 for your position your order will get cancelled on lack of free margin.
That's why i.m.h.o. you need to use the 'taken margin' calculation. 
And as all traders know sometimes a few percent can make the difference!
Best rgds,

El A

 


@TonNcie

TonNcie
12 Nov 2019, 10:16

RE:

Hi Panagiotis,

Lets wrap it up

The correct formula to calculate the required marging is NOT

Required Margin =  (Volume / Leverage) * Conversion Rate

but more like  :

(volumeInUnits / UsedLeverage * (CrossBid + MySymbol.Spread)) + (CrossBid * (Commission1WayPerM / 1000000) * volumeInUnits) + (volumeInUnits * MySymbol.Spread);

So an extention method like the one here below [with your own cross ofcourse ;-) ]  in the robot or Symbol or Account class would be very nice in a next release.

  public static class extention
    {
        public static double Required_Margin(this Robot MyRobot, Symbol MySymbol, double volumeInUnits, TradeType tradeType, double Commission1WayPerM)
        {
            string Cross = MySymbol.Name.Left(3) + MyRobot.Account.Currency;
            double UsedLeverage = Math.Min(MyRobot.Account.PreciseLeverage, MySymbol.DynamicLeverage[0].Leverage);
            double CrossBid = 1;
            if (MySymbol.Name.Left(3) != MyRobot.Account.Currency)
            {
                Symbol CrossSym = MyRobot.Symbols.GetSymbol(Cross);
                if (CrossSym != null)
                    CrossBid = tradeType == TradeType.Buy ? CrossSym.Bid : CrossSym.Bid;
                else
                {
                    Cross = MyRobot.Account.Currency + MySymbol.Name.Left(3);
                    CrossSym = MyRobot.Symbols.GetSymbol(Cross);
                    CrossBid = 1 / (tradeType == TradeType.Buy ? CrossSym.Bid : CrossSym.Bid);
                }
                Cross = CrossSym.ToString();
            }
            return (volumeInUnits / UsedLeverage * (CrossBid + MySymbol.Spread)) + (CrossBid * (Commission1WayPerM / 1000000) * volumeInUnits) + (volumeInUnits * MySymbol.Spread);
        }
    }

If this is not correct please correct me, it it is please state so !
At the end we'll have a concensused answer on how cTrader calculates the required margin and we can all update our MoneyManagement routines.

Best regards
El Antonio


@TonNcie

TonNcie
11 Nov 2019, 21:16 ( Updated at: 21 Dec 2023, 09:21 )

Example of Difference Calculated margin and taken margin

Hi Panagiotis,

Just to show you the outcome of the required margin and the taken margin and the unexplainable difference (meaning i can't explain it but certainly you folks can)
I'd like to be able to calculate the real TAKEN margin in my money management module.
So teh question is
What constitutes the difference !
Best rgds,
El A.

 

        protected override void OnStart()
        {
            double CrossBid = 1;
            double Volume = 30000;
            string Cross = Symbol.Name.Left(3) + Account.Currency;
            if (Symbol.Name.Left(3) != Account.Currency)
            {
                Symbol CrossSym = Symbols.GetSymbol(Cross);
                if (CrossSym != null)
                    CrossBid = CrossSym.Bid;
                else
                {
                    Cross = Account.Currency + Symbol.Name.Left(3);
                    CrossSym = Symbols.GetSymbol(Cross);
                    CrossBid = 1 / CrossSym.Bid;
                }
                Cross = CrossSym.ToString();
            }
            double StartMargin = Account.FreeMargin;
            Print("Account Currency ", Account.Currency);
            Print("Cross Symbol \t", Cross.ToString());
            Print("CrossBid2Use  " + CrossBid.ToString("F5"));
            Print("Current Symbol \t", Symbol.ToString());
            Print("Account Leverage \t", Account.PreciseLeverage);
            Print("Symbol Leverage \t", Symbol.DynamicLeverage[0].Leverage);
            double UsedLeverage = Math.Min(Account.PreciseLeverage, Symbol.DynamicLeverage[0].Leverage);
            Print("Used Leverage \t", UsedLeverage);
            Print("Free Margin \t", StartMargin.ToString("N2"));
            Print("Volume in Units \t", Volume);
            double rm = Volume / UsedLeverage * CrossBid;
            Print("Required Margin in " + Account.Currency + "\t", rm.ToString("N2"));
            TradeResult tradeResult = ExecuteMarketOrder(TradeType.Buy, Symbol.Name, Volume);
            Print("Free Margin \t", Account.FreeMargin.ToString("N2"));
            Print("Taken Margin \t", (StartMargin - Account.FreeMargin).ToString("N2"));
            Print("Difference \t", (100 * (StartMargin - (rm * CrossBid)) / Account.FreeMargin).ToString("N2"), "%");
            Print("Position Commissions \t", tradeResult.Position.Commissions.ToString("N2"));
            Print("Position EntryPrice\t", tradeResult.Position.EntryPrice.ToString("F5"));
            Print("Position GrossProfit \t", tradeResult.Position.GrossProfit.ToString("N2"));

            Stop();

        }

Output:

Prder info


@TonNcie

TonNcie
11 Nov 2019, 12:52

RE:

Hi Panagiotis,

I'd seen that post and studied it.
Even with adaptions regarding leverage (taking into account the symbol.dynamicleverage and using tickvalue instead of calculating the SymbolRate ) also these results differ!
So still a formula on how you guys exactly calculate the taken margin would be verry helpfull.

Best Rgds,
El A

 


 

 


@TonNcie

TonNcie
11 Nov 2019, 10:36

Hi Panagiotis, 
Thanks for your answer. It helps but still the results differ.
Could you please reveal the way the taken margin is calculated when taking a position in a base currency that is not equal to the account currency?
So we can adjust our required margin calculator to closely match the taken margin.

Best Rgds
El A

 


@TonNcie

TonNcie
11 Nov 2019, 10:22

RE:

cTrader team,
Although not every broker supports autochartists it still would be a great addon to cAlgo.
It also might encourage some brokers to support this function.
So please provide access to the autochartist function from within cAlgo,
It would be a great plus for the platform.
So is there alread a date set for this ;-)
please let us now.


@TonNcie

TonNcie
07 Nov 2019, 11:01

Ok and is that the price using the bid or the ask?


@TonNcie

TonNcie
07 Nov 2019, 10:57

RE:

Hi srubtsov

I can't match your reply to my question. What do you mean to say?

 


@TonNcie

TonNcie
07 Nov 2019, 10:56

RE:

Hi Panagiotis.
What is the definition for monetaryvalue as stated in the docs?

eg. When trading EURJPY on a USD account, What is the monetaryvalue(tickVlaue) in  USD or JPY or EUR. The docs are not clear about that.


@TonNcie

TonNcie
04 Nov 2019, 12:27

RE: Optimization settings

And keep the results sort position when switching between optimization results; and when you ar at it enable a set-default for sort,columns,position too.
And add a Params column (params in order of paraminput screen separated by space or ;)

 


@TonNcie

TonNcie
08 Jul 2019, 17:39

Sorry Panagiotis,

But IMHO it has nothing to do with the internal logic of a cBot.
It's all your side calculations. My cBot does not make up these figures, cTrader automate Backtest does.

Best rgds,

Ton


@TonNcie

TonNcie
08 Jul 2019, 11:11

there is no average of 24.48 and 31.25 that produces 13.31
and Max Balance DD seems to be equal to then max Eq DD everytime.


@TonNcie

TonNcie
01 Jul 2019, 15:25

So backtesting is not first-come first serve?
My sequence of events is:
Tick 1: open buy & open Sell

Tick 2: Open Sell

Tick 3: Open Sell



So in backtesting I'd expect them to have id 1, id 2 and id 3 and haven ascending  entrytimes

 

Best rgds,

Ton

 


@TonNcie

TonNcie
26 Jun 2019, 10:58

add CALMAR ratio to fitness

add CALMAR ratio to fitness


@TonNcie

TonNcie
26 Jun 2019, 10:53

Enable setting BE level from algo l

position.SetBreakeven();


@TonNcie