Sample STOCHASTIC free

Description

This Cbot use STOCHASTIC indicator to Trade.

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
´╗┐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 DragonStochastic : Robot
    {

        [Parameter(" Volume Percent", DefaultValue = 1, MinValue = 0)]
        public double VolumePercent { get; set; }

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

        [Parameter("K Slowing", DefaultValue = 3)]
        public int kSlowing { get; set; }

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

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }


        [Parameter("UP Level", DefaultValue = 80)]
        public int Up_Level { get; set; }

        [Parameter("Down Level", DefaultValue = 20)]
        public int Down_Level { get; set; }


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

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



        private StochasticOscillator _stochastic;

        protected override void OnStart()
        {
            _stochastic = Indicators.StochasticOscillator(kPeriods, kSlowing, dPeriods, maType);
        }


        protected override void OnBar()
        {
            var volumne = Math.Floor(Account.Balance * 10 * VolumePercent / 1000) * 1000;
            if (_stochastic.PercentK.Last(2) > _stochastic.PercentD.Last(2) && _stochastic.PercentK.Last(1) < _stochastic.PercentD.Last(1))
            {
                Print("_stochastic.PercentD.Last(1) {0}", _stochastic.PercentD.Last(1));
                Print("_stochastic.PercentD.Last(2) {0}", _stochastic.PercentD.Last(2));
                if (_stochastic.PercentD.Last(2) > Up_Level && _stochastic.PercentK.Last(2) > Up_Level)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volumne, "DragonStochastic", StopLoss, TakeProfit);
                }

            }

            if (_stochastic.PercentK.Last(2) < _stochastic.PercentD.Last(2) && _stochastic.PercentK.Last(1) > _stochastic.PercentD.Last(1))
            {
                Print("_stochastic.PercentD.Last(1) {0}", _stochastic.PercentD.Last(1));
                Print("_stochastic.PercentD.Last(2) {0}", _stochastic.PercentD.Last(2));
                if (_stochastic.PercentD.Last(2) < Down_Level && _stochastic.PercentK.Last(2) < Down_Level)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumne, "DragonStochastic", StopLoss, TakeProfit);
                }

            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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