From Rags to Automated Rags... my attempt at automating Forex.

FTMO Trader Scouting


Well-Known Member
Kick it off

After a quick intro in Hi there...time to get serious?
Followed by a basic brain dump over on Can't measure success without setting a Goal..or two...and you are gonna need a plan.

I basically set out a very high level outline of where i am and where I want to get to and the things that have caused me issue in the past.

I put out a basic straw man of the following...
  • Platform choice.
    • Define requirements
    • Research the options
    • Evaluate shortlist
    • POC
    • Choose.
  • Broker choice.
    • Supported brokers for platform.
    • Additional Api requirements?
    • Trust
    • Funding.
  • Define System Pipeline
    • High level approach to Algo research, dev through to deployment. Timeframe/instruments etc. How to evaluate, discard, test deploy etc. How to monitor post live!!, how to integrate new systems into the portfolio.
    • Risk parameters and kill switch.
  • Algo!!!!
    • ideas and the pipeline.... loop loop loop.. Go live!!!... monitor as per pipeline.
    • GOTO Algo...

Some great points from @jack that I may have it backwards choosing platform and broker before attempting to investigate an edge. There is a lot of sense in that statement and obviously dipped in some experience.
I did mull it over and ultimately discounted (for now) the idea of getting into data /edge first and then looking for a broker that meets my needs for access in favour of just looking for a platform then broker.

Why if its great advice sven?
  1. I've been plagued/burnt in the past where I've went down a rabbit hole building testing frameworks and playing with jupyter notebooks. I have always struggled to get systems to the market.
  2. I'm primarily interested in time series and not order book based algos. Not to say I wouldn't but I simply don't have any insight on them. I think the tools for TS are freely available and won't require me to be bespoke.

But ultimately I'm most concerned about not getting anything to market and for now at least want to just keep it as vanilla as possible. I realise that will likely result in vanilla results but it's a start.

So.. the sooner I start this the quicker I can toss it in the bin and comeback to @jack 's Idea lol.

With that in mind and the absence of a better home, I'll treat it like a journal.. you can see my random thoughts and feel free to chime in.

Next up.... Platform Choice.
Why if its great advice sven?
  1. I've been plagued/burnt in the past where I've went down a rabbit hole building testing frameworks and playing with jupyter notebooks. I have always struggled to get systems to the market.
  2. I'm primarily interested in time series and not order book based algos. Not to say I wouldn't but I simply don't have any insight on them. I think the tools for TS are freely available and won't require me to be bespoke.

Mm.. could you describe the kinds of pitfalls you ran into doing this? Worked out a few possible edges on paper only to realize they don't materialize when trading live markets?

This is where a lot of quants / analysts benefit from working with experienced traders (specifically ones experienced in DMA and market structure.)

Could you give an example of a rabbit hole you went down that didn't yield the results you first expected (strategy wise)?
Mm.. could you describe the kinds of pitfalls you ran into doing this?
Oh thats easy.. I basically spent months making cool infrastructure and tools and webapps and forgot one of the primary goals..... alpha lol

Worked out a few possible edges on paper only to realize they don't materialize when trading live markets?
I think most edges don't materialize :/ I did the classic, gridding systems look like they can't lose etc.. long before I made any effort to understand risk or expectancy etc.. plug that bad boy in and test over a short period lol.

This is where a lot of quants / analysts benefit from working with experienced traders (specifically ones experienced in DMA and market structure.)
I'm sure. if I had 1/2 a clue on DMA and market structure I'd be dangerous. I think given my current restrictions I would have to look towards crypto to gain exposure. Not sure I've got what it takes lol.
How's progress?

No one subject is hard, there's just a lot of individual things to understand... it might appear daunting but keep chipping away and you'll be surprised how much you can pick up even in a few months time.
How's progress?
Somewhere between zero and none I would say jack. pretty much planned tbh. I’ve been trying to give my self a couple of full weeks away from everything except family over the holidays.

That mission is complete and I’m back to work tomorrow. Likely be a bit of carnage for a week or so as projects get back on track at work. Family goals done, work and pick up the gym/ health goals again after the short break.

I have made a little progress on platforms and brokers which I will write up soon but short version is pepperstone uk and first account there is the
ctrader Razor. Played with a bunch of demos and brokers but pepperstones support were great.

so a little write up in the works to keep me honest on why and next mission pipeline and ideas.
Happy new year!
Platform Choice
Rather than litter threads across the FXGears-a-sphere I'll just keep them inline unless they warrant their own thread.

  • Define requirements
  • Research the options
  • Evaluate shortlist
  • POC
  • Choose.

