Category Trend  Published on 25/11/2020

Fast bot EMA58

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!

2020-11-25:

new update:

Now updated with good default value for EURUSD 5MIN.

Also added Max volume size so you wont blow up your account.

 

OBS. IF you have a bigger account you will increese the succeed rate buy bulle the MAX volume for 16000 


// -------------------------------------------------------------------------------------------------
//
//    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 = 1000, MinValue = 0)]
        public int InitialVolume { get; set; }

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

        [Parameter("Take Profit", DefaultValue = 40)]
        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("Max Volume", DefaultValue = 8000)]
        public int MaxLoose { 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, "Tintry", StopLoss, TakeProfit);

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

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {

            Print("Closed");

            var position = args.Position;
            int NextVolume = (int)position.Volume * 2;
            if (position.Label != "Tintry" || position.SymbolCode != Symbol.Code)
                return;
            if (NextVolume > MaxLoose)
            {
                NextVolume = InitialVolume;
            }


            if (position.GrossProfit > 0)
            {
                //ExecuteOrder(InitialVolume, GetRandomTradeType());
                //TA bort
            }

            else if (Revers == true && sametrend == false)
            {
                if (position.TradeType == TradeType.Buy)
                {
                    ExecuteOrder(NextVolume, TradeType.Sell);
                }
                else
                {
                    ExecuteOrder(NextVolume, TradeType.Buy);
                }
            }
            else if (sametrend == true && Revers == false)
            {
                ExecuteOrder(NextVolume, 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)));


            }
        }
    }
}


patrik.webb@gmail.com's avatar
patrik.webb@gmail.com

Joined on 16.02.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: EMA-5-8.algo
  • Rating: 0
  • Installs: 2613
Comments
Log in to add a comment.
TR
trading.ternet · 3 years ago

Hi ,

Sorry Patrik,

with default settings on EURUSD M5 :
from 1/7/2020 to 1/7/2021 1000 -->992 €

Not really good ... but it's not worse than the others
Thanks for sharing

patrik.webb@gmail.com's avatar
patrik.webb@gmail.com · 3 years ago

New update!
Thanks guys for your feedback. Hope this will work even better for you.
DEfault value are optimize for EURUSD 5 min

mattia.musiello's avatar
mattia.musiello · 3 years ago

I have tested the robot in EURUSD M1 and it works well, certainly above the average of the robots that are available. If in the future you have paid robots, keep us updated and I would gladly evaluate them.
Simple and effective, I'm a fan of moving averages.
Tomorrow I will text it in Live, thanks for your work.
Greetings from Denmark.

IA
iacopoeste · 3 years ago

I tested a bit last night it works good.  with small stop loss and take profit on 1 minute time frames.

I cheched and works in with all pairs. I'm testing it in a demo account so I don't know yet if it works on live account.  

I let you know later.  

great job so far!

IA
iacopoeste · 3 years ago

It works good just seems that it's not working on all pairs.. In some occasion doesn't open the double opposite position after a loss.

I'm testing it in GOLD in 5 minutes time frame works good. 

 what do you think it's the best time frame and pair?

I would add the option of trailing stop.

VU
vutechx@gmail.com · 3 years ago

On the live account bot wont open any possition... :/ Do someone know where can be the problem? I already tried loads of different setups. In backtesting is working great, but the live environment and nothing opened in two weeks... :/ Can somebody help pls? Cheers!