Category Trend  Published on 28/10/2020

EMA´s cross Bot

Description

A coding modification is required, i hope someone could assist in doing tow things: 

  1. changing the simple SL to trailing SL.
  2. adding trading hours parameter ( trading can be like between two fixed hours )

I am using a cross of two EMA ( fast and medium)  with a condition of being above or below the major EMA ( like 200 or so - here it is named as slow) this bot gave me great result while back testing it, looking into it. 

an example of a good back test results is: 

GBPUSD: 

  • timeframe: 15 minutes 
  • Slow period: 190
  • Medium:50
  • fast:14
  • SL:70
  • TP: 105

 

Note: This is a modified version by me on the bot done by https://ctrader.com/forum/cbot-support/10910 all credit goes to the original bot. 

 

following is the code

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class EMACross_RSI : Robot
    {
        [Parameter("Source")]
        public DataSeries SourceSeries { get; set; }
        [Parameter("Label", DefaultValue = "EMA")]
        public string label { get; set; }

        [Parameter("Slow Periods", DefaultValue = 30)]
        public int SlowPeriods { get; set; }
        [Parameter("Medium Periods", DefaultValue = 12)]
        public int MediumPeriods { get; set; }
        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter("Stop Loss", DefaultValue = 10)]
        public int SL { get; set; }
        [Parameter("Take Profit", DefaultValue = 10)]
        public double TP { get; set; }
        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private ExponentialMovingAverage slowMa;
        private ExponentialMovingAverage mediumMa;
        private ExponentialMovingAverage fastMa;


        protected override void OnStart()
        {

            fastMa = Indicators.ExponentialMovingAverage(SourceSeries, FastPeriods);
            mediumMa = Indicators.ExponentialMovingAverage(SourceSeries, MediumPeriods);
            slowMa = Indicators.ExponentialMovingAverage(SourceSeries, SlowPeriods);

        }


        protected override void OnBar()
        {
            int index = MarketSeries.OpenTime.Count - 2;
            var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
            var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);

            if ((fastMa.Result[index] > slowMa.Result[index]) && (mediumMa.Result[index] > slowMa.Result[index]) && (fastMa.Result[index - 1] < mediumMa.Result[index - 1]) && longPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);

                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, SL, TP);

            }
            else if ((fastMa.Result[index] < slowMa.Result[index]) && (mediumMa.Result[index] < slowMa.Result[index]) && (fastMa.Result[index - 1] > mediumMa.Result[index - 1]) && shortPosition == null)
            {

                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label, SL, TP);

            }

        }
        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }
}


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ASSignalLinkLink : Indicator
    {
        protected override void Initialize()
        {
            ChartObjects.DrawText("ASSignel Link", "Download for $3: https://gum.co/MGSxg", StaticPosition.Center, Colors.Red);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}


BA
bave.rowe28

Joined on 23.07.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: ASSignalLink.algo
  • Rating: 0
  • Installs: 2376
Comments
Log in to add a comment.
JO
jovancaran · 3 years ago

This is indicator, not cBot mate