how do not open positios on saturdays?

Created at 14 May 2019, 21:47
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!
NE

nelson.pmf.sc

Joined 07.02.2019

how do not open positios on saturdays?
14 May 2019, 21:47


Please, someone coud help me to improve the code below to not open positions on saturdays.

I'm newbie but I swear that I have studied a lot ... but I could not figure out how to do this.... thanks

 

COde ...

 

using System.Linq;

using cAlgo.API;

using System.IO;

using System.Collections;

using System.Collections.Generic;

using cAlgo.API.Indicators;

using cAlgo.API.Internals;

using cAlgo.Indicators;

 

namespace cAlgo

{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]

    public class MACD : Robot

    {

 

        [Parameter("Volume", DefaultValue = 1000)]

        public int volume { get; set; }

 

        [Parameter(DefaultValue = 52, MinValue = 1)]

        public int StopLoss { get; set; }

 

        [Parameter(DefaultValue = 58, MinValue = 1)]

        public int TakeProfit { get; set; }

 

 

        [Parameter("MACD LongCycle", DefaultValue = 43, MinValue = 1)]

        public int LongCycle { get; set; }

 

        [Parameter("MACD ShortCycle", DefaultValue = 10, MinValue = 1)]

        public int ShortCycle { get; set; }

 

        [Parameter("MACD Period", DefaultValue = 10, MinValue = 1)]

        public int MACDPeriod { get; set; }

 

        private MacdCrossOver _MACD;

       

protected override void OnBar()

        {

            if (Positions.Count < 20)

            {

                var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

 

                _MACD = Indicators.MacdCrossOver(dailySeries.Close, LongCycle, ShortCycle, MACDPeriod);

 

                if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)

                {

                    ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);

                }

 

                if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)

                {

                    ExecuteMarketOrder(TradeType.Sell, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);

                }

            }

        }

        protected override double GetFitness(GetFitnessArgs args)

        {

            //maximize count of winning trades and minimize count of losing trades

            return args.WinningTrades / args.LosingTrades;


@nelson.pmf.sc
Replies

PanagiotisCharalampous
15 May 2019, 09:14

Hi nelson.pmf.sc,

You can try something like this

        protected override void OnBar()
        {
            if (Server.Time.DayOfWeek == DayOfWeek.Saturday)
                return;

Best Regards,

Panagiotis


@PanagiotisCharalampous

nelson.pmf.sc
15 May 2019, 17:14

RE:

Panagiotis Charalampous said:

Hi nelson.pmf.sc,

You can try something like this

        protected override void OnBar()
        {
            if (Server.Time.DayOfWeek == DayOfWeek.Saturday)
                return;

Best Regards,

Panagiotis

Thanks once again Panagiotis.

When I added this complement; the following message shows up : "Error CS0103: The name 'DayOfWeek' does not exists in the atual context"

Could you give me an additional hand?

 


@nelson.pmf.sc

Waxy
15 May 2019, 20:04

Add the namespace System.
 

using System;

 


@Waxy