pepperstone uk, ctrader with a razor account (comms + spread)

Define requirements
Before I started looking at platforms and the likes I needed a basic idea what I wanted and the criteria of which I would judge them. So with that in mind I jotted down a mini wish list of the ideal platform. It looked a little like this and in no particular order.
  • Full auto
    • Comprehensive support for EA/automated trading out of the box.
    • multi pair system dev and testing.
    • multi timeframe support.
    • clear documentation
    • existing resources on the Tinterweb
    • optimisation tools.
  • Discretionary /semi-auto
    • Ability to customise the interface with trading panels for order entry, risk management etc.
    • range bars, tick charts(although not as truthful on FX obviously but do help normalise the bar sizes.)
    • decent range of timeframes.
  • Ability to interface with different brokers and not be tied.
  • Support account hedging (to make life simple with multiple systems in the same account)
  • Mobile/Web support

Research the options
Well if you have been messing about with FX for any length of time you will know that Metatrader is pretty much the defacto platform of choice by traders and brokers. Of course a relatively new cTrader by spotware is around and supported but then the well can get a little dry unless you prefer a platform like quantconnect(which has some merit unless you want to trade using your amazing skills manually)

Heck check out Jacks excellent Best practice accounts for MT4/5 and cTrader to see some of the common pro's and con's of both plafforms as well as 2 brokers that support them.

Of course you can build your own or use frameworks that others have build such as backtrader in python. Then it becomes more of a question o brokers and if they support an API of some form.

I'm interested in platforms so lets stick to MT + cTrader
Now I'm sure that some(maybe) will pick me up and say "Hey XXX can do that!!!!". Probably can. I probably missed it...breath.

Support for EA/automated tradingCome on. You know that MT is has approximately 700 million indicators and EAs. They have been around since the internet was born.. don't believe me? check out the interface ;)

It has its own language which is kinda c/c++ ish..
cTrader now supports algos in the same platform as the trading app. Once upon a time it was an additional cAlgo app but they merged it into cTrader and call it 'automate'

Its in C#
Multi pair backtestingYes MT5Yes
Multi TimeframeYesYes
Clear DocumentationYes MQL5Yes cTrader Guides and of course its generic c#
Existing ResourcesLoads/the most/Every whereSome / algos marketplace and can install with one click.
Optimisation toolsMT5 is quite comprehensive.

  • genetic optimisation
  • 1/2 decent charts for reviewing parameter space
  • easy click forward testing
  • agents to speed up work.
cTrader provides a somewhat limited amount of tools.
  • Genetic optimisation
  • Custom Fitness function (to allow you to build your own evaluation function in optimisation.. Nice)
Interface CustomisationYes - own custom componentYes - own custom components
Bar TypesRange bars/tick bars only through indicators and offline charts AFAIKNative range bars and Tick charts, renko and others.
Timeframeslots / more with offline chartslots
Broker supportEveryoneSeveral and usually decent ones
Account Hedging supportYes MT5 now supports(after much pushing by clients)Yes
Mobile/Web supportMobile app is quite good.
Web app is ok.
Mobile app is quite good
Web is close to desktop with limited chart types (time + range)

Evaluate shortlist
Frankly there is little between them. However, after playing with them for sometime I got a feel for how their different tools sat with me.

I just couldn't muster any love for MT's UI. God I know in the scheme of automating systems this it pretty low on the criteria but it just made me sad opening it up. cTrader on the other hand felt fresh and almost a joy to use. After a few years of TradingView charts being available we have been spoilt in the joy of typing a few letters for the pair chooser to pop up, typing a few numbers for the timeframes to come up etc. Neither MT/CT were close but its clear CT sucks less lol.

CTs DOM entry and order management is years ahead of MT. You can do partial closes, breakevens etc without algo requirements. Even the web app supports this.

Range bars and tick charts in CT are really good. They are native and it feels like it vs indicators running to generate offline charts in MT. This is a big deal for me. Discretionary shortterm trading I prefer to use tick charts instead of 3-5min charts. I know they are not as useful in Forex but with a sensible broker they can still help to normalise the bar sizes and make things a little more sensible. Range bars are something I had already done some initial testing with years ago.
They are great at removing the whipsaws that happen from low volatility periods as the bars don't print. Also if you take a look at the distribution of returns on them they tend to look like an M.. ie almost no chance of zero movement and higher chance of full movement which is pretty much the opposite of normal time based bars.
With range bars you only need 1 number to represent the entire movement of that bar and its easy to normalise as R/c-o.. +1 full up bar.. +0.75 went south for 25% and then finished up.. etc. There has to be an edge there right? somewhere?. I digress but has to be useful for ML..

