Topics
Replies
lec0456
13 Mar 2013, 18:32
( Updated at: 21 Dec 2023, 09:20 )
Actually, I checked the results for your exact indicator and robot and at 7:32am on 3/713 it causes the same issue. So, you don't even have to have a reference to the custom indicator.
So, the SimpleMovingAverage is not giving the same results as robots when backtesting. Could you please send me screen shots of your results for 3/7/13at 7:32 am for each? and could you please use ICmarkets data.
@lec0456
lec0456
13 Mar 2013, 01:25
( Updated at: 21 Dec 2023, 09:20 )
The erratic behavior is repeating itself
Ok so I created simplifed indicators and robots and the sma's are still giving differnet results...
Here is the code for the indicator I used:
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false)] public class testMASlopeIndicator : Indicator { [Output("MA Slope", PlotType = PlotType.Histogram, Thickness = 2, Color = Colors.Purple)] public IndicatorDataSeries Result { get; set; } private SimpleMovingAverage SMA; int t0=-1; protected override void Initialize(){SMA=Indicators.SimpleMovingAverage(MarketSeries.Open,60);} public override void Calculate(int index) { if(t0!=index) { t0 = index; int t1 = t0 - 1; if(t1<0)return;//** prevent crash caused by posibly using a negetive index value if(double.IsNaN(SMA.Result[t1]))return; //** skip printing bar until moving average data is calculated Print("{0,20:MM/dd/yyyy HH:mm} | MA {1,30} | {2,30} | {3,30}",MarketSeries.OpenTime[t0],SMA.Result[t0],SMA.Result[t1],Math.Round((SMA.Result[t0]-SMA.Result[t1])/Symbol.PointSize,2)); Result[index]= Math.Round((SMA.Result[t0]-SMA.Result[t1])/Symbol.PointSize,2); } } } }
Here is the code for the robot i used:
//#reference: C:\Users\lcespedes\Documents\cAlgo\Sources\Indicators\testMASlopeIndicator.algo using System; using System.Collections.Generic; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.Indicators; using cAlgo.API.Requests; namespace cAlgo.Robots { [Robot] public class TestMASlopeBot : Robot { private testMASlopeIndicator slope; protected override void OnStart(){ slope = Indicators.GetIndicator<testMASlopeIndicator>();} protected override void OnBar() { if (Trade.IsExecuting) return; int t0=MarketSeries.Close.Count-1;//** t0 results are not final because the bar has not completed double test=slope.Result[t0]; } } }
I backtested for the last 7 days, used 60 periods for the SMA, Market Open data and 1 minute time frame. Here are the results for 7:32am and 8am for the robot and indicator...
Slope Robot @732am on 3/7/13
Slope Indicator @8am on 3/7/13
Slope Robot @8am on 3/7/13
Do you see how sometimes the values are the same and sometimes they differ? If you notice the numbers don't get back in sync until 7:46am. Do you see what I'm talking about now?
@lec0456
lec0456
12 Mar 2013, 19:15
But you are not using the indicator as a reference in the robot! you are recalculating within the robot. that defeats the whole purpose of having indicators! also the values do not differ throughout the whole series some times they are the same and sometimes they are not. Thats what makes it erratic. Also are you only testing this in realtime because I have been backtesting? I see the IsRealTime statement in your indicator, thats why I'm asking?
But I am going to strip down both the indicator and the robot and send you the code with the results...give me a couple hours...
@lec0456
lec0456
12 Mar 2013, 00:34
( Updated at: 21 Dec 2023, 09:20 )
OK, I did some more troubleshooting and what is happenening is that your indicator simplemoving average is giving different values to the robots than outputing to the chart.
So, first you can forget the my trend indicator I sent you it is not the issue.
I placed a print statement in the MASlope indicator, like so:
Print("{0,20:MM/dd/yyyy HH:mm} | {1,20} | {2,20} | {3,20}",MarketSeries.OpenTime[t0],MA.Result[t0],MA.Result[t1],Math.Round((MA.Result[t0]-MA.Result[t1])/Symbol.PointSize,2));
In the robot I took out the print statement and placed a dummy variable to read the indicator otherwise it will not print in the log, like so:
double test=trendShort.TrendDnIndicator[t0];
The log of the indicator looks like this
:
The log of the robot looks like this:
The values for the moving averages are different! So the slopes are different and thats why my trend indicator was acting erratic.
@lec0456
lec0456
11 Mar 2013, 18:54
( Updated at: 21 Dec 2023, 09:20 )
RE:
Hello,
The print statements from the indicator and the robot match. If this is not the issue please provide us with some more information (i.e. a screenshot indicating the difference or some more explanation).
Also please ensure you are using the same parameters for the indicator and the robot as the default parameters for the myTrend are not the same used in the Robot:
trendShort = Indicators.GetIndicator<myTrend>(60, 1.9, .6);Whereas, the myTrend default parameters are: 240, 0.8,0.05
ok yes, I used the correct parameters for the indicator as in the robot (60,1.9,.6) If you look at 3/7/13 at 8am the indicator shows 0 or ranging but the print statement in the robot shows -1 or down trend.
Realize I simplified the robot so you could troubleshoot the issue but it does more stuff than just print.
Right, so if you backtest the robot you will see print statements from the robot and the indicator and they match. But if you apply the indicator to the chart you get different results.
Capture1 shows the indicator as applied to the chart, make note of the log at time 3/7/13 8am trend is indicating 0
Now look at the Robot, Capture 1a shows the trend as -1
See what I mean??
@lec0456
lec0456
08 Mar 2013, 05:51
RE:
Do you mean the 1-minute time frame?
We plan to show the full chart with visual deals in the backtesting report in near future.
Yes, the 1 minute chart. only shows 2 weeks of data. It would be helpful if it just showed the data selected from the backtest date range
@lec0456
lec0456
20 Feb 2013, 11:20
Anyway, here is the code for one...
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, ScalePrecision = 3, AutoRescale=true)] public class myMultiMADifferential: Indicator { [Parameter(DefaultValue = 10)] public int paramLimit { get; set; } [Parameter(DefaultValue = 60)] public int MA2Periods { get; set; } [Parameter(DefaultValue = 120)] public int MA3Periods { get; set; } [Parameter(DefaultValue = 240)] public int MA4Periods { get; set; } [Output("MA1MA4Diff", PlotType = PlotType.Histogram, Thickness = 2, Color = Colors.Purple)] public IndicatorDataSeries MA1MA4Diff { get; set; } [Output("MA1MA3Diff", PlotType = PlotType.Line, Thickness = 1, Color = Colors.MediumPurple)] public IndicatorDataSeries MA1MA3Diff { get; set; } [Output("MA1MA2Diff", PlotType = PlotType.Line, Thickness = 2, Color = Colors.Yellow)] public IndicatorDataSeries MA1MA2Diff { get; set; } [Output("MA2MA4Diff", PlotType = PlotType.Line, Thickness = 1, Color = Colors.Navy)] public IndicatorDataSeries MA2MA4Diff { get; set; } [Output("MA2MA3Diff", PlotType = PlotType.Line, Thickness = 2, Color = Colors.Blue)] public IndicatorDataSeries MA2MA3Diff { get; set; } [Output("MA3MA4Diff", PlotType = PlotType.Line, Thickness = 2, Color = Colors.Red)] public IndicatorDataSeries MA3MA4Diff { get; set; } [Output("UpperLimit", PlotType = PlotType.Line, LineStyle=LineStyle.DotsRare,Thickness = 1, Color = Colors.Red)] public IndicatorDataSeries UpperLimit { get; set; } [Output("LowerLimit", PlotType = PlotType.Line, LineStyle=LineStyle.DotsRare, Thickness = 1, Color = Colors.Red)] public IndicatorDataSeries LowerLimit { get; set; } private LinearRegressionForecast linreg; private SimpleMovingAverage MA1; private SimpleMovingAverage MA2; private SimpleMovingAverage MA3; private SimpleMovingAverage MA4; protected override void Initialize() { linreg= Indicators.LinearRegressionForecast(MarketSeries.Open,9); MA1= Indicators.SimpleMovingAverage(linreg.Result,5); MA2 = Indicators.SimpleMovingAverage(MarketSeries.Open,MA2Periods); MA3 = Indicators.SimpleMovingAverage(MarketSeries.Open,MA3Periods); MA4 = Indicators.SimpleMovingAverage(MarketSeries.Open,MA4Periods); } public override void Calculate(int index) { if(double.IsNaN(MA1.Result[index]))return; //** skip printing bar until moving average data is calculated if(double.IsNaN(MA2.Result[index]))return; if(double.IsNaN(MA3.Result[index]))return; if(double.IsNaN(MA4.Result[index]))return; double MA1_MA2=Math.Round((MA1.Result[index]-MA2.Result[index])/Symbol.PipSize,3); // Difference double MA1_MA3=Math.Round((MA1.Result[index]-MA3.Result[index])/Symbol.PipSize,3); double MA1_MA4=Math.Round((MA1.Result[index]-MA4.Result[index])/Symbol.PipSize,3); double MA2_MA3=Math.Round((MA2.Result[index]-MA3.Result[index])/Symbol.PipSize,3); // Difference double MA2_MA4=Math.Round((MA2.Result[index]-MA4.Result[index])/Symbol.PipSize,3); double MA3_MA4=Math.Round((MA3.Result[index]-MA4.Result[index])/Symbol.PipSize,3); // Difference UpperLimit[index]=paramLimit; LowerLimit[index]=-paramLimit; MA1MA4Diff[index]=MA1_MA4; MA1MA2Diff[index]=MA1_MA2; MA2MA3Diff[index]=MA2_MA3; MA1MA3Diff[index]=MA1_MA3; MA3MA4Diff[index]=MA3_MA4; MA2MA4Diff[index]=MA2_MA4; } } }
@lec0456
lec0456
20 Feb 2013, 11:17
RE:
Hello,
You may send us the code so that we can investigate it at engage@ctrader.com.
Its not the code its all my custom indicators that are not Overlays. I also tryed pulling it up from other broker platforms and I get the same thing, a blank indicator...
@lec0456
lec0456
20 Feb 2013, 06:25
RE:
Recently, the indicators that I built will compile and work with the instance attached to the indicator. But when I try to select the indicator from the custom indicator list in ctrader or one of the other instances in cAlgo, it will not work??
Any ideas what is going on?
Correction, overlay indicators work. histogram indicators or indicators where IsOverlay =false will not work
@lec0456
lec0456
19 Dec 2012, 08:13
RE:
Well, what you are saying then is that on the current bar then the SMA will be changing with the close. When I put my cursor over the very last bar it is changing with the close. however, this is the instability I am refering to. On mySma the sma at T is the previous close if you use 1 period.
So,I am asking, At any time T, should the MA consist of the previous x closing prices or should it include the the current closing price which is still unknown during live execution?
I would really apprieciate if you would explain this...
@lec0456
lec0456
16 Dec 2012, 07:12
Here is a robot to test the indicator
Remember you have to put the print statement in the indicator!
//#reference: C:\Users\<yourpath>\Documents\cAlgo\Sources\Indicators\Sample SMA.algo // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot] public class TestIndicatorBot : Robot { private SampleSMA sma; protected override void OnStart() { sma = Indicators.GetIndicator<SampleSMA>(MarketSeries.Close,10); } protected override void OnBar() { if (Trade.IsExecuting) return; //** Indicator calculations and Analysis int t0 = MarketSeries.Close.Count-1;//** t0 results are not final because the bar has not completed int t1 = t0 - 1; if(t1<0)return;//** prevent crash caused by posibly using a negetive index value DateTime opentime = MarketSeries.OpenTime[t0]; double MA1t1 = sma.Result[t0]; double MA1t2 = sma.Result[t1]; Print("{0,20}{1,20}{2,20}{3,20}{4,20}",opentime,t0,MA1t1,MA1t2,"OnBar"); } }//** End of class ********* }//** End of namespace *********
@lec0456
lec0456
13 Mar 2013, 18:33
Oh, the only thing I changed, obviously, was removing the IsRealTime statment in order to backtest
@lec0456