Replies

galafrin
30 Sep 2016, 16:42

RE:

lucian said:

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class Linearregressionintercept : Indicator
    {
        [Parameter(DefaultValue = 30)]
        public int Period { get; set; }

        [Output("Main", Color = Colors.Yellow, PlotType = PlotType.Line)]
        public IndicatorDataSeries Result { get; set; }


        public override void Calculate(int index)
        {


            double sumx = 0, sumx2 = 0, sumy = 0, sumxy = 0;

            int start = (index + 1) - Period;
            int end = index;

            for (int i = start; i <= end; i++)
            {
                sumx += i;
                sumx2 += i * i;
                sumy += MarketSeries.Close[i];
                sumxy += MarketSeries.Close[i] * i;
            }

            double m = (Period * sumxy - sumx * sumy) / (Period * sumx2 - sumx * sumx);
            double b = (sumy - m * sumx) / Period;
            Result[index] = start * m + b;

        }

    }
}

 

Nice try Lucian , a correct solution would be this :

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
 
namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class Linearregressionintercept : Indicator
    {
        [Parameter(DefaultValue = 30)]
        public int Period { get; set; }
 
        [Output("LF", Color = Colors.Yellow, PlotType = PlotType.Line)]
        public IndicatorDataSeries LF { get; set; }
 
        [Output("LFI", Color = Colors.Orange, PlotType = PlotType.Line)]
        public IndicatorDataSeries LFI { get; set; }
 
  
        public override void Calculate(int index)
        {
 
 
            double sumx = 0, sumx2 = 0, sumy = 0, sumxy = 0;
 
            for (int i = 1; i <= Period; i++)
            {
                sumx += i;
                sumx2 += i * i;
                sumy += MarketSeries.Close [ index - Period + i  ] ;
                sumxy += MarketSeries.Close[ index - Period + i  ] * i ;
            }
 
            double m = (Period * sumxy - sumx * sumy) / (Period * sumx2 - sumx * sumx);
            double b = (sumy - m * sumx) / Period;
            LF[index] = Period * m + b;
            LFI[index] = b;
 
        }
 
    }
}

Btw be aware that corresponding builtin indicators are flawed from period 283 upward. I alerted Spotware to no avail yet : TimeSeries MA , LRF , LRFI , LR slope.


@galafrin

galafrin
09 Sep 2016, 01:47

RE: RE: RE: .NET 4

jaredthirsk said:

she666 said:

zelenij.krokodil said:

Hi cTrader/cAlgo developers,

Is .NET 4.5 supported?  Or do we have to compile algos against 4.0 Client Profile?

 

 

cAlgo.dll is  v4.0.30319 which implies dotNet 4.0

Spotware, any chance of dotNet upgrade for better performance? It's been 3 years and still remains stagnant. 

+1

.NET 4 Client Profile is basically abandoned by Microsoft -- everybody has moved on (.NET 4.6.2).  Is cTrader/cAlgo abandoned?

Good point for Calgo is sometimes slow and consumes too much resources, for instances loading multi symbols series or the Optimizer.


@galafrin

galafrin
09 Sep 2016, 00:25

In order to get five full daily bars per week , cAlgo code should be set with  TimeZone = TimeZones.EEuropeStandardTime while cTrader and cAlgo screens should be set to UTC+2 or UTC+3 depending on actual Daily Saving Time status,, currently +3;  

 


@galafrin

galafrin
01 Sep 2016, 19:49

RE:
double
trade = ( volume < 0 ? 1 : -1 ) , 
commission = 35.0 / 1000000.0 ;
netProfit = Math.Round ( ( oPrice * ( 1.0 - commission * trade ) - cPrice * ( 1.0 + commission * trade ) ) * Math.Abs ( volume ) / Symbol.TickSize * Symbol.TickValue  * trade , 2 ) , 
comm      = Math.Round ( ( oPrice + cPrice ) * commission * Math.Abs ( volume ) / Symbol.TickSize * Symbol.TickValue , 2 ) ;

 


@galafrin

galafrin
01 Sep 2016, 19:39

