triccomane
triccomane's avatar

Info

Username:triccomane
Name:triccomane
Member since: 07 Apr 2021

About

None

Signature

None

Last Forum Posts

@backtesting mode sometimes does not trade multiple symbols:  12 Jan 2022, 17:57


Hello, 

I've been trying to back test my cbot that trades two symbols. I'm using tick data now, but also bar data gives the same problem. 

What I do not understand is why sometimes one of the symbols does not take trades while on some other back tests the cbot works properly.

My cbot takes always trades on both symbols at the same time, when symbol1 opens a trade also symbol2 opens a trade.

I noticed that my cbot works properly when I randomly change the back test starting or ending date. 

I also noticed that both symbols downloaded the same amount of days, so they should have synchronized data.

Furthermore, I've found another cbot, that trades multiple symbols, on the forum made by another person. It also had the same issue when back testing, sometimes it does not trade both symbols but only one of them.

@Subtracting the value of a series to another one:  11 Jan 2022, 11:35


amusleh said:

Hi,

Try this:

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

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

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

        private RelativeStrengthIndex diffRSI;

        private IndicatorDataSeries nasdow;

        private Bars _nasdaqSeries, _dowjonesSeries;

        protected override void OnStart()
        {
            _nasdaqSeries = MarketData.GetBars(TimeFrame, "US TECH 100");
            _dowjonesSeries = MarketData.GetBars(TimeFrame, "US 30");

            nasdow = CreateDataSeries();

            diffRSI = Indicators.RelativeStrengthIndex(nasdow, Periods);
        }

        protected override void OnTick()
        {
            var index = Bars.Count - 1;

            var dowjonesSeriesIndex = _dowjonesSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            var nasdaqSeriesIndex = _nasdaqSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            nasdow[index] = _dowjonesSeries.ClosePrices[dowjonesSeriesIndex] - _nasdaqSeries.ClosePrices[nasdaqSeriesIndex];
        }
    }
}

The "nasdow" series contains the subtraction result of two other series, and you can use it on any indicators.

Thanks a lot to the both of you. You were very helpful.

@Subtracting the value of a series to another one:  09 Jan 2022, 13:19


