Robin 's avatar


Member since: 05 Feb 2021





Last Forum Posts

@Hold trendlines after restart bot:  23 Dec 2022, 10:35

i made it interactive as you can see in the code above, line stays when the bot stops but not when it starts again.

@Hold trendlines after restart bot:  22 Dec 2022, 23:09

Hi, does anyone know if it is possible to keep chart drawings after restarting a bot?

When I start a bot it automatically draws a trendline right through the chrart until it gets drawn. if I stop the bot and start it again, the trendlines disappear and they are all across the chart again.

this problem does not happen in backtest.

Thank you in advance!

For example:

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.WEuropeStandardTime, AccessRights = AccessRights.None)]
    public class RS : Robot

        private ChartTrendLine _trendLine1;

        protected override void OnStart()

         _trendLine1 = Chart.DrawTrendLine("High1", Chart.FirstVisibleBarIndex, Chart.BottomY, Chart.LastVisibleBarIndex, Chart.TopY, Color.Red);


        protected override void OnBar()

        protected override void OnTick()
            _trendLine1.IsInteractive = true;
            if (Bars.Last(0).High > Bars.Last(1).High & Bars.Last(1).High > Bars.Last(2).High )

                DateTime x2 = Bars.Last(0).OpenTime;
                DateTime x1 = Bars.Last(10).OpenTime;
                double y1 = Bars.Last(0).High;
                double y2 = Bars.Last(0).High;

                Chart.DrawTrendLine("High1", x1, y1, x2, y2, Color.Red);


@How to get current unclosed bar open price in BarOpened event:  12 Dec 2022, 22:42


maybe u can use bid or ask istead of Bars.Last() ?

@Stoploss placed automatically certain level (certain level is x% of account equity):  01 Oct 2022, 23:22

Hi Samm193,

Use this variable:

        [Parameter(" Volume Percent", DefaultValue = 15, MinValue = 0)]
        public double VolumePercent { get; set; }

var Stoploss = Math.Floor(Account.Balance * 1 * VolumePercent / 1000) * 1000;

@Close position after 5 bar passes:  27 Sep 2022, 21:40

Hi hamirady60, 

I think its not posible to close positon on bars, i use this method, it works with time. 

            var SellPosition = Positions.Find("Short", SymbolName, TradeType.Sell);

            if (SellPosition != null &&  SellPosition.EntryTime.AddHours(5) < TimeInUtc)
                ClosePosition(Positions.Find("Short", SymbolName, TradeType.Sell));

@close position on profit:  07 Mar 2022, 22:08

Hi, to my close orders I would like to add to only close a position when profit is above zero.

must be something like (UnrealizedNetProfit > 0)

does anyone know how to enter this correctly?

For example:

            if ((Positions.Find("Short", SymbolName, TradeType.Sell)) != null & MACDline > prevMACDline)
                ClosePosition(Positions.Find("Short", SymbolName, TradeType.Sell));
            if ((Positions.Find("Long", SymbolName, TradeType.Buy)) != null & MACDline < prevMACDline)
                ClosePosition(Positions.Find("Long", SymbolName, TradeType.Buy));

@close position w trendline:  19 Oct 2021, 19:50

thanks a lot Amusleh!

@close position w trendline:  16 Oct 2021, 19:13

hi, does anyone know how to automatically close a position after it crosses a trendline?

method i use: 

Chart.DrawTrendLine("TrendLine 30", x1, y1, x2, y2, Color.Blue);

thanks in advance!

@draw trendline:  13 Aug 2021, 22:43

thanks for your answer Musleh, unfortunately it still doesn't work when I enter Bars.Last(55).OpenTime at the x axis. with the following error: unable to convert from int to System.DateTime
do you know what's going wrong?

for example: 

                        var trendLine = Chart.DrawTrendLine("trendLine",Bars.Last(55).OpenTime , 0.75555, Chart.LastVisibleBarIndex, Bars.HighPrices[Chart.LastVisibleBarIndex], Color.Red, 2, LineStyle.Dots);
                        trendLine.IsInteractive = true;

@draw trendline:  07 Aug 2021, 11:44

thank you, the link has the following example:

        protected override void Initialize()
            var trendLine = Chart.DrawTrendLine("trendLine", Chart.FirstVisibleBarIndex, Bars.LowPrices[Chart.FirstVisibleBarIndex], Chart.LastVisibleBarIndex, Bars.HighPrices[Chart.LastVisibleBarIndex], Color.Red, 2, LineStyle.Dots);
            trendLine.IsInteractive = true;
here a trendline is drawn from the first visible point to the last visible point. when I change FirstVisibleBarIndex to bar.last(55) it shows an error saying invalid arguments.

can you please tell me how to enter this correctly?
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.