how to put parameters on volume oscillators?

Created at 19 Feb 2021, 13:58
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!
SA

samuel.jus.cornelio

Joined 19.03.2020

how to put parameters on volume oscillators?
19 Feb 2021, 13:58


 

I am trying to put a negative parameter on the volume oscillator. but BOT has not ignored the command lines. How can I fix the problem?

 

 

The bot executes sales, when the volume oscillator is at levels higher than the programmed

 

   if (_vol1.Result.LastValue < -10)
                        if (_vol2.Result.LastValue < -10)

 

_lastTrade = Server.Time;
            if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
                if (Positions.Count == 0)

                    ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "bot", StopLoss, TakeProfit);


@samuel.jus.cornelio
Replies

PanagiotisCharalampous
19 Feb 2021, 15:59

Hi samuel.jus.cornelio,

Please provide the complete source code and steps to reproduce the problem.

Best Regards,

Panagiotis 

Join us on Telegram 

 


@PanagiotisCharalampous

samuel.jus.cornelio
19 Feb 2021, 18:37

RE:

PanagiotisCharalampous said:

Hi samuel.jus.cornelio,

Please provide the complete source code and steps to reproduce the problem.

Best Regards,

Panagiotis 

Join us on Telegram 

 

Ok, 

 

 

 

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.ESouthAmericaStandardTime, AccessRights = AccessRights.None)]
    public class bot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Source")]
        public DataSeries Source { get; set; }

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

        [Parameter("Stop Loss (pips)", DefaultValue = 35, MinValue = 10)]
        public double StopLoss { get; set; }

        [Parameter("Take_Profit", DefaultValue = 30, MinValue = 10)]
        public double TakeProfit { get; set; }

        [Parameter("Start Hour", DefaultValue = 6.0)]
        public double StartTime { get; set; }

        [Parameter("Stop Hour", DefaultValue = 14.0)]
        public double StopTime { get; set; }


        private bool _todaysOrderExecuted;
        DateTime _lastTrade;

        private DateTime _startTime;
        private DateTime _stopTime;

  private VolumeOscillator _vol1;
        private VolumeOscillator _vol2;
        private UltimateOscillator _ult1;





        protected override void OnStart()
        {
            _startTime = Server.Time.Date.AddHours(StartTime);


            _stopTime = Server.Time.Date.AddHours(StopTime);


            _lastTrade = Server.Time.AddDays(-1);

            var currentHours = Server.Time.TimeOfDay.TotalHours;
            bool tradeTime = StartTime < StopTime ? currentHours > StartTime && currentHours < StopTime : currentHours < StopTime || currentHours > StartTime;


            if (!tradeTime && _todaysOrderExecuted)
            {
                _todaysOrderExecuted = false;
            }
        }




        protected override void OnTick()
        {

            var hour1 = MarketData.GetBars(TimeFrame.Hour);
            var day = Server.Time.DayOfWeek;

   _vol1 = Indicators.VolumeOscillator(hour1, 6, 6);
            _vol2 = Indicators.VolumeOscillator(hour1, 3, 15);
            _ult1 = Indicators.UltimateOscillator(hour1, 3, 3, 5);




            if (Trade.IsExecuting)
                return;

            var currentHours = Server.Time.TimeOfDay.TotalHours;
            bool tradeTime = StartTime < StopTime ? currentHours > StartTime && currentHours < StopTime : currentHours < StopTime || currentHours > StartTime;

            if (!tradeTime)
                return;

   if (_vol1.Result.LastValue > 200)
                        if (_vol2.Result.LastValue > 200)
                            if (_ult1.Result.LastValue > 60)

 

     _lastTrade = Server.Time;

            if (_lastTrade.DayOfYear != Server.Time.DayOfYear)
                if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
                    if (Positions.Count == 0)


                        ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "bot", StopLoss, TakeProfit);

 

if (_vol1.Result.LastValue < -200)
                            if (_vol2.Result.LastValue < -200)

  if (_ult1.Result.LastValue < 40)

  _lastTrade = Server.Time;
                if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday)
                    if (Positions.Count == 0)

                        ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "bot", StopLoss, TakeProfit);


@samuel.jus.cornelio

PanagiotisCharalampous
22 Feb 2021, 08:04

Hi samuel.jus.cornelio,

How do we reproduce the problem? Where do we need to backtest this and what parameters shall we use?

Best Regards,

Panagiotis 

Join us on Telegram 


@PanagiotisCharalampous