Replies

belasto
30 Aug 2022, 01:42 ( Updated at: 30 Aug 2022, 01:44 )

RE:

Hi Panagiotis,

Okay - with your input, I finally got it to work.

If some other Super Newbie like me has the same question, here is a super noob recap.


Indicator Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{

   [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights == AccessRights.None)]
    public class YourCustomIndicator : Indicator
    {
        [Output("Value1", LineColor = "Transparent")]
        public IndicatorDataSeries MyValue { get; set; }

        ......
    }


    public override void Calculate(int index)
    {
         MyValue[index] = WhateverYouWantToPass;
    }
}



cBot Code
(Don't forget to click on "Manage References" on the top and include your custom indicator!)
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class YourBot : Robot
    {
    
        private YourCustomIndicator theIndicator;

        protected override void OnStart()
        {
            theIndicator = Indicators.GetIndicator<YourCustomIndicator>();
        }

        protected override void OnTick()
        {
            Print("YourValue: ", theIndicator.MyValue.LastValue.ToString());
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}




Best regards.


@belasto

belasto
02 Sep 2021, 19:51

RE:

Thanks for the answer. It makes sense this way. However, maybe you can help me with a workaround? Not such a big deal I assume, but I am not sure how to get there.
I am creating one initial Position and 4 PendingOrders afterwards, some kind of grid trading approach. I'd like to give the PendingOrders the same TP as the initial Position. I could add listener on PendingOrder filled and immediately adjust the TP, but is there an easy way to adjust it in advance?

 


@belasto

belasto
28 Apr 2021, 12:51 ( Updated at: 21 Dec 2023, 09:22 )

RE:

In the indicators Calculate function - working:
 

Chart.DrawIcon("arrow", ChartIconType.DownArrow, index, Bars[index].High + 5 * Symbol.PipSize, Color.Red);


In the cBot onBar function - not working, I let it run in backtesting, so onBar() is being called:
 

Chart.DrawIcon("arrow", ChartIconType.DownArrow, Bars.Count - 1, Bars[Bars.Count-1].High + 5 * Symbol.PipSize, Color.Red);



Thanks so much for helping out.


!!!! EDIT: If found the problem. I was not using the "visual mode" in backtesting... no wonder! Now it's working. Thanks!














 


@belasto