isabakas
isabakas's avatar

Info

Username:isabakas
Name:isabakas
Member since: 25 Nov 2021

About

None

Signature

None

Last Forum Posts

@18000% backtesting bot doesn't perform good on live trading:  23 Sep 2022, 00:38


Hi, i have written the following bot based on a ma envelope strategy. It opens a position whenever price gets below or the upper or lower band, with a tp of 2pips. When backtesting on eurusd, with comimission set to 20 and spread to 0.2, it gives pretty nice results. I dont use ontick data, as my strategy is based on a onbar method. However during forward testing it looses money very quickly. Any idea why, and tips so it might work?

You should use the envelope indicator: https://ctrader.com/algos/indicators/show/281

Source code:

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.FullAccess)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 52)]
        public int EnvelopePeriod { get; set; }
        
        [Parameter(DefaultValue = 0.101)]
        public double BandDistance { get; set; }
        
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }
        
        [Parameter("Periodpricema", DefaultValue = 2)]
        public int Periodsprice { get; set; }
        
        [Parameter("TP", DefaultValue = 2)]
        public int TP { get; set; }

        [Parameter("SL", DefaultValue = 10000)]
        public int SL { get; set; }
   
        private ExponentialMovingAverage emaprice;
        private EnvelopeChannels envelopeChannels;
        
        protected override void OnStart()
        {
            emaprice = Indicators.ExponentialMovingAverage(Source, Periodsprice);
            envelopeChannels =  Indicators.GetIndicator<EnvelopeChannels>(EnvelopePeriod, BandDistance, MovingAverageType.Simple);
            
        }

        protected override void OnBar()
        {
            var currentPriceMa = emaprice.Result.Last(1);
            var previousPriceMa = emaprice.Result.Last(2);
            var channelup = envelopeChannels.ChannelUp.Last(1);
            var prevchannelup = envelopeChannels.ChannelUp.Last(2);
            var channeldown = envelopeChannels.ChannelLow.Last(1);
            var prevchanneldown = envelopeChannels.ChannelLow.Last(1);
            var longPosition = Positions.Find("Buy", SymbolName, TradeType.Buy);
            var shortPosition = Positions.Find("Sell", SymbolName, TradeType.Sell);
            
            {
            
            //Buy Entry
            if (prevchannelup > previousPriceMa && channelup < currentPriceMa)
                {
                if (shortPosition != null)
                ClosePosition(shortPosition);     
                {
                  if(Positions.Count == 0)
                ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits,"Buy", SL, TP);
                }
                }
                
            if(prevchannelup < previousPriceMa && channelup > currentPriceMa && longPosition != null)
                ClosePosition(longPosition);

            //Sell Entry
            
            else if (prevchanneldown < previousPriceMa && channeldown > currentPriceMa)
                {
                if (longPosition != null)
                ClosePosition(longPosition);
                {
                if(Positions.Count == 0)
                ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, "Sell",SL,TP);
                }
                }
             if (prevchanneldown > previousPriceMa && channeldown < currentPriceMa && shortPosition != null)
                ClosePosition(shortPosition);
             } 
             }
             
            
   private double VolumeInUnits
        {
            get { return Symbol.QuantityToVolumeInUnits(Quantity); }
        }
    }
}

@Getting coordinates from objects drawn by cystom indicator.:  03 Aug 2022, 09:43


Hi all, how would one store the coordinates from objects that are drawn on the chart by a custom indicator? I I want my indicator to draw a trendline between each arrow it draws. Therefore i need the coordinates of the arrows.

Sourcecode:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Multitimeframerenkoema : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("SlowmaPeriods", DefaultValue = 14)]
        public int SlowmaPeriods { get; set; }
        
        [Parameter("FastmaPeriods", DefaultValue = 14)]
        public int FastmaPeriods { get; set; }

        [Output("Slowma", LineColor = "Red")]
        public IndicatorDataSeries Resultslowma { get; set; }
        
        [Output("Fastma", LineColor = "Yellow")]
        public IndicatorDataSeries Resultfastma { get; set; }
        
        [Output("Cross")]
        public IndicatorDataSeries Resultcross { get; set; }

        private double slowma;
        private double fastma;
        
        protected override void Initialize()
        {
            slowma = 2.0 / (SlowmaPeriods + 1);
            fastma = 2.0 / (FastmaPeriods + 1);
        }

        public override void Calculate(int index)
        {
        //Slowma
            var previousValueslow = Resultslowma[index - 1];
            
            if (double.IsNaN(previousValueslow))
            {
                Resultslowma[index] = Source[index];
            }
            else
            {
                Resultslowma[index] = Source[index] * slowma + previousValueslow * (1 - slowma);
            }
            
        //Fastma
            {
           var previousValuefast = Resultfastma[index - 1];
           
           if (double.IsNaN(previousValuefast))
            {
                Resultfastma[index] = Source[index];
            }
            else
            {
                Resultfastma[index] = Source[index] * fastma + previousValuefast * (1 - fastma);
            }

            if ((previousValueslow > previousValuefast && Resultslowma[index] < Resultfastma[index]))
                Resultcross[index] = 1;
            else if (previousValueslow < previousValuefast && Resultslowma[index] > Resultfastma[index])
                Resultcross[index] = -1;
            else
                Resultcross[index] = 0;

            //Draw arrows
            if (Resultcross[index] == 1)
            {
                Chart.DrawIcon(index.ToString(), ChartIconType.UpArrow, index, Bars.LowPrices[index], "blue");
            }
            else if (Resultcross[index] == -1)
            {
                Chart.DrawIcon(index.ToString(), ChartIconType.DownArrow, index, Bars.HighPrices[index], "purple");
            }
           
          
         }
    }
    }
}
 

@Check if last trade was buy or sell condition:  24 Jun 2022, 21:16


Hi all, how would one code the following entry condition? The cbot can only enter a new buy position, if the last trade it took was a sell position. And vice versa.

Thx

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.