Click here to Login




Troubleshooting a Trading System

Updated on 2014-01-11





If your trading system doesn't generate any trade or behaves in an unexpected way, the following article will help you troubleshoot, debug and fix it.

A trading system is composed of:
- Formula
- Settings
- Ranking Systems
- Money Management Scripts (Although we call it money management script, it is actually much more than that. These scripts allow you take full control of your trading system, create adaptive strategies, metrics, dynamic position sizing…)


Step 1

If your trading system contains a money management script then the first step is to remove it (you can save it and add it later). Once done, backtest your trading system and check if the issue is fixed.

Fixed: You must probably debug the money management script now (go to the last paragraph of this article).
Not Fixed: Move to step 2.


Step 2

Check your symbols and the time frame used by the trading system. Make sure you have data for some of these symbols in the chosen time frame.
If your trading system trades S&P 500 stocks using a one-minute period then make sure you have downloaded intraday data for these S&P 500 stocks. You can check that by displaying a chart of one of these stocks using one-minute time frame.

Not Fixed: Move to step 3.


Step 3


Now, it is time to check the backtesting period (Symbols & Dates tab).
You must have quotes for the selected securities within the start and end date specified at the bottom of the control.
To make sure all data is analyzed, set for example "1900" as year for the start date and "3000" as year for the end date.

Not Fixed: Move to step 4


Step 4

Let us check the formula now.
First of all, make sure the variables "buy and sell (optional)" are initialized (long system) and "short and cover (optional) are initialized too (in the case of a short system).

For example:
filter = close > 10;

The above trading system will not generate any single trade because QuantShare will not be able to find the "buy" variable.

Instead, you should type:
buy = close > 10;
OR
filter = close > 10;
buy = filter;


If you have a trading system with several lines, the best way to troubleshoot your system is by removing a rule, performing a backtest then repeating the process again until you discover the part of code that generates the issue or the unexpected behavior.

Example:
buy = close > 10 and volume < 0;

By performing the above steps, you will easily discover that the issue is caused by the following part (volume < 0). This is because volume is never negative. To get a visual confirmation, you can select a chart, create a new pane, right click, select "Edit Formula", plot the above rule then click on "Update Graph".

Here is the formula to plot the volume time series:
a = volume < 0;
plot(a, "Test", colorRed);


On the chart, you will see that the value of variable "a" is always equal to 0.

If you get no signals after performing a backtest, then you can plot the "buy" rule on a chart (using the "plot" function described above) and see if the "buy" variable is always equal to 0 (false - no signal) or not.You can also check each rule individually to see which one is the most restrictive (prevents the system from generating signals).

Another thing to check is the system type. If you select "Short" as system type and type:
buy = close < sma(20);

Then it is clear that no signals will be generated since you want to trade a "Short" only system and you didn't specify a "short" rule in your formula.

Not Fixed: Move to step 5


Step 5

The issue could be cause because of some changes you have done in the settings.
In this case, copy your formula, create a new empty trading system, paste your formula, select symbols/period/dates then backtest.

Still Not Fixed: Send us your formula to support [at] quantshare [dot] com and we will tell you what is wrong :)


Debugging a Money Management Script

If you find that the issue is caused by your money management script then the best way to fix this is by removing the code of one event, backtesting the strategy then checking for the issue.
If the issue is still present, remove the code of another event then backtest again, until you discover which part of the code to analyze further.

After that, remove some part of the code within the event (make sure the script can still be compiled), backtest then repeat the same steps until you find out what is causing the issue.

Do not forget to save your script before performing changes.

You may also want to use the following functions to trace information during the script execution:

Divers.Output("Type info here");
// This function displays trace info in the "Details" tab of the trading system report. The trace info is stored separately for each trading day.

Global.Trace("Type info here");
// This functions displays trace info in "View -> Output"


Example of a code that can generate an error during execution:

OnStartSimulation:
Functions.SetNumericInput("My Input", 0, "");

OnEndPeriod:
int val = (int)Global.GetVariable("My Input");

By following the above steps, you will easily discover that the issue is caused by this line:
int val = (int)Global.GetVariable("My Input");

In this case, there was a casting error. Numeric input variables are of type (double), so you should change this line and type:
double val = (double)Global.GetVariable("My Input");


Please tell us about your experience in the comments section.












no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1407 days ago

Profile Graphs
Posted 1512 days ago

QuantShare
Previous Posts

Troubleshooting a Trading System
Posted 3925 days ago


More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.