It is not possible to exact profit when trading outside account currency , albeit this may help and match Symbol.UnrealizedNetProfit and Symbol.UnrealizedGrossProfit ;

            double 
            trade = ( volume < 0 ? 1 : -1 ) , 
            commission = 35.0 / 1000000.0 ;
            
            double netProfit = Math.Round ( ( openPrice * ( 1.0 - commission * trade ) - closePrice * ( 1.0 + commission * trade ) ) * Math.Abs ( volume ) / Symbol.TickSize * Symbol.TickValue  * trade , 2 ) ; 
            double comm      = Math.Round ( ( openPrice + closePrice ) * commission / Symbol.TickSize * Symbol.TickValue * Math.Abs ( volume ) , 2 ) ; 

 


@galafrin

galafrin
13 Aug 2016, 00:38

RE:

jaredthirsk said:

I am trying to open a position with a size based on the risk.  However, I am stymied in backtesting when I try to do currency conversion because "GetSymbol is temporarily not supported in backtesting".

How temporary is this limitation?

I would think this is a pretty common strategy to use.  E.g. If my bot is trading XAUEUR and my Account.Currency is USD and the stop loss for my bot's trade is 0.5% and my account balance is $10000 and I want to risk 1% per trade, then I want to risk $100 on the trade.  So I want that 0.5% stop loss to be no more than $100.  I could calculate this if I had GetSymbol for EURUSD but I don't have that in backtesting.  Does anyone have ideas what I can do?

 

(I have been wondering if I will need to write my own backtesting / bot software (or find alternatives) and missing features like GetSymbol for backtesting force me in that direction.  I want to see cAlgo/cTrader succeed so I hope it fleshed out.  I found this feature request on the vote page.  Apparently many others believe this is a critical feature going back more than 2 years.  Not having a critical feature available makes me question my future with cTrader and makes me pay more attention to alternatives.)

 

http://vote.spotware.com/forums/229166-ideas-and-suggestions-for-ctrader-and-calgo/suggestions/5435043-multi-currency-backtesting

 

Symbol.TickValue hold the conversion of current Bid to Account currency , I doubt it is synced like Symbol.Bid in backtesting , if not it might aproximately do the trick in backtesting.


@galafrin

galafrin
06 Jul 2016, 10:30

RE:

moneybiz said:

How to calculate the max historical equity? It'd be nice if HistoricalTrade had Equity property besides the Balance property .

Equity Chart actually shows it but there is no way to access it, or is there?

After downloading through backtesting M1 bars of each symbol traded from the very first trade, then browse historical trades in sync with files to rebuild trades in parallell. :()


@galafrin

galafrin
03 Jul 2016, 23:44

RE:

ttkrauss said:

Hi there

I always want to trade the same percentage of my account balance regardless of the currency pair I trade.

Is there a smart way to calculate the volume to set an order in cAlgo?

Thanks

This would do in real time only

volume = Symbol.NormalizeVolume ( Account.Balance / Symbol.Bid * InpLeverage / Symbol.TickValue * Symbol.TickSize ) ;

 


@galafrin

galafrin
16 Jun 2016, 08:56

I noticed too that yesterday's update was followed by yesterday's night deconnexion . The problem on both cTrader and cAlgo is they don't reconnect automatically as other trading softwares do, which is an obvious deterrent for automated trading. 


@galafrin

galafrin
23 May 2016, 03:50

RE:

galafrin said:

Most FOREX markets start at 21H00 GMT on sunday except RUB , in order  to get 24hours bars there is no such ting like friday in FOREX daily series except for RUB .

