Topics
06 Jun 2019, 17:34
 1212
 3
16 May 2019, 04:33
 1465
 3
08 May 2019, 00:41
 1203
 3
07 May 2019, 13:26
 1072
 1
26 Apr 2019, 04:45
 1707
 5
24 Apr 2019, 21:34
 1085
 1
Replies

lec0456
24 Oct 2018, 08:55

RE:

lec0456 said:

I created a subclass to encapsulate all the indicator data that I send to a database. I tried using inheritance  with :Robot or <RobotName> and it complies but i get an exception error.

I passed in the Robot object and used this. to do it. It works for the Market series but it can not access the individual indicators. isthere a way to access the indicators of a Robot from within a subclass? I would prefer to not pass tham all in.

I solved my own problem.  All you hear is crickets from this forum. I passed in the Name of the cBot to the method in the subclass, no inheritance was needed. Got access to all indicators, marketseries, etc.


@lec0456

lec0456
24 Oct 2018, 08:51

Can you use the chart Object in backtesting yet? Users have been asking for that for 6 years.


@lec0456

lec0456
23 Oct 2018, 06:07

I created a subclass to encapsulate all the indicator data that I send to a database. I tried using inheritance  with :Robot or <RobotName> and it complies but i get an exception error.

I passed in the Robot object and used this. to do it. It works for the Market series but it can not access the individual indicators. isthere a way to access the indicators of a Robot from within a subclass? I would prefer to not pass tham all in.


@lec0456

lec0456
02 Oct 2018, 12:25

I want its value when I roll over the chart but i don't want it to take up chart space.  i would also like to be able to expose the value to a robot. 

 

For example:

rsi.Result2[index];

 

But I don't want Result2 to be plotted because it is not on the same scale as the main indicator.


@lec0456

lec0456
25 Sep 2018, 23:21

There used to be sample code for all major indicators in the samples section of the forum. RSI, Stocastic, bollinger bands, EMA, SMA, etc. It was very helpful to learn and tweak indicators.


@lec0456

lec0456
23 Sep 2018, 09:46

Also, even if it is correct to use the ema.  Why does the formula calculate the ema periodsd as:

var emaPeriods = 2 * paramPeriods - 1;

this would mean that instead of using 14 period ema it uses a 27 period ema to calculate a 14 period RSI

 

please verfiy and explain

 


@lec0456

lec0456
03 Jul 2018, 21:38

WWWWHAT??? You are a rockstar. I need more specifics. Can you walk me through the steps.  I didn't enevn know there was a cbotset parameters file.


@lec0456

lec0456
30 May 2018, 09:52

I agree with you as far as the left bar.  It takes up way too much valuable screen realestate.  They can easily make this selectable for top, side and bottom


@lec0456

lec0456
04 Apr 2018, 11:09

Well, problem is that that indicator is an Overlay, so If I put zeros in it, it will mess up the display.

I can survive by using the MarketSeries index. I was just trying to clean up some of my code with the newer API.

But at least I confirmed the behavior. And  that it is by design, I suggest placing a note in the API documentation so that developers know how to work with it. Or including the nan values in the series. 

It is confusing because lastvalue works fine with all the market series stuff and most indicators are based off of them. But some cases, where nan values are possible, it could take a while before figuring out the indexes are off. 


@lec0456

lec0456
03 Apr 2018, 18:19

ok, but the problem is then that the index of the indicator does not match up with the index of the robot.

 

Dayend should return a non nan value on the first bar of a new day within a cbot.  If the onBar is triggering in sync with the MarketSeries index and the indicator is using a different index the values will not matchup.  That is why if I use div.Dayend.Last(0) it will not give me the corresponding value for the specific time of day that the cBot is at.

if (!double.IsNaN(div.Dayend[MarketSeries.Close.Count - 1]))
{
    Print("****" + EESTDate(MarketSeries.OpenTime.Last(0)).Date + "*****" + EESTDate(MarketSeries.OpenTime.Last(0)).DayOfWeek.ToString());
}

The above code works fine. But if I change it to div.Dayend.Last(0) it does not work.


@lec0456

lec0456
02 Apr 2018, 17:56

The indicator is here:

/algos/indicators/show/399

Here is some code:

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

namespace cAlgo.Robots
{
    [Robot]
    public class NewRobot : Robot
    { 
        Dividers div;
        protected override void OnStart()
        {
            div = Indicators.GetIndicator<Dividers>(falsefalsefalse);
        }
        protected override void OnBar()
        {
        Print("Div:"+div.Dayend[MarketSeries.Close.Count - 1]+" "+div.Dayend.Last(0)+" "+div.Dayend.LastValue);
        }
    }
}

 


@lec0456

lec0456
02 Apr 2018, 00:54

Hi, This is a simple but important issue, can I please get a response from spotware?


@lec0456

lec0456
29 Mar 2018, 21:43

