Category Trend  Published on 09/02/2015

Trend Following Bot

Description

Hi all,

 

This the first post of a serie of posts where I'll share my robots.
This robot use moving average crossover strategy.
The time frame to use is D1 otherwise don't change any other setting.

This robot can help you pass the tough times if you use contrarian strategies because it allows you to have a big draw UP 
when your contrarian strategy is making a big dawn. In the long term, 
the results of this robot are sufficiently positive to not reduce the gain of your main strategy.

Here are some back tests results : 


// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API sample.
//
//    This cBot 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.
//
//    The "Sample Trend cBot" will buy when fast period moving average crosses the slow period moving average and sell when 
//    the fast period moving average crosses the slow period moving average. The orders are closed when an opposite signal 
//    is generated. There can only by one Buy or Sell order at any time.
//
// -------------------------------------------------------------------------------------------------

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 TrendFollow10100Exponenetial : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

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

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

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

        [Parameter(DefaultValue = 10000, MinValue = 0)]
        public int Volume { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Exponential10and100";

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

        protected override void OnBar()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);
            //&&  previousSlowMa > previousFastMa

            if (currentSlowMa <= currentFastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label);
            }
            //&& previousSlowMa < previousFastMa
            else if (currentSlowMa >= currentFastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label);
            }
        }
    }
}


illicoIt's avatar
illicoIt

Joined on 25.11.2013

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: TrendFollow10100Exponenetial.algo
  • Rating: 0
  • Installs: 5065
Comments
Log in to add a comment.
BO
bojesim268 · 11 months ago

It’s the pity you actually don’t possess a donate switch! I’d most likely donate to this superior site! We suppose that for now i’ll are satisfied with book-marking as well as adding your own Rss feed in order to my personal Search engines accounts. We appear forth in order to recent posts and can show this particular web page along with my personal Myspace group: )cummins EGR delete kit

BO
bojesim268 · 11 months ago

Heya i am for the first time here. I came across this board and I to find It truly useful & it helped me out a lot. I’m hoping to provide something again and help others such as you helped me.Hawaii Shirt Shorts & Flip Flops

HE
hecar35256 · 1 year ago

Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it.Wockhardt syrup

HE
heciraf296 · 1 year ago

Thanks for your post. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks. revenue loans

KT
ktfaizan2 · 1 year ago

Shoppers selling for which you applied exploration earlier than writing. It's painless to write down first-class write-up in that position .Pc

TI
tikobig768 · 1 year ago

An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers 축구중계

TA
tariq254500 · 1 year ago

Do you have a spam issue on this website; I also am a blogger, and I was curious about your situation; we have developed some nice methods and we are looking to swap methods with other folks, please shoot me an email if interested. server sensasional

TA
tariq254500 · 1 year ago

This method posting generally have a good deal of guests. Make a plan to support it? This task offers a awesome amazing take over factors. We experiencing a single thing huge in addition to extensive produce home elevators is a vital component. Shared catamaran tours

YI
yibemit512 · 1 year ago

plastic bathroom faucets woud eaily break compared to bronze bathroom faucets’ anti rungkat slot

NA
naveelansari525 · 1 year ago

There couple of fascinating points in time in this article but I do not determine if these center to heart. There may be some validity but I am going to take hold opinion until I take a look at it further. Good write-up , thanks therefore we want more! Combined with FeedBurner at the same timeslotzeus88

AB
abdullahjameel9137 · 1 year ago

This is a great blog, and i want to visit this every day of the week ,  kolkata ff

ZU
zubairkhatri101 · 1 year ago

my God, i thought you were going to chip in with some decisive insght at the end there, not leave it with ‘we leave it to you to decide’.Travel latvia

SI
siddiquekhirt123 · 1 year ago

Thanks for every other informative site. The place else may just I get that kind of information written in such an ideal means? I have a venture that I’m just now operating on, and I have been on the look out for such information.physics tutor

GI
gijeci2531 · 1 year ago

Cloud c-store back-office software for Retail, convenience store software, gas station software, and Jobbers Inventory Management, Fuel Management, Price Book, Lottery, Promotions and Tobacco!