Topics
28 Jun 2016, 12:30
 1883
 3
Replies

emmamail
01 Feb 2017, 12:15

hi

Hello Lucia,

 

I want assistance if  you can assist with adding  the three bar exit to the below RSI mean reverting strategy;

 

// -------------------------------------------------------------------------------------------------
//
//    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 SampleRSIRobot : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }
 
        [Parameter("Periods", DefaultValue = 14)]
        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 < 30)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (rsi.Result.LastValue > 70)
            {
                Close(TradeType.Buy);
                Open(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");
        }
    }
}

 


@emmamail

emmamail
31 Jan 2017, 18:38

thanks

Hi Lucian,

 

Thanks for your assistance .. i will add your code and revert to you.

 

Thanks once again.

 

Emmanuel


@emmamail

emmamail
26 Jan 2017, 18:41

RE:

lucian said:

I am sorry, but I don't understand what do you want exactly by " three price bars"

You can use OnBar() by example:

 

 protected override void OnBar()
        {
            int index = MarketSeries.Close.Count - 1;
            if (MarketSeries.Close[index - 1] > MarketSeries.Close[index - 2])
            {
                foreach (var position in Positions)
                    ClosePosition(position);
            }
        }

 

Hi Lucian,

 

What i mean is to close my open position on three candles.

 

thanks.

 

emmanuel.


@emmamail

emmamail
29 Jun 2016, 19:03

RE: RE:

Thanks: moneybiz

emmamail said:

Hello Support,

 

Please I need a code to start two cbot ,can that be possible ?

 

Emmanuel

There is no code to start 2 bots. But if you have their source code you can combine them under a 3rd bot which will feed the tick data to both of them.
If those 2 bots don't need to communicate with each other you can add 2 instances of the bot and start them manually.

 


@emmamail