c#. Now we know in the perfect world we would have our own systems running in our own frameworks and plug into our chosen brokers. Using MT this is a challenge albeit not impossible. CT uses c# and it would be a relatively simple job to take Algos from that and build your own framework that mocks the API or simply rewrite to use your own API (keeping the key events like start, on tick, on bar etc)
AND... you have pretty much the universe of c# available to you. Yes in MT you can write some DLL's or bridges are available but its not quite the same.

Optimisation in MT stood out for over CT based on its charts making it easier to review the parameter space. Its clear that CT has someway to go however of course it does have the extensive fitness functionality as well as allowing you to create custom Fitness functions. This is quite a bit deal if you have your preferred way of evaluating performance. CT results are available and can be exported so external charting could be done easily.

Proof of Concept (POC)
I used MT4 previously messing about for years(why?) I know it intimately. I demoed a MT5 account and spent as much time in it as I could. I didn't build anything as I've done it before. Took a look at the key differences between MT4/5

cTrader I traded discretionary for a week or so on demo (yey I'm rich with demo money) to get a feel for the tool. I also, downloaded a few sample algos and indicators. built a trade entry panel for fun.

So when I started I thought I'll be rational, base it on the facts and see what can be done by the various offerings. the end though it comes down to the feels you have. Thats as important as facts given you will need to enjoy the process.

So.... cTrader won this round. Not really much between them and of course each has strengths and weaknesses but its important to remind ourselves of my goals.
I want to automate systems robustly with an off the shelf offering and also discretionary trade as a secondary goal.

The reality is that seeking Alpha is what is hard. Neither cTrader or MT will limit me in functionality or brokers. Neither would prevent me from taking a winning algo and redeploying in another framework/api or whatever in more than a handful of days/weeks.

So at the end of the day just need to make a choice. believe in it and move forward. We can always come back to it.
Last edited:
Broker Choice

Broker choice.
  • Supported brokers for platform.
  • Additional Api requirements?
  • Trust
  • Funding.

See: Jacks.. Best forex plaforms for demo/practice accounts
Life's too short.. I chose Pepperstone UK. The end

Ok maybe a little more to it than that. If I had wanted to use MT4 I could have stuck with Oanda (and will but just for the REST api and spreadbetting should I get some traction).

But I decided on cTrader as we know. With that I checked out a few brokers.

Trust and ease of funding and withdrawals
I see people pushing unregulated brokers that are based in the freaking Caymans on reddit and other places because "leverage man". Anyone that is treating this like a business and doing any kind of due diligence will push those straight in the bin.


That leaves regulated and in the UK thats going to be the FCA with some ESMA overhead so I checked out a few; Pepperstone UK, FX Pro and IC Markets.

Pepperstone were the only ones that reached out to me and checked if I had everything I needed.. tried to get an understanding of who I am and what I want.. They didn't push any live account or recommend anything but they did reach out. The others I got a flurry of emails but thats about all.

Type of account
FX is typically a spread game with a bunch of made up terms like ECNs / STP and the likes when they are maybe not that in the strictest definition. Ultimately I want a NDD platform. I'm not overly concerned if the broker takes the other side but I would rather have transparency in my pricing.

cTrader makes it pretty much impossible for a broker to get tricky as cTrader essentially white labels and own the infrastructure. That said you can usually choose between spread based or comm's + spread.

Pepperstones Razor account is comms+spread. A basic bit of maths and you can see that their spread based offering is competitive and their Razor is tight spreads with decent enough comms to work out the cheapest. cTrader at Pepperstone has some "weird" pricing model for comms in that its 7 units per Lot round trip in the Base CCY... so 7£ if GBP pairs.. $7 for USD pairs etc.. A little quirky but I guess you can take advantage by choosing scalping pairs carefully if its really that important but on all pairs I calculated it came out cheaper than comms only (assuming sensible spreads at time)

Most of the brokers will give somekind of discount for volume and of course one day thats going to be something I care about..

In the end, I've went with PepperStone UK as they have a very competitive offering and excellent customer service, strong track record and regulatory oversight.
Their only real downside is lack of spreadbetting which of course may or may not matter in the long haul once I make my millions.
Define System Pipeline

Define System Pipeline
  • High level approach to Algo research, dev through to deployment. Timeframe/instruments etc. How to evaluate, discard, test deploy etc. How to monitor post live!!, how to integrate new systems into the portfolio.
  • Risk parameters and kill switch.

Well I have been giving the subject of system development some thought. On one hand its somewhat instinctive but of course on the other we need to treat this as a business. We need to try and avoid as many biases as we can.

For me at least a pipe really just a decision tree or flowchart that has criteria or rules of thumb that determine how we transition from one to the other.

Why bother?
"if its profitable trade it.. else just tweak it...etc"
-- said no one out loud.

  1. Procrastination for one. Man I'm amazing at it.
  2. Reducing Bias... I'll just tweak it.. optimise a little more...
  3. Moving toward the goal.
  4. Time management. Putting enough work into each facet of the process.
  5. Defining success or failure up front to allow us to think clearly when needed.

For fun (lol) I'll go into a little more detail on above.

If anyone has read The Lean Startup (@jack you may enjoy / feel free to add affiliate link if you do) then you know that the whole idea is to come up with millions of ideas and fail fast and fail early. Don't invest effort too early and just refine as the feedback tells you. Thats the idea here. Don't waste time in later stages.

Time Management
If you have a roadmap of how to get to your 'end' goal it is much easier to know how you are progressing. Its also important to understand where the time is going and where it should be going.

Value as we pass through the pipeline (when we do it correctly)


As we continue through our pipe we invest more and more time on the process. Its obvious that anything you spend time on you can lose objectivity. Painters for example after spending a while on a painting will often use a mirror to complete the final details. Sure they like carrying a mirror but it allows them to see things for the first time and with fresh eyes.

The longer you spend on something the more likely you are to invest mentally in the success of it. This is something software developers and the early days of RAD realised. If you show a user a fancy mocked screen they are reluctant to tell you it sucks and you don't want to hear it. If you sketch together you are happy to toss them in the bin.

Wastage of Effort(if we do it right)

So that means in an ideal world we would throw aways the garbage early on and as we pass through the pipeline.. Each step forward is an investment in effort and we lose objectivity.

Speaking of Steps.. what are they?
Now this is deliberately vague and geared towards 'Model based systems' rather than datamining / ML etc.

Some notes...
  • Its entirely possible to add a million more steps and break each down to definite steps AND I intend on doing just that.
  • Its just a high level guess at what I think I need to do, Obviously its without any background or proven track record.
  • There is likely some iteration between stages but of course some things should not (out of sample validation back to optimisation for example)
  • There are hidden / not defined Criteria for moving to the next stage.. Like what the hell decides if its good enough to go to validation?
  • The colouring tries to represent the frequency of which I'd expect to make it through the steps.. Millions of concepts not so many deployments etc.
  • The general idea is to try and dedicate the appropriate amount of time to each stage.. instead of 90% on entry signals ;)


