cBot DSSBresset

Created at 25 Apr 2019, 09:40
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!
jamespeterwilkinson's avatar

jamespeterwilkinson

Joined 23.02.2019

cBot DSSBresset
25 Apr 2019, 09:40


Good day,

The current trade condition for buy is (Functions.IsRising(_DSSBressert.DSS))

would like to add the following condition to buy:

(_DSSBressert.DSS.LastValue > 40) and also (_DSSBressert.DSS.LastValue < 80) 

all 3 conditions must be true for buy conditions

The current trade condition for sell is (Functions.IsFalling(_DSSBressert.DSS))

would like to add the following condition to sell: 

(_DSSBressert.DSS.LastValue < 60) and also (_DSSBressert.DSS.LastValue > 20) 

all 3 conditions must be true for buy conditions

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 cBot : Robot
    {
        //DSSBressert indicator parameters
        [Parameter("Stochastic period", DefaultValue = 13)]
        public int Stochastic_Period { get; set; }
        [Parameter("EMA period", DefaultValue = 8)]
        public int EMA_Period { get; set; }
        [Parameter("WMA period", DefaultValue = 8)]
        public int WMA_Period { get; set; }

        //Trade position parameters
        [Parameter("Stop Loss", DefaultValue = 10)]
        public int StopLoss { get; set; }
        [Parameter("Take Profit", DefaultValue = 20)]
        public int TakeProfit { get; set; }
        [Parameter("Slippage", DefaultValue = 0.1)]
        public int Slippage { get; set; }
        [Parameter("Volume In Units", DefaultValue = 1000)]
        public double volumeInUnits { get; set; }
        [Parameter(DefaultValue = 1, MinValue = 1)]
        public int MaxPositions { get; set; }
        //Trade pause start stop parameters
        [Parameter("Start Time", DefaultValue = "02:00")]
        public string StartTime { get; set; }
        [Parameter("Stop Time", DefaultValue = "22:00")]
        public string StopTime { get; set; }

        private DSSBressert _DSSBressert;

        protected override void OnStart()
        {
            _DSSBressert = Indicators.GetIndicator<DSSBressert>(Stochastic_Period, EMA_Period, WMA_Period);
        }

        protected override void OnBar()
        {

            if (Positions.Count < MaxPositions)
            {
                var tradingStarts = TimeSpan.ParseExact(StartTime, "hh\\:mm", null);
                var tradingStops = TimeSpan.ParseExact(StopTime, "hh\\:mm", null);
                if (Server.Time.TimeOfDay >= tradingStarts && Server.Time.TimeOfDay < tradingStops)



                    if (Functions.IsRising(_DSSBressert.DSS))
                        ExecuteMarketOrder(TradeType.Buy, Symbol, volumeInUnits, "cBot", StopLoss, TakeProfit, Slippage, "this is a comment");

                if (Functions.IsFalling(_DSSBressert.DSS))
                    ExecuteMarketOrder(TradeType.Sell, Symbol, volumeInUnits, "cBot", StopLoss, TakeProfit, Slippage, "this is a comment");

            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 

 

 

 

 

 

 


@jamespeterwilkinson