MAster Gold StrategyVersion 3 for you guys, just add to favorites and you can use.
Only 36 trades since 2017, since that is when the backtesting began.
I made the commission more realistic, now it is about 37 pips per trade.
Only works on gold, (XAUUSD).
Trend Following as you can see.
1 contract size, 1 trade at a time, good proof of how being correct less than a third of the time can still bring you in a lot of profits.
Essentially, the net profit will be close to $8000, or 80%, as a long position on XAUUSD is currently running, and when it is closed, the profit will go up.
Imagine that, 72% profit on your account in 3 months?
(Hint: add the indicator to your favs, pull up the 30 minute gold chart)
Pinescript
Updated Gold Strategy - Trend Following Script v4.0This strategy improves on the latest one that I posted in several ways.
the %profit is reduced by 3%
Success rate reduced by 2%
Drawdown decreased by half (from 40% to 20%)
Average trade $ increased by $500
Backtesting Period Selector | ComponentDescription
It's nice to quickly be able to set the backtesting period when writing strategies.
To make this process faster I wrote a simple 'component'.
So this is not a strategy but rather code you can plug-into your strategy and use
if you need that specific functionality.
Then it's just a matter of selecting which dates you want to backtest.
You can also chose to color the background to visually show the testing period.
Unfortunately, the background color is fixed at 'blue' for now.
Ps. I like the idea of writing small components to be pluged into other strategies
I'll try to develop this idea a bit further and see how small pieces of code can
easily provide specific functionality to assist and make deving strategies a bit less 'Pineful'.
Usage
First copy the instructed part of the component code over to your strategy.
Next, use the testPeriod() function to limit strategies to the specified backtesting period.
Example usage:
if testPeriod()
strategy.entry("LE", strategy.long)
Todo / Improvements
There are many ways to improve this component and I'm not a very good coder so this is a very crude solutions.
Anyway, here are some things which would be nice to improve:
1. Enable color selection so that the user can choose the background color of his own liking.
2. Improve naming of variables.
3. Test for ilogical choices, such as test period start being at a later date, than test period stop.
4. Account for time zones.
As always, any feedback, corrections or thoughts are very much welcome!
/pbergden
Simple Strategy Code StubThis is a very basic strategy implementation
Use as a code stub for your strategy code. I wrote it because I could not find one.
This particular strategy goes long on Tuesdays at 10 am and goes short at 3 pm on Thursdays.
Because US markets open at 9:30 you have to have your chart in 30 minute or less resolution for trades to fire.
You can gut that code and replace it with your own to start testing your own indicators and strategies.
If you build a strategy that doesn't use "hour" like I have this resolution requirement won't apply.
For giggles, compare its performance to other strategies. Weird, huh? About 53% effective on most equities and indexes.
This strategy does the minimum needed to get a strategy working
and uses default position sizes and buys at market with no stops.
Again, it is the minimal code stub needed to test an indicator/rule based strategy.
A great code reference for building more sophisticated strategies can be
found here =>
The code is written by @greatwolf and is very well structured for anyone looking to fully utilize
strategy features for position sizing, limit orders, stops and cancellations.