So I'm treading a fine line between making progress and disappearing on an academic exercise defining the 'perfect' pipeline but thats how I roll. I need to formalise this else I will be dev/code/optimise-tastic

Ok.. Next step in a week or so's time for a Model Backlog. Define a backlog or ideas, concepts, prioritise them and then start investigating...

Feedback / criticism gratefully accepted as usual. I plan on refining as I learn stuff but now is a good time to tell me I've missed any key points/stages or I'm wasting my time.
You're putting a lot of effort into organizing and planning your approach. Nice!

That said, you're going to risk getting caught up in a lot of the small details and that will slow your progress down. Don't get me wrong, nothing you wrote down so far screams "getting lost in the weeds".. but there's a saying I heard many years ago that I constantly remind myself whenever I get lost in the fine details and start burning a lot of time:
Not every job worth doing, is worth doing well.

Maybe take a basic (dummy) model and run it through your process from start to finish.. just go through the motions, and see where you get gummed up the most. Maybe you can come up with ways to not let such things slow you down when you get an idea that's worth testing out.
Not every job worth doing, is worth doing well.
Lol wise words indeed. I used to suffer early in my career with 'it has to be done right' attitude. I promise you that has long since gone and I take a more pragmatic and risk based view.. if its throw away then don't invest.

Maybe take a basic (dummy) model and run it through your process from start to finish.. just go through the motions, and see where you get gummed up the most. Maybe you can come up with ways to not let such things slow you down when you get an idea that's worth testing out.