Slight correction : Most FOREX markets start at 0H00 GMT on Monday which translate in Sunday 21H00 Cyprus DST or russian time or Sunday 23:00 London DST or  Monday 00.00 GMT . Hence in order to have friday daily bars , Russian time is to be set as time zone. Just a a bit of a headache but it goes like this

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.RussianStandardTime, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            Print("Server Time Today: {0} {1}", Server.Time.DayOfWeek, TimeZones.RussianStandardTime.ToString());
            Print("bar OpenTime Series : {0}", MarketSeries.OpenTime.Last(1).DayOfWeek);
            //So far so good
            MarketSeries x = MarketData.GetSeries(Symbol.Code, TimeFrame.Daily);
            Print("GetSeries dAily: {0}", x.OpenTime.Last(1).DayOfWeek);

            Print("Server Time Today: {0} {1}", Server.Time.DayOfWeek, TimeZones.RussianStandardTime.ToString());
            Print("Current Series Today: {0} {1} {2} {3} ", Symbol.Code, TimeFrame, MarketSeries.OpenTime.Last(1).DayOfWeek, MarketSeries.OpenTime.Last(1));
            //So far so good
            for (int i = 1; i < MarketData.GetSeries(TimeFrame.Daily).OpenTime.Count; i++)
                if (MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i).TimeOfDay != MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i - 1).TimeOfDay)
                    Print("GetSeries Today: {0} {1} {2} {3} {4} {5} {6} ", i, Symbol.Code, TimeFrame.Daily, MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i).DayOfWeek, MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i), MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i - 1).DayOfWeek, MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i - 1));
            //This thwows data 1 day behind, why?  */      

        }
        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }

23/05/2016 00:44:19.278 | Server Time Today: Monday Russian Standard Time
23/05/2016 00:44:19.278 | bar OpenTime Series : Friday
23/05/2016 00:44:19.278 | GetSeries dAily: Friday
23/05/2016 00:44:19.294 | Server Time Today: Monday Russian Standard Time
23/05/2016 00:44:19.294 | Current Series Today: EURUSD Daily Friday 20/05/2016 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 51 EURUSD Daily Friday 11/03/2016 1:00:00 Monday 14/03/2016 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 144 EURUSD Daily Friday 30/10/2015 0:00:00 Monday 02/11/2015 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 315 EURUSD Daily Sunday 08/03/2015 1:00:00 Monday 09/03/2015 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 405 EURUSD Daily Friday 31/10/2014 0:00:00 Monday 03/11/2014 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 410 EURUSD Daily Friday 24/10/2014 1:00:00 Monday 27/10/2014 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 576 EURUSD Daily Sunday 09/03/2014 2:00:00 Monday 10/03/2014 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 668 EURUSD Daily Saturday 02/11/2013 1:00:00 Monday 04/11/2013 2:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 869 EURUSD Daily Friday 08/03/2013 2:00:00 Monday 11/03/2013 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 964 EURUSD Daily Saturday 03/11/2012 1:00:00 Monday 05/11/2012 2:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 1167 EURUSD Daily Sunday 11/03/2012 2:00:00 Monday 12/03/2012 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 1272 EURUSD Daily Friday 04/11/2011 1:00:00 Monday 07/11/2011 2:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 1462 EURUSD Daily Sunday 27/03/2011 0:00:00 Monday 28/03/2011 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1474 EURUSD Daily Sunday 13/03/2011 1:00:00 Monday 14/03/2011 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1581 EURUSD Daily Friday 05/11/2010 0:00:00 Monday 08/11/2010 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1586 EURUSD Daily Friday 29/10/2010 1:00:00 Monday 01/11/2010 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1771 EURUSD Daily Sunday 28/03/2010 0:00:00 Monday 29/03/2010 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1783 EURUSD Daily Sunday 14/03/2010 1:00:00 Monday 15/03/2010 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1894 EURUSD Daily Friday 30/10/2009 0:00:00 Monday 02/11/2009 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1899 EURUSD Daily Friday 23/10/2009 1:00:00 Monday 26/10/2009 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2078 EURUSD Daily Sunday 29/03/2009 0:00:00 Monday 30/03/2009 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2096 EURUSD Daily Sunday 08/03/2009 1:00:00 Monday 09/03/2009 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2202 EURUSD Daily Sunday 02/11/2008 0:00:00 Monday 03/11/2008 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2208 EURUSD Daily Sunday 26/10/2008 1:00:00 Monday 27/10/2008 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2388 EURUSD Daily Sunday 30/03/2008 0:00:00 Monday 31/03/2008 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2406 EURUSD Daily Sunday 09/03/2008 1:00:00 Monday 10/03/2008 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2514 EURUSD Daily Sunday 04/11/2007 0:00:00 Monday 05/11/2007 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2520 EURUSD Daily Sunday 28/10/2007 1:00:00 Monday 29/10/2007 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2706 EURUSD Daily Sunday 25/03/2007 0:00:00 Monday 26/03/2007 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 2718 EURUSD Daily Sunday 11/03/2007 1:00:00 Monday 12/03/2007 0:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3010 EURUSD Daily Sunday 02/04/2006 2:00:00 Monday 03/04/2006 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3016 EURUSD Daily Sunday 26/03/2006 1:00:00 Monday 27/03/2006 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3322 EURUSD Daily Sunday 03/04/2005 2:00:00 Monday 04/04/2005 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3328 EURUSD Daily Sunday 27/03/2005 1:00:00 Monday 28/03/2005 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3611 EURUSD Daily Sunday 04/04/2004 2:00:00 Monday 05/04/2004 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3617 EURUSD Daily Sunday 28/03/2004 1:00:00 Monday 29/03/2004 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3874 EURUSD Daily Sunday 06/04/2003 2:00:00 Monday 07/04/2003 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3880 EURUSD Daily Sunday 30/03/2003 1:00:00 Monday 31/03/2003 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 4137 EURUSD Daily Sunday 07/04/2002 2:00:00 Monday 08/04/2002 1:00:00
23/05/2016 00:44:19.341 | GetSeries Today: 4143 EURUSD Daily Sunday 31/03/2002 1:00:00 Monday 01/04/2002 2:00:00
 


