Reference Indicators in Robots
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!
Replies
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
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
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