Topics
14 Jul 2015, 17:47
 4716
 2
08 Jul 2015, 22:07
 3537
 12
18 Jun 2015, 22:54
 3096
 1
11 Sep 2014, 23:46
 2971
 4
07 Aug 2014, 22:35
 2836
 2
27 Jul 2014, 16:51
 2363
 2
18 Jul 2014, 20:54
 2406
 4
partial close in backtesting

completed Closed cTrader Automate

Suggestions
28 Jun 2014, 12:49
 74
 1298
 3
Replies

aysos75
19 Jul 2015, 14:11

In CSharp you can determine the length of a string by this instruction

            String myString = "myString";
            int length = myString.Length;


@aysos75

aysos75
17 Jul 2015, 20:06

ok I see that All broker discussions are prohibited on cTDN.


@aysos75

aysos75
17 Jul 2015, 20:03

This post has been removed by the moderator due to a violation of the EULA.


@aysos75

aysos75
17 Jul 2015, 14:37

This post has been removed by the moderator due to a violation of the EULA.


@aysos75

aysos75
17 Jul 2015, 14:36

This post has been removed by the moderator due to a violation of the EULA.


@aysos75

aysos75
14 Jul 2015, 21:55

RE:

torokbalint1986

If you want to use double volume, you can use this instructions :

double volume = moneyManagement(RiskPercent, StopLoss);

 

long normalizedVolume = Symbol.NormalizeVolume(volume, RoundingMode.ToNearest)

ExecuteMarketOrder(tradeType, Symbol, normalizedVolume, _instanceLabel, StopLoss, TakeProfit, 10, comment);

 


@aysos75

aysos75
14 Jul 2015, 21:41

RE:

SaifBD said:

I can make break even price only for buy and only for sell. Here's my code. But I can't make break even price between buy & sell together. Please help me. How can I make this?

        private double pnt_12(TradeType TrdTp)
        {
            double Result = 0;
            double AveragePrice = 0;
            long Count = 0;
            for (int i = Positions.Count - 1; i >= 0; i--)
            {
                position = Positions[i];
                if (position.Label == Label && position.SymbolCode == Symbol.Code)
                {
                    if (position.TradeType == TrdTp)
                    {
                        AveragePrice += position.EntryPrice * position.Volume;
                        Count += position.Volume;
                    }
                }
            }
            if (AveragePrice > 0 && Count > 0)
                Result = Math.Round(AveragePrice / Count, Symbol.Digits);
            return Result;
        }

 

This code

pnt_12(TradeType TrdTp)

calculate the average price oppositions of type TrdTp. What is the correspondance to Break Even ?


@aysos75

aysos75
14 Jul 2015, 18:52

The solution is simple, I use extensions method to TimeFrame :

 

#region Licence
//The MIT License (MIT)
//Copyright (c) 2014 abdallah HACID, https://www.facebook.com/ab.hacid

//Permission is hereby granted, free of charge, to any person obtaining a copy of this software
//and associated documentation files (the "Software"), to deal in the Software without restriction,
//including without limitation the rights to use, copy, modify, merge, publish, distribute,
//sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
//is furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all copies or
//substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Project Hosting for Open Source Software on Github : https://github.com/abhacid/cAlgoBot
#endregion

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

namespace cAlgo.Lib
{
    /// <summary>
    /// Méthodes d'extensions du type cAlgo.API.TimeFrame
    /// </summary>
    public static class TimeFrameExtensions
    {
        public enum TimeFrameEnum
        {
            Minute,
            Minute2,
            Minute3,
            Minute4,
            Minute5,
            Minute6,
            Minute7,
            Minute8,
            Minute9,
            Minute10,
            Minute15,
            Minute20,
            Minute30,
            Minute45,
            Hour,
            Hour12,
            Hour2,
            Hour3,
            Hour4,
            Hour6,
            Hour8,
            Daily,
            Day2,
            Day3,
            Weekly,
            Monthly,
        }

        public static TimeFrameEnum ToTimeFrameEnum(this TimeFrame timeFrame)
        {
            TimeFrameEnum timeFrameEnum;

            Enum.TryParse<TimeFrameEnum>(timeFrame.ToString(), out timeFrameEnum);

            return timeFrameEnum; 
        }


        public static TimeSpan ToTimeSpan(this TimeFrame timeFrame)
        {
            TimeSpan timeSpan;
            long ticks=0;


            // instruction to transform each TimeFrame.Time in TimeSpan.

            switch(timeFrame.ToTimeFrameEnum())
            {
                case TimeFrameEnum.Minute:
                    ticks = TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute2:
                    ticks = 2 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute3:
                    ticks =3 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute4:
                    ticks = 4 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute5:
                    ticks = 5 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute6:
                    ticks = 6 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute7:
                    ticks = 7 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute8:
                    ticks = 8 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute9:
                    ticks = 9 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute10:
                    ticks = 10 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute15:
                    ticks = 15 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute20:
                    ticks = 20 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute30:
                    ticks = 30 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Minute45:
                    ticks = 45 * TimeSpan.TicksPerMinute;
                    break;

                case TimeFrameEnum.Hour:
                    ticks = TimeSpan.TicksPerHour;
                    break;

                case TimeFrameEnum.Hour2:
                    ticks = 2 * TimeSpan.TicksPerHour;
                    break;

                case TimeFrameEnum.Hour3:
                    ticks = 3 * TimeSpan.TicksPerHour;
                    break;

                case TimeFrameEnum.Hour4:
                    ticks = 4 * TimeSpan.TicksPerHour;
                    break;            
            
                case TimeFrameEnum.Hour6:
                    ticks = 6 * TimeSpan.TicksPerHour;
                    break;

                case TimeFrameEnum.Hour8:
                    ticks = 8 * TimeSpan.TicksPerHour;
                    break;

                case TimeFrameEnum.Hour12:
                    ticks = 12 * TimeSpan.TicksPerHour;
                    break;

                case TimeFrameEnum.Daily:
                    ticks = TimeSpan.TicksPerDay;
                    break;

                case TimeFrameEnum.Day2:
                    ticks = 2 * TimeSpan.TicksPerDay;
                    break;

                case TimeFrameEnum.Day3:
                    ticks = 3 * TimeSpan.TicksPerDay;
                    break;

                case TimeFrameEnum.Weekly:
                    ticks = 7 * TimeSpan.TicksPerDay;
                    break;

                case TimeFrameEnum.Monthly:
                    ticks = (long)(30.5 * TimeSpan.TicksPerDay);
                    break;
            }

            timeSpan = TimeSpan.FromTicks(ticks);

            return timeSpan;
        }
    }
}