@galafrin

galafrin
20 May 2016, 23:01 ( Updated at: 24 May 2016, 10:22 )

Hola , You should post it in its entirety  if you expect somebody looking at it .


@galafrin

galafrin
20 May 2016, 22:54

Most FOREX markets start at 21H00 GMT on sunday except RUB , in order  to get 24hours bars there is no such ting like friday in FOREX daily series except for RUB .


@galafrin

galafrin
13 May 2016, 21:44

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleSMA : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Output("Main", Color = Colors.Turquoise)]
        public IndicatorDataSeries Result { get; set; }

        double sum = 0 ;
        

public override void Calculate(int index)
        {

            for (int i = index - Periods + 1; i <= index; i++)
            {
                sum += ( MarketSeries.Close [i] + MarketSeries.High [i] + MarketSeries.Low [i]  ) / 3.0 ;
            }
            Result[index] = sum / Periods;
        }
    }
}


@galafrin

galafrin
13 May 2016, 21:44

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleSMA : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Output("Main", Color = Colors.Turquoise)]
        public IndicatorDataSeries Result { get; set; }

        double sum = 0 ;
        

public override void Calculate(int index)
        {

            for (int i = index - Periods + 1; i <= index; i++)
            {
                sum += ( MarketSeries.Close [i] + MarketSeries.High [i] + MarketSeries.Low [i]  ) / 3.0 ;
            }
            Result[index] = sum / Periods;
        }
    }
}


@galafrin

galafrin
29 Apr 2016, 20:39

T​his helps to write Excel file : /algos/cbots/show/1050  This helps to handle csv file : /algos/cbots/show/1098

 


@galafrin

galafrin
29 Apr 2016, 20:35

RE:

Paul Cookson said:

I understand most brokers only offer hedged accounts. Do any offer netted?

My issue with hedge accounts is that I pay round-trip commission on both the original trade and the hedging trade. I presume this is under the control of the broker but i do not want to pay double commission just to use hedging.

At the moment i use a hedge account and use the partial-close function in ctrader but being able to have a netting account and therefore manage positions separately would be a real help.

 

Thanks.

I know of only one boker that offers the netted version of Ctrader , but lately only in demo


@galafrin

galafrin
25 Apr 2016, 00:26

​Did you try the converter from MT4 to cTrader ;  http://​2calgo.com  ?


@galafrin

galafrin
22 Apr 2016, 22:29 ( Updated at: 21 Dec 2023, 09:20 )

I didn't hear about publicly available market scanner but it is no big deal to code as it needs only a list of symbol to be filled as there is not yet built-in one.Here is a screen shot of a market scanner that displays highest HL by asset class::market scanner

 


@galafrin

galafrin
31 Mar 2016, 21:37

It took roughly 6 mn to get my broker's 1470 series of 70 working symbols and displaying last bar close / open , in line with the market.  


@galafrin

galafrin
31 Jan 2016, 21:58

​You may adjust  cTrader time shift  right bottom to have time separators coincide with date. 


@galafrin