Plot indicators

Now we'll plot a preview of our indicator against the closing price to get an idea of what it looks like.

display(inputSeries.tail(100).plot({}, { y: ["close", "sma" ] }));

Define your trading strategy

It's time to define our trading strategy. A Grademark strategy is a simple JavaScript object that defines rules for entry and exit. We are going to enter a position when the price is below average and then exit as soon as the price is above average. I told you this was a simple strategy!

We also set a 2% stop loss that will help limit our losses for trades that go against us.

Plot your trades

Let's plot the profit on our trades to visualize what they look like... you can see that all the loosing trades are clamped to 2%, that shows that our stop loss is working.

display(trades.plot({ chartType:"bar" }, { y:"profitPct" }));

Analyze performance

To get a clear picture of how well (or not) the strategy performed we can use the analyze function to produce a summary of results.

Here we need to specify an amount of starting capital. This is the amount of (virtual) cash that we invest in the strategy at the start of trading. You can see that executing this strategy from 2015 to end 2016 delivers us a nice profit of 83%. This is fairly optimistic (it doesn't include fees and slippage) but it's a good start.

conststartingCapital=10000;
constanalysis=analyze(startingCapital, trades); // Analyse the performance of this set of trades.display(analysis);

Equity curve

For a more visual understanding of the strategy's performance over time, let's compute and plot the equity curve. This shows the total value of our (virtual) trading account over time.

Drawdown chart

We can also compute and render a drawdown chart. This gives us a feel for the amount of risk in the strategy. It shows the amount of time the strategy has spent in negative territory, that's those times when a strategy has reached a peak but is now losing value (drawing down) from that peak.