And I can use in my indicator instructions like this :

        [Parameter()]
        public TimeFrame Global { get; set; }

        protected override void Initialize()
        {
            marketSerieGlobal = MarketData.GetSeries(Global);
            
            int period = (int) (Global.ToTimeSpan().Ticks / MarketSeries.TimeFrame.ToTimeSpan().Ticks);

            _localMA = Indicators.MovingAverage(LocalTrendSignal, period, MovingAverageType.Exponential);

        }


@aysos75

aysos75
11 Jul 2015, 16:58 ( Updated at: 21 Dec 2023, 09:20 )

Your robot is not closing the losing positions so the Equity, the only outcome that makes sense is bad

Here is a graph of your robot with Equity -100 from an initial capital of 100,000!

 


@aysos75

aysos75
11 Jul 2015, 16:38

RE: RE: RE:

susantasaren said:

hichem said:
Kate said:

There are brokers with minimum account much less than 2000€.

I know, but the strategy requires a minimum of 2000 to eliminate risk of a margin call.

Why not decrease the Lot Size equivaltent to 2000 the result will be the same.

 

Some robot take positions whose volume depends on the capital account, therefore the results of such robots depends on the initial nonlinear fashion capital. In other words double the initial capital has the effect of also affect the results in gains or losses.


@aysos75

aysos75
11 Jul 2015, 15:01

RE: RE: RE: RE:

breakermind said:

Spotware said:

breakermind said:

Hi and thanks,

 

I have this:

        public override void Calculate(int index)
        {

            // access to different series
            var weeklySeries = MarketData.GetSeries(TimeFrame.Weekly);

            // open price bars
            double open = weeklySeries.Open[index];
            Print(open);

            // If first bar is first bar of the day set open
            Week1Open[index] = open;

        }

How get Week open price and draw line on this price ? what is wrong ? 

index is wrong. The weeklySeries object has different indexes.

Cool,

something is wrong with this spotware cAlgo,

if do not hang it terribly slow ... shows some strange results ... in backtests

Support helpful as usual ...

... defeat.

Bye.

 

 

 

 

In the 'Calculate', 'index' is the index of the current timeframe candles eg M1. But if you want to retrieve values OLHC (Open High Low Close) a candle from another timeframe eg H1, we can not do it with 'index' because the index of the two series corresponding to the two timeframes are distinct. We must use the conversion method GetIndexByExactTime ( (MarketSeries.OpenTime [index]) or GetIndexByTime (MarketSeries.OpenTime [index]).


@aysos75

aysos75
11 Jul 2015, 14:51 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Spotware said:

Dear Trader,

Thank you for reporting this. We will investigate.

When I do a backtest , cAlgo gives as result the new position of thousands with the same second input (even EntryPrice ) , even though the robot is programmed to take no more 1 position both ???


@aysos75

aysos75
10 Jul 2015, 20:31

I found the problem that all optimization results were Zero, this was because the money management prevented to take position. So it was from the program.


@aysos75

aysos75
10 Jul 2015, 18:19

You can use Visual Studio for debugging a cAlgo Bot or an indicator


@aysos75

aysos75
10 Jul 2015, 18:17 ( Updated at: 21 Dec 2023, 09:20 )

There is a problem with the optimization too :

 


@aysos75

aysos75
10 Jul 2015, 13:47 ( Updated at: 21 Dec 2023, 09:20 )

RE:
I deleted the cache as requested, then I restarted the backtest over a period 
of 3 May 2015 to 3 June 2015. The results will be made ​​until 11 June 2015 and 
certain positions were taken outside of the curve price .

 

backtest

 

 

 


@aysos75

aysos75
10 Jul 2015, 13:45 ( Updated at: 21 Dec 2023, 09:20 )

I deleted the cache as requested, then I restarted the backtest over a period of 3 May 2015 to 3 June 2015. The results will be made ​​until 11 June 2015 and certain positions were taken outside of the curve price .

@aysos75

aysos75
10 Jul 2015, 00:20

In the first figure the position entry and the position close is out of the graph.

In the figure 2 and 3 the prices candles on the same timeframe and instrument are different.


@aysos75

aysos75
09 Jul 2015, 09:37 ( Updated at: 21 Dec 2023, 09:20 )

RE:

aysos75 said:

Two graphiques for the same instrument and same timeframe ?

 


@aysos75

aysos75
08 Jul 2015, 22:14

the problem is that returns GetIndexByExactTime = =1 if it does not find an exact match ( at a second close ) . Just use GetIndexByTime that if it does not find an exact match returns the index of the previous candle

@aysos75