Replies

isakov2
18 Aug 2016, 09:04

RE: RE:

1007601 said:

isakov2 said:

I dont have any expirience with programing, but i am trying a lot of time to comlete this cbot, but somthing wrong. take a look.thanks

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

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

        [Parameter("Take Profit", DefaultValue = 15)]
        public int TakeProfit { get; set; }

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

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

        [Parameter("BandPeriods", DefaultValue = 20)]
        public int BandPeriod { get; set; }
        [Parameter("Std", DefaultValue = 3)]
        public int std { get; set; }
        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Max Spread", DefaultValue = 5.0)]
        public double MaxSpread { get; set; }

        [Parameter("Buy", DefaultValue = true)]
        public bool Buy { get; set; }

        [Parameter("Sell", DefaultValue = true)]
        public bool Sell { get; set; }

        private RelativeStrengthIndex rsi;
        private BollingerBands boll;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, RSIPeriods);
            boll = Indicators.BollingerBands(Source, BandPeriod, std, MAType);
        }

        protected override void OnTick()
        {
        
            if ((rsi.Result.LastValue < 30) && (Symbol.Bid < boll.Bottom.LastValue))
            {
                Print("****4****");
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume);
            }
            else if ((rsi.Result.LastValue > 70) && (Symbol.Ask > boll.Top.LastValue))
            {
                Print("****5****");
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume);
            }
        }
        protected override void OnStop()
        {
            Print("****3****");
        }

    }
}

You could try changing "OnTick" to "OnBar"

 

Then also the "if" lines could read something like this:

bool a1 = rsi.Result.Last(1) < 30;

bool a2 = MarketSeries.Close.Last(1) < boll.Bottom.Last(1);

bool b1 = rsi.Result.Last(1) > 70;

bool b2 = MarketSeries.Close.Last(1) > boll.Top.Last(1);

if (a1 & a2)

{

  // do your thing in here

}

if (b1 & b2)

{

//ditto 

}

 

---  

I didn't try the onTick method, but you might find you're entering a crazy number of trades that way.  OnBar will make it happen once per time period.  

Hope this helps!

 

 

Thank you dear friend, i will code it and test, its seem to be good code. i will back with conclusion : )


@isakov2