I've just tossed together an initial model backlog of 12 or so various stupid ideas across the classics Momentum, MR, volatility etc.. and thrown them in Trello. I had planned on doing something stupid like a classic momentum with zero expectations on result. Instead I'll take your point and create dummy model that I'm not invested in and expect it to be a failure.

That last post was just a sketch that I don't expect it to look like that in a few iterations. After all I know nothing other than code!!! Its just guess work and a basic outline to try and make me move forward. I already know that once the editor opens I will struggle to leave it or I will be in backtest hell.

So... the pipeline is throwaway and I'm allowed to change it as I learn. Its not a rule book and its not a contract. Its just a map to try and help me find my way. Once I learn the landmarks I'm sure its shredder food.

thanks for the suggestion and feedback as ever mate.
Off to spec out a basic model!!!
Dummy model time + Initial Build
A basic model to run through the pipeline.

The idea is not to make a profitable algo but to shake out the stages of the pipeline.
Simple Momentum based model.

Model Concept
Try and capture momentum using the worlds worst kept secret... moving averages

Initial Model:
- Single moving average like 200sma. close above/below.
- Stop and reverse.
- 60min or above.
- No stop loss .
- no target.

Reviewing the model and had a little think about it. Closing above a MA is basically the same as a 1 period moving average closing over the MA. If we switch out the Close time series for a MA we get a little more flexibility later.

No build for stops or targets or any alternative exists/position sizing etc...although we can add in the eval stage if made sense.

Dev Environment
I do all my personal dev on a Mac. Sure work I'm on linux and windows but home == mac. That means I tend to remote into a machine or run it in virtualbox or similar. My poor mac is getting on for sure but it can still manage cTrader for dev...ish.

cTrader is c# currently windows and like Metatrader has its own editor. You can also integrate Visual Studio for external editing and I tried both.
  • internal editor = Basic, no version control or refactoring etc however completions and syntax checking are all good.
  • MSVS = Advanced. refactoring etc etc etc.. built in Version control. Pretty bloated on my poor little machine and frankly Its been years since I heavily used anything other than the amazing Pycharm/intellij IDEs.
I was more than happy to use the internal editor. Maybe that will change as my comfort with cTraders API improves or I need debug or something.

Version Control
Yeah I don't need to sell the idea of a VCS do I guys and girls?
GIT in combination with Bitbucket is my favourite VCS. You can always get a git client or shell and its well supported. Its ideal for being on the move as you can check your changes in frequently to your local repository even when without network access. Push it to the cloud... pull it onto the other machine. Job is a good un.

Likely be using a VPS and simply create another key for readonly access to a branch on bitbucket. When I want to deploy, just push the compiled .algos to that branch and its available. Of course with hooks and the likes you could even deploy if you were insane lol.

So since I was not planning of using stops/targets I opted for the 'OnBar' event instead of OnTick. I don't need to be updating my view of the world on every tick. I'm only opening positions once a bar closes and have no need to manage positions(yet).

The other advantage of OnBar is you can simulate with open prices, be it 1min or the target timeframe. I realise that simulating a 60min system with 60min Candles is unlikely to be accurate however I believe that having the ability to quickly simulate or optimise on coarse data is useful before committing to tick based tests.

That in mind, hear is overly verbose cBot using the ReversePosition function (if currently in a position).

