Replies

jamespeterwilkinson
12 Mar 2019, 13:54

RE: Thank you

Panagiotis Charalampous said:

Hi James,

As the message clearly states, you need to end your region somewhere. You start your region here

        #region Indicator declarations
        private DSSBressert _DSS { get; set; }

Best Regards,

Panagiotis 

 


@jamespeterwilkinson

jamespeterwilkinson
26 Feb 2019, 12:39

RE:

Panagiotis Charalampous said:

Hi jpwtrading,

You have a wrong bracket at line 65 and lots of missing brackets at the end.

Best Regards,

Panagiotis

@Panagiotis Thank you


@jamespeterwilkinson

jamespeterwilkinson
25 Feb 2019, 19:03

RE:

Panagiotis Charalampous said:

Hi jpwtrading,

See an example below

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 CustomcBot : Robot
    {
        [Parameter(DefaultValue = 1, MinValue = 1)]
        public int MaxPositions { get; set; }

        protected override void OnStart()
        {

        }

        protected override void OnTick()
        {
            if (Positions.Count < MaxPositions)
            {
                // Do somehting
            }
        }

        protected override void OnStop()
        {

        }
    }
}

Best Regards,

Panagiotis

@Panagiotis Working Thank you!

 


@jamespeterwilkinson

jamespeterwilkinson
25 Feb 2019, 12:10 ( Updated at: 21 Dec 2023, 09:21 )

RE: Thank you

Panagiotis Charalampous said:

Hi jpwtrading,

See an example below

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 CustomcBot : Robot
    {
        [Parameter(DefaultValue = 1, MinValue = 1)]
        public int MaxPositions { get; set; }

        protected override void OnStart()
        {

        }

        protected override void OnTick()
        {
            if (Positions.Count < MaxPositions)
            {
                // Do somehting
            }
        }

        protected override void OnStop()
        {

        }
    }
}

Best Regards,

Panagiotis

Thank you for the code.

Is my application of the code correct? added another &&

if (Functions.IsRising(AwesomeOscillator.Result) && Functions.HasCrossedAbove(AwesomeOscillator.Result, MarketSeries.Close, 10) && (Positions.Count < MaxPositions))
                    ExecuteMarketOrder(TradeType.Buy, Symbol, volumeInUnits, "cBot", StopLoss, TakeProfit, Slippage, "this is a comment");

also was surprised not to find MaxPositions in the Reference Editor

Regards + thank you

James


@jamespeterwilkinson

jamespeterwilkinson
25 Feb 2019, 11:42

Apologies copied incorrect code, below the code on which I am working on
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 Awesome_Oscillator : Robot
    {

        [Parameter("Start Time", DefaultValue = "02:00")]
        public string StartTime { get; set; }

        [Parameter("Stop Time", DefaultValue = "22:00")]
        public string StopTime { get; set; }

        [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; }

        private AwesomeOscillator AwesomeOscillator;

        protected override void OnStart()
        {
            AwesomeOscillator = Indicators.AwesomeOscillator();
        }

        protected override void OnBar()
        {

            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(AwesomeOscillator.Result) && Functions.HasCrossedAbove(AwesomeOscillator.Result, MarketSeries.Close, 10))
                    ExecuteMarketOrder(TradeType.Buy, Symbol, volumeInUnits, "cBot", StopLoss, TakeProfit, Slippage, "this is a comment");

            if (Functions.IsFalling(AwesomeOscillator.Result) && Functions.HasCrossedBelow(AwesomeOscillator.Result, MarketSeries.Close, 10))
                ExecuteMarketOrder(TradeType.Sell, Symbol, volumeInUnits, "cBot", StopLoss, TakeProfit, Slippage, "this is a comment");

        }

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

 


@jamespeterwilkinson