Reference Indicators in Robots

Created at 20 Nov 2012, 15:43
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
RK

rkokerti

Joined 28.06.2012

Reference Indicators in Robots
20 Nov 2012, 15:43


Hello Admin, 

Unfortunately, backtesting function dosn't work well if I use reference indicator in my code since I received the version of FxPro UK cAlgo 1.0.18.

I don't know important or not, but when I type "using aAlgo." then only "API" text is appear on popup window as selectable text. If I remember well previously "Indicator" also was there. Maybe this is related to my problem of reference indicators?

Thanks for your help!

p.s.: New added functions are very good!

 


@rkokerti
Replies

admin
20 Nov 2012, 16:20

We apologize for that inconvenience, it will be fixed promptly. But it does not have anything to do with any errors. It is only a matter of the intellisense feature.

About the backtesting, could you be more specific. What exactly is the error?

 


@admin

rkokerti
20 Nov 2012, 17:03 ( Updated at: 21 Dec 2023, 09:20 )

OK, durring I used cAlgo 1.0.16 all backtest ran normally. There was a lot of trade in result table and on balance/equity chart.

Now, I received new version 1.0.18 (yesterday evening) I wanted to run backtest again, but the result contains only one trade, see below:

I didn't change anything in code of robot and reference indicator between two version 1.0.16 and 1.0.18.


@rkokerti

rkokerti
20 Nov 2012, 17:55 ( Updated at: 21 Dec 2023, 09:20 )

One other comment... 

If I remove "using cAlgo.Indicators;" from robot code and press "Build Robot" button then an error message come. It said "Maybe one using directive is missing" or something like that. (sorry for translation) So, this is the reason why I think it is important is case of reference indicators. Or not?

see below:


@rkokerti

admin
20 Nov 2012, 18:21

We will investigate the backtesting feature promptly. 

 


@admin

rkokerti
21 Nov 2012, 14:26

Hello Admin,

I would just like to inquire when expected the solution of backtest issue?

Thanks for your help!


@rkokerti

admin
21 Nov 2012, 15:50

We are currently testing and will get back to you as soon as we have more information.  Thank you for your patience.

 


@admin

admin
22 Nov 2012, 14:22

Thank you for reporting this. We have identified an issue with the backtesting and are currently working on a solution for it.

 


@admin

rkokerti
26 Nov 2012, 12:11

I know, you work hard for solve this issue... I just want to inquire about what to expected, days, weeks? What is your estimation? 

Thanks, and sorry for disturbing


@rkokerti

admin
26 Nov 2012, 12:27

It is on the top of our list. It should be very soon. We will keep you posted.

 


@admin

rkokerti
27 Nov 2012, 14:50

OK, thanks!

Can I maybe download an older version somehow, until solution will available? 

Thanks for your help!


@rkokerti

admin
27 Nov 2012, 17:21

No unfortunately not, but it will be fixed this week.

 


@admin

rkokerti
30 Nov 2012, 16:51

Thanks for your support, backtest function works well again!


@rkokerti

rkokerti
02 Dec 2012, 13:53 ( Updated at: 21 Dec 2023, 09:20 )

Hello, 

I revoke my previous comment, that everything is fine with backtest result!!!

I tested the robot what coded by you Admin, the name is: „Sample SAR Trailing Stop”. This code is default in cAlgo.

Code:

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This robot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk
//
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample SAR Trailing Stop Robot" will create a market Buy order if the parabolic SAR of the previous bar is 
//    below the candlestick. A Sell order will be created if the parabolic SAR of the previous bar is above the candlestick.  
//    The order's volume is specified in the "Volume" parameter. The order will have a trailing stop defined by the 
//    previous periods' Parabolic SAR levels. The user can change the Parabolic SAR settings by adjusting the "MinAF" 
//    and "MaxAF" parameters.
//
// -------------------------------------------------------------------------------------------------


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

namespace cAlgo.Robots
{
    [Robot]
    public class SampleSARTrailingStop : Robot
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double MinAF { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double MaxAF { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 0)]
        public int Volume { get; set; }

        private Position position;
        private ParabolicSAR parabolicSAR;

        protected override void OnStart()
        {
            parabolicSAR = Indicators.ParabolicSAR(MinAF, MaxAF);
        }

        protected override void OnTick()
        {
            if (position == null && !Trade.IsExecuting)
            {
                var command = parabolicSAR.Result.LastValue < Symbol.Bid ? TradeType.Buy : TradeType.Sell;
                Trade.CreateMarketOrder(command, Symbol, Volume);

                Print("TradeCommand is {0}, Parabolic SAR is {1}, Bid is {2}", command, parabolicSAR.Result.LastValue, Symbol.Bid);
            }

            if (position != null && !Trade.IsExecuting)
            {
                double newStopLoss = parabolicSAR.Result.LastValue;
                bool isProtected = position.StopLoss.HasValue;

                if (position.TradeType == TradeType.Buy && isProtected)
                {
                    if (newStopLoss > Symbol.Bid) return;
                    if (newStopLoss - position.StopLoss < Symbol.PointSize) return;
                }

                if (position.TradeType == TradeType.Sell && isProtected)
                {
                    if (newStopLoss < Symbol.Bid) return;
                    if (position.StopLoss - newStopLoss < Symbol.PointSize) return;
                }

                Trade.ModifyPosition(position, newStopLoss, null);
            }
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            position = openedPosition;
        }

        protected override void OnPositionClosed(Position position)
        {
            Stop();
        }
    }
}

If you add for example EUR/USD instance to robot, and run a test you will see the result is INCORRECT again!!! Where these S/L values are coming???

Add the indicator PSAR to chart (settings: MinAF:0.02, MaxAF:0.2) and compare the indicator value with test result values. DO NOT MACH!

 

This statement is also true for other robots that use indicator value as stoploss!!!

If build a strategy to a backtest result, so many trader will be disappointed!!!  

Please investigate it thoroughly, and fix it as soon as possible, because we waited for weeks for a well-functioning backtest!!!! 

 

Thanks


@rkokerti

admin
03 Dec 2012, 15:37

This example is setting stop loss value equal to the last value of parabolic sar in the OnTick event. There are two things to keep in mind. One, the OnTick event occurs many times for the same bar until the time is up, therefore it cannot coinside with the actual value produced on the chart. That value is known only when the execution of the next bar begins. In other words the last value of the parabolic sar will keep changing on each tick for the duration of the bar. Second, the value at the OnTick event is as close to the actual value that occured as possible but it is not identical due to the fact that the ticks are generated by interpolation for the backtesting. It is in our future plans though to include the actual ticks in the backtesting.

 

 

 


@admin