Help building simple rsi system

Created at 02 May 2015, 13:34
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!
DO

DontAlgoMe

Joined 02.05.2015

Help building simple rsi system
02 May 2015, 13:34


So I have no knowledge of coding and Im just trying to figure it out based on the sample bots.

I want a bot that opens a buy position when rsi < 15 and open a sell position when rsi > 85. I want to have a 10 pip stop on my positions, and I want the positions to close when RSI reverts to 50.

 

This is what I ended up with tampering with the code... I dont think its working because adjusting values doesnt change my backtesting results. So Im pretty sure I butchered the language.

 

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

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

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

        [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
        public int Volume { get; set; }
        
        [Parameter("Inital Stop Loss (pips)", DefaultValue = 10.0)]
        public int init_StopLoss { get; set; }

        private RelativeStrengthIndex rsi;

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

        protected override void OnTick()
        {
            if (rsi.Result.LastValue = 50)
            {
                Close(TradeType.Sell);
               
            if (rsi.Result.LastValue < 15)
            {
               Open(TradeType.Buy,PlaceStopOrder)            
            }
            else if (rsi.Result.LastValue = 50)
            {
                Close(TradeType.Buy);
               
            if (rsi.Result.LastValue > 85)
            {Open(TradeType.Sell,PlaceStopOrder)
            
           }
            
        

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


@DontAlgoMe
Replies

DontAlgoMe
02 May 2015, 17:01

RE:

I would also like to be able to set profit targets based on pips that close the position rather than the rsi value, to see which works better.

 


@DontAlgoMe

Spotware
18 Jun 2015, 12:54

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.

 


@Spotware

JeremyG
27 Jun 2015, 18:33

RE: RE:

Hey, you're really gonna have to devote time to learning the basics of c# and cAlgo (the language and the program) and do a lot of testing and tweaking of your strategy.

Watch youtube videos, read the microsoft help files, read through this forum, keep breaking and fixing the reference cBots. Start with very simple building blocs and add complexity from there.

Not to discourage you in any way, but I can absolutely promise you that your current strategy won't work without a fair amount of tweaking and you'll need to know how to tweak it to get it to where you want it.

Keep going, I was an absolute beginner not even two months ago and now I can code my own robots. It takes time but knowing how to code your strategies yourself is invaluable.

Sorry I can't help more specifically with the code you posted..

 

DontAlgoMe said:

I would also like to be able to set profit targets based on pips that close the position rather than the rsi value, to see which works better.

 

 


@JeremyG

JeremyG
27 Jun 2015, 18:38

RE:

A couple tips:

When using IF statements etc, you gotta use two equals signs when comparing two numbers, eg:

if (rsi.Result.LastValue == 50)

Another problem is that your position's won't work if RSI passes over 50 but was never exactly 50.

 

DontAlgoMe said:

So I have no knowledge of coding and Im just trying to figure it out based on the sample bots.

I want a bot that opens a buy position when rsi < 15 and open a sell position when rsi > 85. I want to have a 10 pip stop on my positions, and I want the positions to close when RSI reverts to 50.

 

This is what I ended up with tampering with the code... I dont think its working because adjusting values doesnt change my backtesting results. So Im pretty sure I butchered the language.

 

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

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

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

        [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
        public int Volume { get; set; }
        
        [Parameter("Inital Stop Loss (pips)", DefaultValue = 10.0)]
        public int init_StopLoss { get; set; }

        private RelativeStrengthIndex rsi;

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

        protected override void OnTick()
        {
            if (rsi.Result.LastValue = 50)
            {
                Close(TradeType.Sell);
               
            if (rsi.Result.LastValue < 15)
            {
               Open(TradeType.Buy,PlaceStopOrder)            
            }
            else if (rsi.Result.LastValue = 50)
            {
                Close(TradeType.Buy);
               
            if (rsi.Result.LastValue > 85)
            {Open(TradeType.Sell,PlaceStopOrder)
            
           }
            
        

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

 


@JeremyG

JeremyG
27 Jun 2015, 18:41

RE: RE:

I meant to say your positions won't CLOSE if RSI passes over 50 but was never exactly 50.

JeremyG said:

A couple tips:

When using IF statements etc, you gotta use two equals signs when comparing two numbers, eg:

if (rsi.Result.LastValue == 50)

Another problem is that your position's won't work if RSI passes over 50 but was never exactly 50.

 

DontAlgoMe said:

So I have no knowledge of coding and Im just trying to figure it out based on the sample bots.

I want a bot that opens a buy position when rsi < 15 and open a sell position when rsi > 85. I want to have a 10 pip stop on my positions, and I want the positions to close when RSI reverts to 50.

 

This is what I ended up with tampering with the code... I dont think its working because adjusting values doesnt change my backtesting results. So Im pretty sure I butchered the language.

 

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

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

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

        [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
        public int Volume { get; set; }
        
        [Parameter("Inital Stop Loss (pips)", DefaultValue = 10.0)]
        public int init_StopLoss { get; set; }

        private RelativeStrengthIndex rsi;

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

        protected override void OnTick()
        {
            if (rsi.Result.LastValue = 50)
            {
                Close(TradeType.Sell);
               
            if (rsi.Result.LastValue < 15)
            {
               Open(TradeType.Buy,PlaceStopOrder)            
            }
            else if (rsi.Result.LastValue = 50)
            {
                Close(TradeType.Buy);
               
            if (rsi.Result.LastValue > 85)
            {Open(TradeType.Sell,PlaceStopOrder)
            
           }
            
        

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

 

 


@JeremyG