News cBot - Something's wrong...

Created at 29 May 2016, 02:56
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!
AM

ampalermo@gmail.com

Joined 21.09.2015

News cBot - Something's wrong...
29 May 2016, 02:56


Hi.

I'm working in a cBot that places stop orders at predefined times along the week, based on Investing.com economic calendar.

I tried to backtest it, but it didn't work... Could you help me, please? Here's 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.RussianStandardTime, AccessRights = AccessRights.None)]
    public class AMPCalendar : Robot
    {

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

        [Parameter("Trigger (pips)", DefaultValue = 10, MinValue = 1, MaxValue = 20, Step = 1)]
        public int Trigger { get; set; }

        [Parameter("TakeProfit (pips)", DefaultValue = 10, MinValue = 1, MaxValue = 50, Step = 1)]
        public int TP { get; set; }

        [Parameter("StopLoss (pips)", DefaultValue = 10, MinValue = 1, MaxValue = 50, Step = 1)]
        public int SL { get; set; }

        public string cBotLabel = "AMPCalendar";
        public DateTime[] TEvento = new DateTime[6];


        protected override void OnStart()
        {
            TEvento[0] = new DateTime(2016, 5, 2, 10, 55, 0);
            TEvento[1] = new DateTime(2016, 5, 2, 17, 0, 0);
            TEvento[2] = new DateTime(2016, 5, 4, 15, 15, 0);
            TEvento[3] = new DateTime(2016, 5, 4, 17, 0, 0);
            TEvento[4] = new DateTime(2016, 5, 4, 17, 30, 0);
            TEvento[5] = new DateTime(2016, 5, 6, 15, 30, 0);
        }


        protected override void OnBar()
        {
       DateTime Agora = new DateTime(Server.Time.Year, Server.Time.Month, Server.Time.Day, Server.Time.Hour, Server.Time.Minute, 0);
            for (int i = 0; i < 23; i++)
            {
                if (Agora == TEvento[i])
                {
                    var expiration = Server.Time.AddMinutes(3);
                    PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Bid + Trigger * Symbol.PipSize, cBotLabel, SL, TP, expiration);
                    PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Ask - Trigger * Symbol.PipSize, cBotLabel, SL, TP, expiration);
                }
            }
        }

    }
}


@ampalermo@gmail.com
Replies

... Deleted by UFO ...

ampalermo@gmail.com
29 May 2016, 17:22

RE:

lucian said:

  public DateTime[] TEvento = new DateTime[6];
 

  for (int i = 0; i < 23; i++)

TEvento[i]) is out of range.

 

 

Dear Lucian

Thanks for your reply. But that's not the problem. I've tested the array with several sizes and several dates/hours, and (in this case) I forgot changing the for loop range (i).

Please, if you can, baktest the code. It just never trigger the stop orders. I don't know why. The code is very simple, and I can't realize where is the mistake.

Thanks again.


@ampalermo@gmail.com