Topics
16 Nov 2023, 07:42
 1170
 1
15 Nov 2023, 10:36
 2069
 16
Replies

Spotware
15 Sep 2017, 17:11

Dear Trader,

Thanks for posting in the forum. You can find a sample of how to program a trailing stop loss here. It might be helpful in your effort to incorporate trailing stop loss logic inside your cBot.

Best Regards,

cTrader Team

 


@Spotware

Spotware
15 Sep 2017, 16:02

Dear irmscher9,

We still do not have an ETA. We will update this thread as soon as we have one.

Best Regards,

cTrader Team


@Spotware

Spotware
15 Sep 2017, 12:14

Dear Jensenbreck093,

All positions should be sent with the first message. Therefore the issue might be related to the way you read the incoming stream. Do you allow enough time for all the information to arrive. Do you keep reading the stream until all messages arrived? A code sample of how you read the incoming stream would be helpful to advise further.

Best Regards,

cTrader Team

 


@Spotware

Spotware
15 Sep 2017, 12:08

Dear Jensenbreck093,

You should be able to do that. Can you please provide the messages you are sending? Also can you tell us what happens after you send the message? Does a new position open instead?

Best Regards,

cTrader Team


@Spotware

Spotware
15 Sep 2017, 12:00

Dear Trader,

Thanks for posting additional information but it is still not clear what the problem is. The code you provided does not build because you are passing variables in the GetIndicator() function while this is not needed. Why do you do that? If you change your indicator initialization code to the following your cBot will build without problems.

        protected override void OnStart()
        {
            barry = Indicators.GetIndicator<BarryBoxIndyV02midLine>();
        }

Let us know if you have any further issues with the cBot.

Best Regards,

cTrader Team


@Spotware

Spotware
15 Sep 2017, 11:32

Dear Trader,

Thanks for posting in our forum. Could you please be more specific on what kind of assistance you need? Form the posted code, even though it is incomplete, it seems that you are already calling the indicator and getting the barryUp and barryDn values. What is the problem you are facing? Are the values you are getting not the ones you are expecting? Do you get compilation error? If you give some more information it will be easier for the community and cTrader Team to help you. 

Best Regards,

cTrader Team


@Spotware

Spotware
14 Sep 2017, 15:33

Hi Paul,

Thanks for the information. We will investigate this and come back to you.

Best Regards,

cTrader Team


@Spotware

Spotware
14 Sep 2017, 15:02

Hi Paul,

Thanks for reporting this. Could you please share a cBot that reproduces this issue, as well as the broker on which this happens?

Best Regards,

cTrader Team


@Spotware

Spotware
14 Sep 2017, 14:45

Dear trader,

The code posted has several mistakes that do not allow cAlgo to build the cBot. OnBar misses several curly braces to close properly. Did you copy and paste parts of the code? Maybe you did a mistake while pastng the code. If you do not have any previous experience in c# you might need somebody to help you with the development of your cBot. You can post a job in the Jobs section or contact a professional cAlgo consultant. You can find them listed in the Consultants page.

Best Regards,

cTrader Team


@Spotware

Spotware
14 Sep 2017, 11:28

Hi hungtonydang,

If you wish your code in the event handler to be executed only for the selected symbol, you can modify it as follows

        void OnPositionsOpened(PositionOpenedEventArgs obj)
        {
            if (Symbol.Code == obj.Position.SymbolCode)
            {
                _lastExecutedOrder = DateTime.Now;
            }
        }

Best Regards,

cTrader Team


@Spotware

Spotware
14 Sep 2017, 09:17

Dear hungtonydang,

If you wish to set the _lastExecutedOrder only whenever an order is executed, you should apply the following changes to your code.

First of all you need to an event handler for the Positions.Opened event as follows
 

        protected override void OnStart()
        {
            BB = Indicators.BollingerBands(Source, Periods, Deviations, MAType);
            Positions.Opened += OnPositionsOpened;
        }

Then in the event handler you can set the _lastExecutedOrder. See below

        void OnPositionsOpened(PositionOpenedEventArgs obj)
        {
            _lastExecutedOrder = DateTime.Now;
        }