I say official because it is spotware's method to detect a cross.  Thier are other custom methods.  You just have to try it and see if it gives you the performance you are looking for. 

Here is what your code would look like. I would recomend just using the OnBar because if you want to make your decision to trade on the close of the previous bar, the open of the next bar is only one tick away.  Yes, there is a diference but 99.9% of the time these match up. If you want to get that specific then I would place the code back into the OnTick and calculate the time to close the candle.  So, if you were tradiing 15 min you would add a criteria Time_from_open.TotalMinutes>14 or doit in second if you want to get closer to the close.  But as far as I know, there is no event to trigger code on the close.  So, while you can get it close, you will never get it exact everytime.  

 

 protected override void OnBar()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
 
            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);
 
            if (fastMA.Result.HasCrossedAbove(slowMA.Result,1) && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
            }
            else if (fastMA.Result.HasCrossedBelow(slowMA.Result,1) && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
            }
        }
 
        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }

 


@lec0456

lec0456
26 Mar 2018, 13:22

Will a compiled cBot be suficient or do you require the source code?  My cBot is pretty complex, and uses several custom indicators so I would need to take out the relavant part if you need the source code.

Also, where should  I send it?


@lec0456

lec0456
26 Mar 2018, 11:36

It happened today, when it hangs, Windows kind of greys out the window and displays a spinning circle.  Pressing Ctrl+ALt+Shift +T would not work. All I could do was select the window of a separate open instance of cAlgo and hit the key combo.  I sent a link to this forum in the description box.  BU i am not sure you will get relavant info because the actual window that hangs would not do the debug routine.  Also, If I try to compile in the second instance, it will also freeze. All I cando is a full restart to get it to start compiling again. I figure maybe there is a file lock, if i atleast knew which file to manually clear maybe it would allow me to start compiling without restarting.


@lec0456

lec0456
26 Mar 2018, 11:22

So, to update. I still can not figure out why cAlgo backtest engine fails to close the trade when the price goes below the stoploss.

What I did however, was place some code to programatically close the trade if price goes below the SL.  But this code should not be necessary.

                foreach (var position in Positions)
                {
                    if (position.TradeType == TradeType.Buy && position.StopLoss != null && position.StopLoss > Symbol.Bid) ClosePosition(position);
                    if (position.TradeType == TradeType.Sell && position.StopLoss != null && position.StopLoss < Symbol.Ask) ClosePosition(position);
                }

So, the issue is why is the backtesting engine not executing trades after Stoplosses are hit? Whats going on?

You can compare the difference in the charts after I added the code to close after SL is hit:

http://roboforex.ctrader.com/c/qn06n

If i don' put the code in, cAlgo does not close the trade for an hour and 3 previous bars all cross the SL multiple times.


@lec0456

lec0456
26 Mar 2018, 11:10

Well, if I understand you correctly, to detect a cross, the official way is the following:

fastMA.Result.HasCrossedAbove(slowMA.Result, 1)

But you can always get false poitives.  in other words, it can cross and then cross back. 

So, its best to add some more criteria to the trade. Like the slope of the fast ma being above or below a certian thresh hold.

I tried out trading strategies based on ma crosses but never got very good results. Never the less, its a good place for beginers to start.

At one point I created an indicator that used the distance between the MAs before and after the cross and calculated a ratio.  I used that to give a weight to the strength of the cross.

If the cross was above a certain strength, it would execute the trade.

Also, trading crosses is a OnBar trading strategy, it does not work well OnTIck because during the course of a bar the MA can cross and cross back.  So, its a lagging indicator use have to atleast wait for the next bar to validate the cross and trigger the trade


@lec0456

lec0456
08 Mar 2018, 02:16

Not to my knowledge.  Same anoying indicator selection behavior.


@lec0456

lec0456
18 Dec 2017, 17:42

I contacted the broker and here is their response:

 

Request #227193 bad back-testing data in cTrader

Dear Louis Cespedes,

Thank you for contacting us.

Please be advised only on our MT4 there are 5 daily candles available through out the week.

In Ctrader there are 6 daily candles . This is not something we manage. We show the prices on the left, the charts are managed by cTrader developers i.e. Spotware.
you can find more info here if you wish http://help.spotware.com/interface

cTrader since Spotware starts candles at 22:00 UTC it will vary, so there is 2 hours difference between our MT4/MT5 servers .

Let us know if you require any further information.

Kind Regards,

Diana Smith | Support | IC Markets


@lec0456

lec0456
17 Dec 2017, 09:03

Further analysis shows that this continues thru May24, 2013 and does not continue in 2014 for the same period.  So, the question is if the backtesting data can be fixed for the broker. It appears that the IC Markets data is missing bars for a time period in which trading starts at this broker but does not occur at the other broker. The back test data is misplaced by 2 hrs.


@lec0456