I made some progress. I succeeded in getting the two symbols on two different arrays, but I still cannot find a way to subtract each element of the first array to the second one

            for (int i = 0; i < Periods; i++)
            {
                double close_nasdaq = (MarketData.GetSeries(MarketData.GetSymbol("US TECH 100"), TimeFrame.Daily).Close.Last(i));
                Print("nasdaq close price: ", i, " ", close_nasdaq);
                double close_dowjones = (MarketData.GetSeries(MarketData.GetSymbol("US 30"), TimeFrame.Daily).Close.Last(i));
                Print("dowjones close price: ", i, " ", close_dowjones);

                double downas;
                downas[i] = close_dowjones[i] - close_nasdaq[i]; //I get an erorr on this line 

@Is VPS location France ok?:  08 Jan 2022, 20:37


If the VPS is located in France and the broker's servers are in France or near France, it should work well. But if the broker's servers are located far away from France, you might have a big ping that might not be suitable for scalping bots.

@Subtracting the value of a series to another one:  08 Jan 2022, 20:11


Hi, I'm trying to subtract a Series from another series. In my case I'm trying to get RSI(dowjones - nasdaq, period).

I know I cannot just subtract a series from another series, can anyone suggest how to do that.

I think that to do that, I need to subtract each element of a series from each element of the other series. But I cannot find anything here that explains how to do that.

Thanks to whoever can help me with that.

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 nasdaqdowjonesspread : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

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

        private RelativeStrengthIndex nasdaq;
        private RelativeStrengthIndex dowjones;

        protected override void OnStart()
        {
            var nasdaqSeries = MarketData.GetSeries("US TECH 100", TimeFrame);
            var dowjonesSeries = MarketData.GetSeries("US 30", TimeFrame);
            var nasdow = dowjonesSeries - nasdaqSeries;

            diffRSI = Indicators.RelativeStrengthIndex(nasdow.Close, Periods);


            dow = Symbol.GetSymbol("US 30");
            nas = Symbol.GetSymbol("US TECH 100");
            downas = dow - nas;
        }

@cannot find open position:  27 Apr 2021, 14:25


Hello, I do not understand why my code would always return false when I try to look for open positions. I know at some point a position must be open because I backtested this code on the chart and positions get opened.  The problem must lie between line 31 and 34, where I try to check if positions are opened. Any help would be appreciated. Thanks.

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 Over9K : Robot
    {
        [Parameter(DefaultValue = 3)]
        public double Exec_buffer { get; set; }

        [Parameter(DefaultValue = 0.8)]
        public double tp_ratio { get; set; }

        [Parameter(DefaultValue = 0.8)]
        public double sl_ratio { get; set; }

        private double _lastClose;

        double HighPrice = 0;
        double LowPrice = 100000;
        protected override void OnTick()
        {
            if (Server.Time.Hour == 7)
                if (HighPrice > Symbol.Ask + (Exec_buffer * Symbol.PipSize) || LowPrice < Symbol.Bid - (Exec_buffer * Symbol.PipSize))
                {
                    var SellPosition = Positions.FindAll("Sell", SymbolName, TradeType.Sell);
                    var BuyPosition = Positions.FindAll("Buy", SymbolName, TradeType.Buy);
                    Print("SellPosition.Count() == 1 ", SellPosition.Count() == 1); // always prints false
                    if ((SellPosition.Count() == 1 && BuyPosition.Count() == 0) || (BuyPosition.Count() == 1 && SellPosition.Count() == 0))
                    {
                        Print("close pending");
                        ClosePendingSell();
                        ClosePendingBuy();
                    }
                    if (MarketSeries.Close.Last(1) != _lastClose)
                    {


                        _lastClose = MarketSeries.Close.Last(1);

                    }
                }

            if (Server.Time.Hour == 7 && Server.Time.Minute == 1 && MarketSeries.Close.Last(1) != _lastClose)
            {
                HighPrice = MarketSeries.High.Last(1);
                Print("massimo ", HighPrice);
                LowPrice = MarketSeries.Low.Last(1);
                Print("minimo ", LowPrice);
                double buy_price = HighPrice + (Exec_buffer * Symbol.PipSize);
                double sell_price = LowPrice - (Exec_buffer * Symbol.PipSize);
                double tp = (HighPrice - LowPrice) * tp_ratio;
                double sl = (HighPrice - LowPrice) * sl_ratio;

                PlaceStopOrder(TradeType.Buy, SymbolName, 0.01, buy_price, "Long", sl, tp);
                Print("BUY LIMIT");
                var line_high = Chart.DrawHorizontalLine("High", HighPrice + (Exec_buffer * Symbol.PipSize), Color.White);
                var line_low = Chart.DrawHorizontalLine("Low", LowPrice - (Exec_buffer * Symbol.PipSize), Color.White);
                line_high.IsInteractive = true;
                line_low.IsInteractive = true;

                PlaceStopOrder(TradeType.Sell, SymbolName, 0.01, sell_price, "Short", sl, tp);
                Print("SELL LIMIT");
                _lastClose = MarketSeries.Close.Last(1);
            }


        }

        ///***********************CLOSE PENDING SELL
        protected void ClosePendingSell()
        {


            Print("count 1");

            foreach (var order in PendingOrders)
            {
                if (order.TradeType == TradeType.Sell)
                    CancelPendingOrderAsync(order);
                Print("close sell");
            }

        }

        //**************************CLOSE PENDING BUY
        protected void ClosePendingBuy()
        {

            Print("count 1");
            foreach (var order in PendingOrders)
            {
                if (order.TradeType == TradeType.Buy)
                    CancelPendingOrderAsync(order);
                Print("close buy");
            }
        }


    }
}

@Server.Time.Hour NOT working for Backtest:  07 Apr 2021, 17:55


amusleh said:

The server time is based on back test data time not current time of server.

The code inside if block will only run if the server time is equal to 9:01, and for that to work you have to use the tick data for back test not bar data.

thanks for answering. How do I do that I cannot find a way to get tick data instead of bar data. What I'm trying to do is to get the high of the 9:00 candle.

@Server.Time.Hour NOT working for Backtest:  07 Apr 2021, 16:31


Hi, I do not understand how to make this work. The code works only when the current time of the server is equal to parameters accepted by the code. It does not make sense that the backtest takes into consideration the current server time and not the time in the backtest data.

        protected override void OnTick()
        {
            // Print("");

            if (Server.Time.Hour > 9 && Server.Time.Hour < 10 && Server.Time.Minute == 1)
            {
                Print("--------");
                var highest = Bars.HighPrices;
                Print("highest ", highest);
            }

Thanks in advance to anyone willing to help :)

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.

No uploaded.