Replies

SwXavi
25 Feb 2020, 18:45

I want to mention this issue happens to me only inside a VPS, all optimizations run for about 5 minutes, while on my own laptop it can go full for hours, I'm not sure where's the problem. But at least I can circumvent it this way.


@SwXavi

SwXavi
20 Feb 2020, 02:41

RE: Saving optimisation results

phill.beaney said:

I don't understand why more people aren't requesting this, unless there is a way to save the data from a temp file that everyone except me is ware of.

Any Ideas welcome.

I really like this to be implemented in order to do proper research, currently backtests and optimizations cannot be shared or exported, the only option is to do screenshots, which is awful.


@SwXavi

SwXavi
19 Feb 2020, 17:46 ( Updated at: 21 Dec 2023, 09:21 )

Hello Panagiotis, I think these are the full settings, please let me know.


@SwXavi

SwXavi
18 Feb 2020, 21:13

I want to mention the example above just worked fine in 3.7 beta version, so I think it's fixed.

The other issue is that it stops early when it's supposed to run for a few hours, most optimizations stop at 3-15 minutes even with an absurd amount of parameters to try, I've used "Sample Trend Bot" to demonstrate, here's the code anyways.

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//
//    The "Sample Trend cBot" will buy when fast period moving average crosses the slow period moving average and sell when 
//    the fast period moving average crosses the slow period moving average. The orders are closed when an opposite signal 
//    is generated. There can only by one Buy or Sell order at any time.
//
// -------------------------------------------------------------------------------------------------

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleTrendcBot : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

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

        [Parameter("Slow Periods", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label);
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label);
            }
        }

        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }
}

Once again thanks for your support


@SwXavi

SwXavi
18 Feb 2020, 20:21

RE:

PanagiotisCharalampous said:

Hi Xavier R,

Can you please post the complete cBot code in text format so that we can use it to reproduce the issue?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hello Panagiotis,

Here's a sample code:
 

using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OptCrash : Robot
    {
        [Parameter("SMA Period", DefaultValue = 100)]
        public int InputSmaPeriod { get; set; }

        private AverageTrueRange _averageTrueRange;

        private Bars _dailySeries;

        private SimpleMovingAverage _sma;

        //private bool _moreTradesAllowed;

        protected override void OnStart()
        {
            _dailySeries = MarketData.GetBars(TimeFrame.Daily);
            _averageTrueRange = Indicators.AverageTrueRange(_dailySeries, 14, MovingAverageType.Simple);

            _sma = Indicators.SimpleMovingAverage(_dailySeries.ClosePrices, InputSmaPeriod);
        }

        protected override void OnBar()
        {
        }

        protected override void OnTick()
        {
        }

        protected override void OnStop()
        {
        }
    }
}

 


@SwXavi

SwXavi
17 May 2015, 03:00

You can store the profit/losses of a list and use sort to organize it.


@SwXavi

SwXavi
08 May 2015, 11:41

RE:

8053143 said:

Hello People

I need help regarding this issue, I have many positions with a single label id, I would like to get the unrealized profit/loss for those positions.

There is Symbol.UnrealizedNetProfit, however that's for a Symbol. I also have Position.GrossProfit but that's only for the last executed order.

I found an indirect way to do this which is simple arithmetic for the entry point and the current price, however it may be a little inaccurate due to swap/spreads and commissions.

Any help/ideas are appreciated.

 

Sorry I'm new to calgo it was easy, heres the code:

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DrawLine : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        double total = 0;

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "test");
            ExecuteMarketOrder(TradeType.Sell, Symbol, 20000, "test");
        }

        protected override void OnTick()
        {

            foreach (var pos in Positions)
            {
                if (pos.Label == "test")
                {
                    total += pos.NetProfit;
                    ChartObjects.DrawText("NetProfit", "Net Profit: " + Math.Round(total, 2).ToString(), StaticPosition.TopRight, Colors.Green);
                }
            }
            total = 0;
        }

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

 


@SwXavi