Replies

michaelocampo1104@gmail.com
17 Jan 2020, 04:00

RE: RE: HI All, much appreciate on your help below

michaelocampo1104@gmail.com said:

Dear Panagoitis

Please see below my draft code or should i do it on the indicator itself? if so does the IsLast bar can do the job?

Thank you in advance.

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 SuperTrendBot : Robot
    {
        #region Declarations

        private Supertrend _supertrend;
        
        #endregion

        #region Indicator Parameters

        //Super Trend
        [Parameter("STPeriod", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter("SuperTrend Multiplier", DefaultValue = 3)]
        public int Multiplier { get; set; }

        #endregion

        //SuperTrend
        #region Indicator Output
        [Output("UpTrend")]
        public IndicatorDataSeries UpTrend { get; set; }

        [Output("Downtrend")]
        public IndicatorDataSeries DownTrend { get; set; }


        #endregion

        #region Risk management
        [Parameter("Stop Loss", DefaultValue = 30)]
        public double _SL { get; set; }

        [Parameter("Take Profit", DefaultValue = 60)]
        public double _TP { get; set; }

        private int _volume;

        #endregion

        #region Initialize
        protected override void OnStart()
        {

            _supertrend = Indicators.GetIndicator<Supertrend>(Period, Multiplier);

        }

        #endregion

        #region Bot Logic
        protected override void OnBar()
        {

 

            if (!double.IsNaN(_supertrend.UpTrend.LastValue))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, _volume, "Buy1", _SL, _TP);
             
            }

            if (!double.IsNaN(_supertrend.DownTrend.LastValue))
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, _volume, "Sell1", _SL, _TP);
               
            }

        }
        #endregion

        

        protected override void OnTick()
        {

           

        }

        #region On Stop
        protected override void OnStop()
        {
          
        }
        #endregion 

}

 

 

PanagiotisCharalampous said:

Hi there,

Yes this is possible. You need to detect at which bar does the trend change happen.

Best Regards,

Panagiotis 

Join us on Telegram

 

 

 

 


@michaelocampo1104@gmail.com

michaelocampo1104@gmail.com
07 Jan 2020, 09:05

RE:

Dear Panagoitis

Please see below my draft code or should i do it on the indicator itself? if so does the IsLast bar can do the job?

Thank you in advance.

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 SuperTrendBot : Robot
    {
        #region Declarations

        private Supertrend _supertrend;
        
        #endregion

        #region Indicator Parameters

        //Super Trend
        [Parameter("STPeriod", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter("SuperTrend Multiplier", DefaultValue = 3)]
        public int Multiplier { get; set; }

        #endregion

        //SuperTrend
        #region Indicator Output
        [Output("UpTrend")]
        public IndicatorDataSeries UpTrend { get; set; }

        [Output("Downtrend")]
        public IndicatorDataSeries DownTrend { get; set; }


        #endregion

        #region Risk management
        [Parameter("Stop Loss", DefaultValue = 30)]
        public double _SL { get; set; }

        [Parameter("Take Profit", DefaultValue = 60)]
        public double _TP { get; set; }

        private int _volume;

        #endregion

        #region Initialize
        protected override void OnStart()
        {

            _supertrend = Indicators.GetIndicator<Supertrend>(Period, Multiplier);

        }

        #endregion

        #region Bot Logic
        protected override void OnBar()
        {

 

            if (!double.IsNaN(_supertrend.UpTrend.LastValue))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, _volume, "Buy1", _SL, _TP);
             
            }

            if (!double.IsNaN(_supertrend.DownTrend.LastValue))
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, _volume, "Sell1", _SL, _TP);
               
            }

        }
        #endregion

        

        protected override void OnTick()
        {

           

        }

        #region On Stop
        protected override void OnStop()
        {
          
        }
        #endregion 

}

 

 

PanagiotisCharalampous said:

Hi there,

Yes this is possible. You need to detect at which bar does the trend change happen.

Best Regards,

Panagiotis 

Join us on Telegram

 

 

 


@michaelocampo1104@gmail.com

michaelocampo1104@gmail.com
04 Dec 2019, 14:48

RE:

Hi  Panagiotis

Thank you for your help I got it working now

PanagiotisCharalampous said:

From what I can see in the indicator code, you need to check the last value of DownTrend/UpTrend. If it is not NaN then the indicator is trending into that Direction. So the conditions should look like the below

            if (!double.IsNaN(_supertrend.DownTrend.LastValue))
            {
                //Close buy and open sell
            }

            if (!double.IsNaN(_supertrend.UpTrend.LastValue))
            {
                //Close sell and open buy
            }

Best Regards,

Panagiotis 

Join us on Telegram

 


@michaelocampo1104@gmail.com

michaelocampo1104@gmail.com
04 Dec 2019, 09:59

RE:

PanagiotisCharalampous said:

Hi there,

I cannot see where is the problem. Can you please elaborate?

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

Thanks for your prompt response,

the cbots built successfully 

However the intend is that the cbots should buy on uptrend signal and cancel/open sell position if receive  downtrend signal

 

 


@michaelocampo1104@gmail.com