Replies

veenajetwisespisan
08 Feb 2023, 09:21

And this is the cbot that I have created. I have managed to call my custom indicator into the cbot without any error and below is the code for the Cbot. However, when I did a backtest for it, when i put in this line "  _Arrowsignal = Indicators.GetIndicator<Arrowsignal>();" , the cbot is unable to produce any backtest result. When i remove that line, it is able to get backtest result with it. 

To sum up, I want to call my indicator to take buy/sell trades when my custom indicator prints an arrow.

Thank you for your help!

 

//#reference:C:\Users\junwe\Documents\cAlgo\Sources\Indicators\Arrowsignal.algo

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 JC2 : Robot
    {

        [Parameter("Source")]
        public DataSeries Source { get; set; }


        [Parameter("Risk [%]", DefaultValue = 5)]
        public double Risk { get; set; }


        private FractalChaosBands _fractalChaos;
        private AwesomeOscillator _AWO;
        private MacdCrossOver _MACD;
        private Arrowsignal _Arrowsignal;
    


        double Support = 0;
        double Resistance = 0;

        double Lambo = 0;
        double Huracan = 0;
        double Aventador = 0;




        protected override void OnStart()
        {

            _fractalChaos = Indicators.FractalChaosBands();
            _AWO = Indicators.AwesomeOscillator();
            _Arrowsignal = Indicators.GetIndicator<Arrowsignal>();
        
        }



        protected override void OnBar()
        {




            if (Bars.ClosePrices.Last(1) > Bars.HighPrices.Last(2) && Bars.OpenPrices.Last(1) < _fractalChaos.High.Last(1) && Bars.ClosePrices.Last(1) > _fractalChaos.High.Last(1) && Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1) && Bars.TickVolumes.Last(2) < Bars.TickVolumes.Last(1))
            {

                if (PendingOrders.Count != 1)
                {
                    Support = Bars.LowPrices.Last(1);
                    Resistance = Bars.HighPrices.Last(1);
                    double differenceInPips = Math.Abs((Resistance - Support) / Symbol.PipSize);
                    double differenceInPips1 = Math.Abs(((Resistance - Support) * 1) / Symbol.PipSize);
                    DateTime? expiry = Server.Time.AddMinutes(1);
                    Huracan = differenceInPips;
                    PlaceStopLimitOrder(TradeType.Buy, Symbol, Volume(), Resistance, 1, "Buy", differenceInPips, differenceInPips1, expiry);



                }
            }




            //if (Trade.IsExecuting)
            // return;

            foreach (var position in Positions)
            {


                if (position.TradeType == TradeType.Buy)
                {

                    var breakevenPrice = position.EntryPrice;
                    var targetbreakeven = position.NetProfit / 2;

                    if (Symbol.Bid < position.EntryPrice - targetbreakeven)
                    {

                        position.ModifyStopLossPrice(breakevenPrice);


                    }
                }
                else
                {
                    var breakevenPrice1 = position.EntryPrice;
                    var targetbreakeven = position.NetProfit / 2;

                    if (Symbol.Bid > position.EntryPrice + targetbreakeven)
                    {

                        position.ModifyStopLossPrice(breakevenPrice1);


                    }
                }
            }
        }



        private double Volume()
        {

            var Volume1 = ((Account.Balance * (Risk * 100)) / (Huracan));

            var Volume2 = Symbol.NormalizeVolumeInUnits(Volume1);

            return Volume2;

        }



    }
}


@veenajetwisespisan

veenajetwisespisan
08 Feb 2023, 09:17

RE:

PanagiotisChar said:

Hi there,

It's better to share here.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

Hi, first of all thank you for your help! Below is the code for my custom indicator.

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



namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class Arrowsignal : Indicator
    {
        [Parameter("Source1")]
        public DataSeries Source1 { get; set; }

        [Parameter("EMA3", DefaultValue = 3)]
        public int EMAPeriod1 { get; set; }

        [Parameter("Source2")]
        public DataSeries Source2 { get; set; }

        [Parameter("EMA13", DefaultValue = 13)]
        public int EMAPeriod2 { get; set; }

        [Parameter("Source3")]
        public DataSeries Source3 { get; set; }

        [Parameter("EMA20", DefaultValue = 20)]
        public int EMAPeriod3 { get; set; }

        [Parameter("Source4")]
        public DataSeries Source4 { get; set; }

        [Parameter("EMA5", DefaultValue = 5)]
        public int EMAPeriod4 { get; set; }


        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }


        private string upArrow = "▲";
        private string downArrow = "▼";
        private string diamond = "♦";
        private string bullet = "●";
        private string stop = "x";

        private const VerticalAlignment vAlign = VerticalAlignment.Top;
        private const HorizontalAlignment hAlign = HorizontalAlignment.Center;
        Colors colorDown = Colors.Fuchsia;
        Colors colorUp = Colors.Green;
        Colors colorStop = Colors.AliceBlue;
        Colors colorBlue = Colors.Blue;
        Colors colorRed = Colors.Blue;

        private double arrowOffset;

        private bool emailsent;


        private FractalChaosBands FCB;
        private AwesomeOscillator AWO;

        protected override void Initialize()
        {
            arrowOffset = Symbol.PipSize * 1;


            FCB = Indicators.FractalChaosBands();
            AWO = Indicators.AwesomeOscillator();
            

        }
        public override void Calculate(int index)
        {
            int x = index - 1;
            int z = index - 1;
            double y;
            string arrowName;

            var volume = MarketSeries.TickVolume[index];
            double volume1 = MarketSeries.TickVolume[index - 1];
            double volume2 = MarketSeries.TickVolume[index - 2];
            double volume3 = MarketSeries.TickVolume[index - 3];
            double volume4 = MarketSeries.TickVolume[index - 4];
            double volume5 = MarketSeries.TickVolume[index - 5];
            double volume6 = MarketSeries.TickVolume[index - 6];
            double volume7 = MarketSeries.TickVolume[index - 7];
            double volume8 = MarketSeries.TickVolume[index - 8];
            double volume9 = MarketSeries.TickVolume[index - 9];
            double volume10 = MarketSeries.TickVolume[index - 10];

            var open = MarketSeries.Open[index];
            double open1 = MarketSeries.Open[index - 1];
            double open2 = MarketSeries.Open[index - 2];
            double open3 = MarketSeries.Open[index - 3];
            double open4 = MarketSeries.Open[index - 4];
            double open5 = MarketSeries.Open[index - 5];
            double open6 = MarketSeries.Open[index - 6];


            var low = MarketSeries.Low[index];
            double low1 = MarketSeries.Low[index - 1];
            double low2 = MarketSeries.Low[index - 2];
            double low3 = MarketSeries.Low[index - 3];
            double low4 = MarketSeries.Low[index - 4];
            double low5 = MarketSeries.Low[index - 5];
            double low6 = MarketSeries.Low[index - 6];

            var close = MarketSeries.Close[index];
            double close1 = MarketSeries.Close[index - 1];
            double close2 = MarketSeries.Close[index - 2];
            double close3 = MarketSeries.Close[index - 3];
            double close4 = MarketSeries.Close[index - 4];
            double close5 = MarketSeries.Close[index - 5];
            double close6 = MarketSeries.Close[index - 6];

            var high = MarketSeries.High[index];
            double high1 = MarketSeries.High[index - 1];
            double high2 = MarketSeries.High[index - 2];
            double high3 = MarketSeries.High[index - 3];
            double high4 = MarketSeries.High[index - 4];
            double high5 = MarketSeries.High[index - 5];
            double high6 = MarketSeries.High[index - 6];

            double spread4 = Math.Abs(open4 - close4);
            double spread3 = Math.Abs(open3 - close3);
            double spread2 = Math.Abs(open2 - close2);
            double spread1 = Math.Abs(open1 - close1);

            var currentHighMinusLow = high - low;
            double previousHighMinusLow1 = MarketSeries.High[index - 1] - MarketSeries.Low[index - 1];
            double previousHighMinusLow2 = MarketSeries.High[index - 2] - MarketSeries.Low[index - 2];
            double previousHighMinusLow3 = MarketSeries.High[index - 3] - MarketSeries.Low[index - 3];
            double previousHighMinusLow4 = MarketSeries.High[index - 4] - MarketSeries.Low[index - 4];
            double previousHighMinusLow5 = MarketSeries.High[index - 5] - MarketSeries.Low[index - 5];
            double previousHighMinusLow6 = MarketSeries.High[index - 6] - MarketSeries.Low[index - 6];
            double previousHighMinusLow7 = MarketSeries.High[index - 7] - MarketSeries.Low[index - 7];
            double previousHighMinusLow8 = MarketSeries.High[index - 8] - MarketSeries.Low[index - 8];
            double previousHighMinusLow9 = MarketSeries.High[index - 9] - MarketSeries.Low[index - 9];
            double previousHighMinusLow10 = MarketSeries.High[index - 10] - MarketSeries.Low[index - 10];
            double previousHighMinusLow11 = MarketSeries.High[index - 11] - MarketSeries.Low[index - 11];
            double previousHighMinusLow12 = MarketSeries.High[index - 12] - MarketSeries.Low[index - 12];
            double previousHighMinusLow13 = MarketSeries.High[index - 13] - MarketSeries.Low[index - 13];
            double previousHighMinusLow14 = MarketSeries.High[index - 14] - MarketSeries.Low[index - 14];

            double LargestSpread = Math.Max(previousHighMinusLow3, Math.Max(previousHighMinusLow4, Math.Max(previousHighMinusLow5, Math.Max(previousHighMinusLow6, Math.Max(previousHighMinusLow7, Math.Max(previousHighMinusLow8, Math.Max(previousHighMinusLow9, Math.Max(previousHighMinusLow10, Math.Max(previousHighMinusLow11, Math.Max(previousHighMinusLow2, Math.Max(previousHighMinusLow13, Math.Max(previousHighMinusLow12, previousHighMinusLow14))))))))))));
            double LargestVolume = Math.Max(volume3, Math.Max(volume2, Math.Max(volume4, volume5)));


            arrowName = string.Format("Arrow {0}", index);

            if ((close1 < open1 && close1 < low2 && close2 > FCB.Low.Last(2) && AWO.Result.Last(1) < AWO.Result.Last(2) && close1 < (high1 - (previousHighMinusLow1 * 0.699))))
            {

                if ((close1 < FCB.Low.Last(1)))
                if ((open1 > FCB.Low.Last(1)))
                if ((previousHighMinusLow1 > previousHighMinusLow2 && spread1 > spread2) || (previousHighMinusLow1 < previousHighMinusLow2))
                if ((high1 > close2))
           
                                
                                    {


                                        {


                                            if (!emailsent)
                                            {
                                                y = high1 + arrowOffset * 5;
                                                Notifications.PlaySound("C:\\Bell.mp3");
                                                ChartObjects.DrawText(arrowName, downArrow, z, y, vAlign, hAlign, colorRed);
                                                Notifications.SendEmail("pieee@hotmail.com", "pieee@hotmail.com", Symbol.Name, "BO KUKU Sell 2min");
                                                emailsent = true;
                                            }
                                        }
                                    }
            }

            else if ((close1 > open1 && close1 > high2 && close2 < FCB.High.Last(2) && AWO.Result.Last(1) > AWO.Result.Last(2) && close1 > (low1 + (previousHighMinusLow1 * 0.699))))
            {

                if ((close1 > FCB.High.Last(1)))
                if ((open1 < FCB.High.Last(1)))
                if ((previousHighMinusLow1 > previousHighMinusLow2 && spread1 > spread2) || (previousHighMinusLow1 < previousHighMinusLow2))
                if ((low1 < close2))
            
                               
                                    
                                        
                                    {

                                        {

                                            if (!emailsent)
                                            {
                                                y = low1 - arrowOffset * 5;
                                                Notifications.PlaySound("C:\\Bell.mp3");
                                                ChartObjects.DrawText(arrowName, upArrow, z, y, vAlign, hAlign, colorRed);
                                                Notifications.SendEmail("pieee@hotmail.com", "pieee@hotmail.com", Symbol.Name, "BO KUKU Buy 2min");
                                                emailsent = true;


                                            }
                                        }
                                    }
            }


            else
            {
                emailsent = false;
                return;

            }



        }



    }
}


@veenajetwisespisan

veenajetwisespisan
07 Feb 2023, 17:28

RE:

PanagiotisChar said:

Hi there,

You need to share your indicator's and cBot's source code in order to assist you further.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Thank you for the reply. Can I have your email?


@veenajetwisespisan