Topics
26 Sep 2017, 23:41
 1793
 3
22 Jun 2016, 16:31
 3414
 6
16 Jun 2016, 23:37
 2582
 8
Replies

kaliszczak1991
27 Sep 2017, 00:07

Small change, I don't want to get high-low, but open-close


@kaliszczak1991

kaliszczak1991
22 Jun 2016, 18:27

tmc, I was trying to put it into the robot but it doesn't work.

I have to crate a new parameter, but I don't know how. 

 

 

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 Buyrsi : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", DefaultValue = 25)]
        public int Periods { 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 OnBar()
        {

            if (rsi.Result.LastValue > 50)
            {
                Open(TradeType.Sell);
            }
            if (rsi.Result.LastValue < 50)
            {
                Open(TradeType.Buy);
            }

            if (rsi.Result.LastValue < 50)
            {
                Close(TradeType.Sell);
            }
            if (rsi.Result.LastValue > 50)
            {
                Close(TradeType.Buy);
            }

        }

        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");
        }
    }
}


@kaliszczak1991

kaliszczak1991
18 Jun 2016, 05:58

Great, that was that :) Thank you very much :)

But I have last question.
Is there an option to set that robot to works only in some hours, lets say during London session?

I download all the robots avaible, and I couldn't find this option. 

Could you help me with it?

I will be gratefull :)


@kaliszczak1991

kaliszczak1991
17 Jun 2016, 00:34

Can you help me with one another think?

Could you tell me what is wrong? Because robot only open Sell positions, why its not open Buy position?

 

 

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 OnBar()
        {
            if (rsi.Result.LastValue > 70)
            {
                Open(TradeType.Buy);
            }
            else if (rsi.Result.LastValue < 30)
            {
                Open(TradeType.Sell);
            }
            else if (rsi.Result.LastValue > 30)
            {
                Close(TradeType.Sell);
            }
            else if (rsi.Result.LastValue < 70)
            {
                Close(TradeType.Buy);
            }
        }

        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");
        }
    }
}


@kaliszczak1991

kaliszczak1991
16 Jun 2016, 23:54

Thanks TMC :)

 

That was sooo easy


@kaliszczak1991