Fast bot EMA58 free

Description

Trading based on when EMA 5 crosses EMA 8.

There is some settings for what to do when you close a loss trade, I used insperation from another bot in here. So you can enable Reverse double that take the double volum and trade it in the other direction.

The other settings to double it in the same direction.

This bot work pretty good. but I haven't doen the optimazation yet so If some one wanna have a look and try it out! go ahead!

 

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
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.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This robot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk
//
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Martingale Robot" creates a random Sell or Buy order. If the Stop loss is hit, a new 
//    order of the same type (Buy / Sell) is created with double the Initial Volume amount. The robot will 
//    continue to double the volume amount for  all orders created until one of them hits the take Profit. 
//    After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount.
//
// -------------------------------------------------------------------------------------------------

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 MartingaleRobot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Stop Loss", DefaultValue = 3)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 5)]
        public int TakeProfit { get; set; }

        [Parameter("Slow Periods", DefaultValue = 8)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter("Double Revers", DefaultValue = true)]
        public bool Revers { get; set; }

        [Parameter("Double Same trend", DefaultValue = false)]
        public bool sametrend { get; set; }

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


        private ExponentialMovingAverage slowMa;
        private ExponentialMovingAverage fastMa;


        protected override void OnStart()
        {
            fastMa = Indicators.ExponentialMovingAverage(SourceSeries, FastPeriods);
            slowMa = Indicators.ExponentialMovingAverage(SourceSeries, SlowPeriods);

            Positions.Closed += OnPositionsClosed;

        }

        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {

            Print("Closed");
            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code)
                return;

            if (position.GrossProfit > 0)
            {
                //ExecuteOrder(InitialVolume, GetRandomTradeType());
                //TA bort
            }
            else if (Revers == true && sametrend == false)
            {
                if (position.TradeType == TradeType.Buy)
                {
                    ExecuteOrder((int)position.Volume * 2, TradeType.Sell);
                }
                else
                {
                    ExecuteOrder((int)position.Volume * 2, TradeType.Buy);
                }
            }
            else if (sametrend == true && Revers == false)
            {
                ExecuteOrder((int)position.Volume * 2, position.TradeType);
            }
        }


        protected override void OnBar()
        {
            //int volumeInUnits = volumeInUnitsStart;

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(2);
            var previousFastMa = fastMa.Result.Last(2);


            //if FAST MA crosses SLOW MA UP on BAR. Open BUY trade
            if (previousSlowMa > previousFastMa && currentSlowMa < currentFastMa && Positions.Count <= 0)
            {
                //Close(TradeType.Sell); //tabort och gör om
                ExecuteOrder(InitialVolume, TradeType.Buy);
                //Open(TradeType.Buy);
                // var position = Positions.Find("EMA58");
                // position.ModifyStopLossPrice(Bars.LowPrices.Last(1) - (Symbol.Ask - (Symbol.PipSize * SL)));

            }
            //SELL
            //if FAST MA crosses SLOW MA Down on BAR. Open SELL trade
            else if (previousSlowMa < previousFastMa && currentSlowMa > currentFastMa && Positions.Count <= 0)
            {
                //Close(TradeType.Buy);
                ExecuteOrder(InitialVolume, TradeType.Sell);
                // var position = Positions.Find("EMA58");
                // position.ModifyStopLossPrice(Bars.HighPrices.Last(1) - (Symbol.Ask - (Symbol.PipSize * SL)));


            }
        }
    }
}
Comments