|
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
|
|