** Yep here is a ham-fisted attempt at a stop and reverse moving average
** bot with no stops/targets or MM.
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 DummyModelBot : Robot
        [Parameter("Source", Group = "Signal")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Fast Period", Group = "Signal", DefaultValue = 1)]
        public int FastPeriod { get; set; }

        [Parameter("Slow Period", Group = "Signal", DefaultValue = 200)]
        public int SlowPeriod { get; set; }

        [Parameter("Type", Group = "Signal", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType { get; set; }

        [Parameter("Lots", Group = "Position", DefaultValue = 0.01, Step = 0.01, MinValue = 0.01)]
        public double Lots { get; set; }

        [Parameter("Instance", Group = "Position", DefaultValue = "DummyModelBot.001")]
        public string Instance { get; set; }

        private MovingAverage fastMA;
        private MovingAverage slowMA;

        protected override void OnStart()
            // initialise the Indicators.
            fastMA = Indicators.MovingAverage(SourceSeries, FastPeriod, MAType);
            slowMA = Indicators.MovingAverage(SourceSeries, SlowPeriod, MAType);

        protected override void OnTick()
            // Not needed

        protected override void OnBar()
            double fMACurrent = fastMA.Result.Last(1);
            double fMAPrev = fastMA.Result.Last(2);

            double sMACurrent = slowMA.Result.Last(1);
            double sMAPrev = slowMA.Result.Last(2);

            // if the closed version of the indicators (previous bar) cross then
            // either open a position of close the existing one and reverse.
            if (fMACurrent > sMACurrent && fMAPrev < sMAPrev)
                // cross up
                Print("Buy Time");
            else if (fMACurrent < sMACurrent && fMAPrev > sMAPrev)
                // cross down
                Print("Sell Time");
                // every thing else


        private void TakePostion(bool isBuy)
            var position = Positions.Find(Instance);

            if (position != null)
                // have a position already
                if (position.TradeType == (isBuy ? TradeType.Buy : TradeType.Sell))
                    // hmm  its the same so ignore
                    Print("Position found already with same direction {0}", position.Id);
                    // time to reverse it.
                    Print("Position found will reverse {0}", position.Id);
                // no position so lets open one.
                var direction = (isBuy ? TradeType.Buy : TradeType.Sell);
                Print("Opening position {0}", direction);
                var result = ExecuteMarketOrder(direction, Symbol.Name, Symbol.QuantityToVolumeInUnits(Lots), Instance);
                Print("Position result {0}", result.ToString());


        protected override void OnStop()
            // if we are backtesting then just close all the trades to simplify results
            if (IsBacktesting)
                foreach (var position in Positions.FindAll(Instance))

  • I am still dyslexic. "Postion" anyone?
  • Crossovers are a common need. cTrader has a function to perform it on 2 series over a given lookback. However, since I want closed bars this is somewhat useless. If I was to build up a set of reusable tools I would make a 'shift' Indicator that is initialised with a Series/Indicator and simply shifts/offsets by the required amount. Using that I could have shifted the 2 MA's on 'start' to ensure I'm always looking at a closed value.. then the Crossover functions would have assisted.
  • Backtester doesn't close the final position and so I added a close all function in OnStop if backtesting to make the interpretation of the stats more meaningful.

Functional Test
That was easy. I simply did the following
  • Pick a pair which is well traded. aka EURUSD of course
  • Set the backtest
    • timeframe to 1hr.
    • Duration to about a month.
    • Set it to 1hr bars open (as I'm using OnBar)
    • check visual test to watch it in action, adjusting the speed till it starts making trades
cTrader doesn't display your indicators when you run the backtest. Obviously you don't want everyone to see the magic(or you don't need to see them when running live.) but for testing its a little chore. I resolved that by creating a template with the indicators on it.

Initial test using 'Open bar' 1hr Bars.
Since I'm a pessimist I set the spread to be 1 pip (average Pepperstone spread for eurusd was 0-0.1 in core hours)

Thats the settings used when testing functionality. So quick and close enough.

Tick based test and historical bid/offers used.
Interestingly seems that it does better due to the more accurate spreads representation. Personally I would be happy if I saw better perf in prod lol.


Looking back
The dev experience isn't too much of a nightmare as the cTrader environment is pretty sweet.

There are a few quirks and considerations like how OnBar is the 'start' of a new bar or the leaving of open positions at the end of simulation.

You can easily export the closed Position History or the Trading Events(open/close individually) to Excel. That said. One thing I like to do is study MAE and MFE. There is nothing here to do that. I think it would be possible to scan through the trade history OnStop() and using the price series over that time write out MFE/MAE (even in pips would do..). Or simply make use of the OnTick and write out the info as positions close but I think the OnStop would make more sense and easier to enable on OnBar systems (and more generic as a library)

This would allow some additional research later in python / jupyter on optimising stops and such.

Next... Evaluation
Version Control
Yeah I don't need to sell the idea of a VCS do I guys and girls?
GIT in combination with Bitbucket is my favourite VCS. You can always get a git client or shell and its well supported. Its ideal for being on the move as you can check your changes in frequently to your local repository even when without network access. Push it to the cloud... pull it onto the other machine. Job is a good un.


I use GitLab's free tier account. Using a proper VCS is a must even if you're new to programming. Such a life saver.

Next... Evaluation

Great start. Obviously you shouldn't expect much or anything out of a moving average crossover strat, but as a dummy to just get your process / workflow down it's fine. The key here is motivation and structure, and it seems you're doing a great job getting that in place.

Obviously you shouldn't expect much or anything out of a moving average crossover strat, but as a dummy to just get your process / workflow down it's fine. The key here is motivation and structure,

yes turns out the moving average crossover won’t be my ticket to financial independence ;) who knew ha ha.

It’s made me run through a few minor obstacles and I’ve already got a better idea of where I’m likely to get bogged down.

On the evaluation stuff. It’s kind of hard to know when enough is enough and you are well into curve fitting.

Then again backtesting is curvefitting by the very nature of discarding or continuing based on some metrics.

I guess this is the secret sauce. How much do you rely on the past to determine your course. if you optimise then what is your criteria for choosing what variations. You see many people heavily optimise to the point it must be curve fit however they work on the premise that there is a half life for that fitting going forward.

Anyhoo. Onward. I’m planning on writing up my evaluation experiments over this week (turns out fictional crap dummy models find it hard to compete with a weeks holiday in Edinburgh, kids birthdays, the lion king musical) .....Hakunna meta-trader ... it means no profits for the rest of your days
Using a proper VCS is a must even if you're new to programming. Such a life saver
Actually on that.. One of my earliest memories of IT (a long long long time ago) was related to using a VCS.

Just joined the team. first job in IT(not a software house).. I was using the emacs editor and it made old file backups as you saved... filenames with a tilde(~) on the end.

One day I did rm *~ to remove the files ending in tilde.

Horror!!!! I actually typed too quick and hit a return before the tilde.
rm *

I looked in the folder and all the files were gone. The entire project that I had joined. 'gone'.

I pretty much wanted to vomit.

After trying to think; should I ask if there are backups somewhere? and give the game away.... I realised I'd started emacs up like emacs * & All the files were open in my editor.
After adding spaces and forcing saves for what seemed like an eternity I almost calmed down as the files started to re-appear.

At that point and disaster averted my brain told me this was a good thing lol.
  1. Asking if we had 'copies' I was told 'yeah probably but they are from when we started'.. so months out of date.
  2. Can we make backups regularly .. i asked. "we should probably use a VCS but no one can be bothered"
  3. Should we all be logging on as 'root'.. someone could be in the wrong dir and delete stuff.. "yeah probably"

So at that point..pretty much pre-internet I set about;
  • Adding cvs for version control. writing a bunch of scripts to help people check stuff in etc.
  • Making scheduled jobs to backup those repos to another machine offsite.
  • changed everyone to use user ids and not the shared root user/password (lol !!!)

Even in a shitshow you can learn something but you a) don't know what you don't know and b) you need to set your own standards.

Evaluation and Validation (kinda)
Well quite a bit going on in the world at the moment. The dreaded virus and economic volatility but somehow I made a little progress.

Semi-related news: I bit the bullet and invested in a very basic Win10Pro Quad core thingamajigy Ryzen whatcha-macall-it PC (first PC in 11 years) to make my cTrader algo dev more enjoyable. Machine is pretty basic spec but you get a lot of PC for your money compared to my beloved fan boi Macs.. But of course I'll all about 'right tool for the job' etc.

Right Moving on.

Evaluation requirements...
My stupid simple moving average crossover dummy model needs to be evaluated. So a few things,
  • I need an easy way to review the optimisation results.
  • I need an easy way to review each backtest from said optimisation results.
cTrader gives some tools for this with the typical metrics however I would have to save, export etc the optimisation results and no chance of the backtest results.

I wrote a simple c# library to let me write out the optimisation passes if required abusing the GetFitness function they provide to do custom GA fitness. I simply wrote the return to be Equity and also wrote out the stats they provide. Since I intend to chose parameters based on my own critera this is ok.

For the backtest trades etc this is simpler as I added a small library call to write out the trade history(closing any final open positions) with my additional stats. Additional stats being The highest and lowest price that occurred over the open-close time of the trade(so I can later use for MAE and MFE in jupyter). I'm sure there is an easier way but its close enough for Jazz.

Cool. Now I get a boat load of files spat into a backtest folder with names resembling BOTNAME-Pair-Timeframe-Param1-Param2.....-Opt(or Test).csv

What more do you need?

Since this is a 60min Dummy model and I'm just using Eur/usd I set the optimisation params as follows.
Time was 1st Nov to 1st Feb. Again, live I would be considering longer periods etc.
I'm happy to let it go through 20 x 50 tests but of course we are using GA so no guarantee it will do that. I've also decided that I'll optimise using only the Open prices of the hourly bars.

This is because I don't use SL/TPs and I'm setting spread as 1pip+comms instead of my live 0-0.1 + comms. If this was for real I would definitely test my final candidates on tick data.

Run it!!!!... 7 seconds pass.
Done. This creates a bunch (700+) passes of Opt and Test files.

To evaluate I could do it in cTrader.. I could.. I would probably chose some meaningful optimisation constraints.. max profit, max sharp and max trades and min DD etc.. but I don't want to be tied. I would rather build a simple env to evaluate externally.

Jupyter is a natural choice but I'm also a touch lazy for this 'Dummy Model' POC so I'm also going to use dtale. This will let me review some basic charts dynamically without too much effort. Frankly you don't need more than a scatter, heatmap and bar chart/histogram so its good for now and gets you up and running quick.

Notebook: I simply looped the folder to load the csv files into 2 dataframes. 1 for optimisation summary and 1 for backtest results. added some columns for the params and calulated MFE + MAE based on the trade direction and the high/low. Then tell detail to display them..

The result?
Param0, Param1 and Net Profit. (fast+slow ma + profit post comms etc)
Observation: you can see a cluster of profitable params in the lower left.

The only issue I have is I can't change the color scale so its hard to distinguish positive vs negative.

So the next chart will fix that.

Param0, Param1 and Clamped Net Profit. (fast+slow ma + profit post comms with -ve clamped to 0)
Rather than remove the -ve I've clamped. This will avoid a sparse set of results...
Ah that is easier.


Now we can see something more interesting (over the test period at least).
The 'white' are the GA's skipped passes as it didn't evaluate them. I think its safe to assume at this stage that 20/80 would be green.. Of course live we would test.

Observation: Seems long parameter 100 is a winner across a spectrum of short params.

Just to take a look at the slow param1.. profit centred around 100 with 50-150 looking ok.
Fast param0 there is a big spread of values that are profitable.

Great so at initial glance it looks like fast/slow of 5-50 vs 50-150 looks pretty good.

At this point I would (and did to some degree) test on the period following 1st feb-march on a few of these parameter sets. The results were actually pretty similar but I can't commit more time to the crap lol writing it up. I basically picked 20-100 and ran it across the whole period on ticks... it looked good.. the end. ;)

Optimisation part 2 MAE/MFE
So if we were to briefly consider MAE and MFE for stop losses and targets etc.. then its a simple enough job.. Either optimise with those and your fixed params or use the data we have and pick a subset to review.

If I use dtale to filter on 5-50 fast with 100 slow (just for fun to see more than one) and group based on the fast param for pretty colours.)

Note: Rob Carver says its better to deal with the average.. So by leaving a bunch of them on the screen I'm reminded I'm not expecting perfection.

testing-MAE .png

Observation: If we were to look at all trades that ended profitable based on the MA cross (right side of screen for profitable) you can see that +ve trades didn't go below -0.0040 pips (vertical).
If we set a SL of -40 pips then we are likely to leave the profitable ones and clamp/limit the losses to -40( or 35 etc) on the bottom left section of trades.
This would have a knock on impact to things so needs to be considered carefully but if you can't improve your winners then close the losers

If we look at the maximum positive movements we see the following. Closing profit along the X and positive movement over its lifetime on the Y.
testing-MFE .png
Observations: There are a bunch of losing trades on the left that hug the x axis. They never went positive really. We can assume that if we had our -40 stop then we can ignore anything left of that.
There is a cluster above that that hit around 50pips profit before closing negative. Its possible a break even or partial close may be of benifit.
Looking on the winning trades on the right we can see unsurprisingly that the MA gives up a lot of profit else it would be a 45 degree line. (see 0.0040 netprof X and 0.0075 MFE Y). Given we are using the same signal to exit this should not be a shock. Multiple targets may be of use here but again beyond ther scope of me caring to do it since its a crappy model.

Summary Time
I did some optimisation, we checked a little on the robustness of parameters via heatmaps and I (take my word for it did a little OOS testing). There are so many rabbit holes we could go down and this is part of the challenge.

I laid out the pipeline as a guide not rules. I could and may do more optimisation/validation etc on better models but doing this exercise has been useful. Its given me cause to consider how to make this easier going forward and what can be explored if needed.

Any point/comments/ suggestions before I move onto Risk shout up.

Next time.. Risk/ Monte Carlo / Position sizing etc.
Are you using cTrader exclusively? ie over MT4/MT5?

I played with cTrader and cAlgo a few years ago. Ended up back to 100% MT4, never much liked C#, or anything M$ for that matter. I consider placing all ones eggs in a M$ basket (read C#) may result in a high voice.

I am now 100% Linux, which runs MT4 under Wine with no issues. Apparently cTrader does not run under Wine, due to no support for WPF, although VB may be an option.
FTMO Trader Scouting