See the full modified code below

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Requests;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Threading;
using System.Threading.Tasks;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.TasmaniaStandardTime, AccessRights = AccessRights.None)]
    public class HunterBB : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 40, MinValue = 1)]
        public int StopLossInPips { get; set; }

        [Parameter("Take Profit (pips)", DefaultValue = 40, MinValue = 1)]
        public int TakeProfitInPips { get; set; }

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

        [Parameter("Cooldown (hours)", DefaultValue = 2, MinValue = 1, Step = 1)]
        public double CD { get; set; }

        [Parameter("Bollinger Bands Deviations", DefaultValue = 2)]
        public double Deviations { get; set; }

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

        [Parameter("Bollinger Bands MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Position Id", DefaultValue = "Pid")]
        public string PositionId { get; set; }

        public Position position;
        private DateTime _lastExecutedOrder;

        BollingerBands BB;


        protected override void OnStart()
        {
            BB = Indicators.BollingerBands(Source, Periods, Deviations, MAType);
            Positions.Opened += OnPositionsOpened;
        }

        void OnPositionsOpened(PositionOpenedEventArgs obj)
        {
            _lastExecutedOrder = DateTime.Now;
        }

        protected override void OnBar()
        {

            var midbb = BB.Main.Last(0);
            var topnow = BB.Top.Last(0);
            var bottomnow = BB.Bottom.Last(0);

            var volumeInUnits = Symbol.QuantityToVolume(Quantity);
            var expiry = Time.AddHours(1);


            if (_lastExecutedOrder.AddHours(CD) < DateTime.Now)
            {
                //higher than indicator target price
                PlaceLimitOrder(TradeType.Sell, Symbol, volumeInUnits, topnow + 5 * Symbol.PipSize, PositionId, StopLossInPips, null, expiry);
                //lower than indicator target price
                PlaceLimitOrder(TradeType.Buy, Symbol, volumeInUnits, bottomnow - 5 * Symbol.PipSize, PositionId, StopLossInPips, null, expiry);
            }

            foreach (var position in Positions)
            {
                if (Symbol.Code == position.SymbolCode)
                {
                    ModifyPositionAsync(position, position.StopLoss, midbb);
                    Print("New Position TP price is {0}", position.TakeProfit);
                }
            }
        }

        protected override void OnStop()
        {
            Stop();
        }
    }
}

Let us know if this is what you are looking for.

Best Regards,

cTrader Team


@Spotware

Spotware
13 Sep 2017, 17:29

Dear dinuka94,

Thanks for the clarification. So your proposal is to add a selection for showing the history for the last week? Note that can also select a custom range when you select the radio button on the right.

Best Regards,

cTrader Team


@Spotware

Spotware
13 Sep 2017, 17:04

Dear dinuka94,

Thanks for posting your suggestion in the forum. Do you mean the History tab in the TradeWatch or do you mean the aggregation period of the equity chart? "Weekly" is not applicable in the History tab.

Best Regards, 

cTrader Team


@Spotware

Spotware
13 Sep 2017, 12:05

Hi jaredthirsk,

Thank you, we will check that as well.

Best Regards,

cTrader Team


@Spotware

Spotware
13 Sep 2017, 10:40

Dear Trader,

Thanks for posting in our forum. Multi-symbol backtesting is currently not supported in cAlgo but it is in our plans to add it in a future release.

Best Regards,

cTrader Team


@Spotware

Spotware
13 Sep 2017, 09:11

Dear msforex,

It is possible to develop custom indicators in cAlgo. If you need somebody to develop the functionality for you, you can post a job in the Jobs section or contact a professional cAlgo consultant. You can find them listed in the Consultants page.

Best Regards,

cTrader Team


@Spotware

Spotware
13 Sep 2017, 09:07

Dear Trader,

If want your vertical lines to show whenever the red line crosses the blue line, you could try the following code instead

            if (TenkanSen.HasCrossedAbove(KijunSen, 0) || TenkanSen.HasCrossedBelow(KijunSen, 0))
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Red, 1, LineStyle.Solid);
            }

Best Regards,

cTrader Team


@Spotware

Spotware
12 Sep 2017, 14:34

Dear Trader,

If we understood well what you are trying to do, then the following code sample should be helpful for you

            if (TenkanSen[index] == KijunSen[index])
            {            
                 ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index].AddDays(-3), Colors.Red, 5, LineStyle.Solid);
            }
            

Best Regards,

cTrader Team


@Spotware

Spotware
12 Sep 2017, 09:34

Dear Trader,

It will be easier for the community to help you if you describe what kind of help you need. If you need somebody to develop the functionality for you, you can post a job in the Jobs section or contact a professional cAlgo consultant. You can find them listed in the Consultants page.

Best Regards,

cTrader Team


@Spotware

Spotware
11 Sep 2017, 16:10

Dear irmscher9,

Thanks for bringing this into our attention. There is a maximum limit of 50k pips for stop loss and take profit in cTrader. But for a volatile asset like bitcoin it seems that it is not enough therefore we will consider increasing this limit.

Best Regards,

cTrader Team


@Spotware