Click here to Login





                                                   Backtest from a chart not resulting in any trades

  0

0
JC
2020-09-10 17:57:40


https://www.quantshare.com/sa-585-how-to-backtest-a-strategy-from-a-chart

when i execute the script, no trades come up
this is the formula..

a = Willr(14);
Plot(a, "Willr", colorBlack, chartLine, StyleSymbolNone);

plot(-20, "");
plot(-80, "");

buy = cross(a, -20); // Buy when Willr crosses above -20
sell = cross(-20, a); // Sell when Willr crosses below -20

and the script as per the instructions

string tradingSystemName = "ChartSystem";

Chart chart = Charts.GetSelectedChart();
if(chart != null)
{
// Get Chart's Data
string symbol = chart.SymbolName;
int timeframe = chart.TimeFrame;
bool isEOD = chart.IsHistorical;
string formula = "";
for(int i=0;i<chart.Panes.Length;i++)
{
for(int j=0;j<chart.Panes[i].Formulas.Length;j++)
{
string formula1 = chart.Panes[i].Formulas[j].Formula.Replace(" ", "").ToLowerInvariant();
if(formula1.Contains("buy=") || formula1.Contains("short="))
{
// Trading system formula found
formula = chart.Panes[i].Formulas[j].Formula;
break;
}
}
}

if(formula != "")
{
// Create Trading System
QSTradingSystem ts = Simulator.CreateTradingSystem("", tradingSystemName);
string[] symbols = new string[1];
symbols[0] = symbol;
ts.Symbols = symbols;
ts.Timeframe = timeframe;
ts.IsEOD = isEOD;
ts.Formula = formula;
ts.Save();
Simulator.Optimize("", tradingSystemName, true);
}
else
{
MessageBox.Show("No system formula found in the chart. Make sure you use 'buy' or 'short' variables");
}
}
else
{
MessageBox.Show("Select a chart first");
}

the result is no trades



QuantShare
2020-09-14 11:19:12

  0

Best Answer
The first thing I notice is that on the script it search for "buy=" while in your formula you have:
buy = (with extra space between "y" and "=")



JC
2020-09-14 11:43:17

  0

doh!!!
Thank you. I copied it word for word from the example but clearly didn't think about the additional space between the script and the formula
Thanks so much



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Strategy Indicator - Percent winning trades for a trading rule
How far are the close prices from the support line
Set the First Trading Bar Values to Not a Number
Current Drawdown of any Price Series or Indicator
Adaptive Trading System - Percent Winning Trades for the Last N-D...

How-to Lessons
How to add trades from one portfolio to another one
How to plot a time-series that do not update the chart scale
How to print a chart
How to plot two different time frames in the same chart
How to import trades into a portfolio

Related Forum Threads
Portfolio - opening a chart from portfolio screen
Minium number of trades per year in fitness formula is not workin...
STATIC WATCH LIST-add a symbol to existing static watch list from...
Charts not visible " No Quotes for any stock"
Backtest equity into chart

Blog Posts
How to Backtest a Strategy from a Chart
Backtesting chart patterns using the auto support and resistance ...
How to build and backtest a robust stock trading system
How to Backtest an Intraday Stock Trading System with EOD Ranking
Update Chart Layout based on Active Time Frame









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.