RSI range bot (80-40) backtesting help

Created at 15 Oct 2016, 17:48
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!
DE

derekszyszka

Joined 15.10.2016

RSI range bot (80-40) backtesting help
15 Oct 2016, 17:48


Hi there

I have been playing around with /algos/cbots/show/403

Set to, EUR/USD 1 min, 6 period RSI, 1k starting capital w/ 10000 units, set to the below perimeters 

             if (rsi.Result.LastValue > 80)
            {
                Open(TradeType.Sell);
            }
            else if (rsi.Result.LastValue < 40)
            {
                Close(TradeType.Sell);

The process behind this cBot is to sell above 80 and close below 40, taking the very top portion of a movement swing. On paper, this makes sense.

If you look at the deal map in the picture below I honestly can not understand how each trade is tested, how cAlgo manages to close RANDOMLY above a candlestick doesn't make any sense. Also, the built in stop loss does not work.

Am I doing something wrong, is this a bad coded cbot, perhaps there is an issue withe cAlgo? Thoughts and opinions welcome.


@derekszyszka
Replies

derekszyszka
15 Oct 2016, 18:39

Sorry, here is the complete code, have a look

// -------------------------------------------------------------------------------------------------
//
//    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 RSI Range Robot" will create a buy order when the Relative Strength Index indicator crosses the  level 30, 
//    and a Sell order when the RSI indicator crosses the level 70. The order is closed be either a Stop Loss, defined in 
//    the "Stop Loss" parameter, or by the opposite RSI crossing signal (buy orders close when RSI crosses the 70 level 
//    and sell orders are closed when RSI crosses the 30 level). 
//
//    The robot can generate only one Buy or Sell order at any given time.
//
// -------------------------------------------------------------------------------------------------

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RSIRange20_30 : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", DefaultValue = 6)]
        public int Periods { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 10, MinValue = 1)]
        public int StopLoss { get; set; }

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

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }

        protected override void OnTick()
        {
            if (rsi.Result.LastValue > 80)
            {
                Open(TradeType.Sell);
            }
            else if (rsi.Result.LastValue < 30)
            {
                Close(TradeType.Sell);
            }
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("SampleRSI", Symbol, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("SampleRSI", Symbol, tradeType);

            if (position == null)
                ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI");
        }
    }
}

 


@derekszyszka

croucrou
20 Oct 2016, 21:57

It seems to be closing sell positions, when the RSI goes below the set level of 30 as has been coded.

The indicator might repaint, so it's possible not to see the exact same values after time.

Don't bother with the deal map lines, if the closing prices are correct.

The stop loss is not "built in". It does not work, because it has not been applied to the execution line.


@croucrou

... Deleted by UFO ...