Hi krzysiaczek99,
The FAQ that TJ pointed out does have the correct information for handling multiple data series, including function calls. The topic is not the most apparent to figure out for an easy language. It is ok to ask how to write the code but you included a function from John Ehler that we don't have.
You should start with basic print statements to show what you want and what is not happening when you try to iterate over data values. I wrote some example code to help you understand.
Code: Select all
inputs: dataindex(2), RSILen(5);
var: Price(0);
if BarStatus(dataindex)<0 then raiseruntimeerror("Need datastream "+NumToStr(dataindex, 0));
for value1=1 to dataindex
begin
Price=C Data(value1); // wrong
print("Close of Data", value1:0:0, ": ", C Data(value1):0:0, ",",
" RSIa Data", value1:0:0, ": ", RSI(Price, RSILen):0:0, ",", // wrong
" RSIb Data", value1:0:0, ": ", RSI(C Data(value1), RSILen):0:0, // sometimes wrong
" RSIc Data", value1:0:0, ": ", RSI(C Data(value1), RSILen) Data(value1):0:0, // correct
" RSId Data1: ", RSI(C, RSILen):0:0);
end;
I wrote it quickly, so be patient and understanding if it has a mistake.
Hi,
I believe its misunderstanding what the fault is, please see my fist messages.
to reproduce it.
1) create chart with 2 instruments.
2) apply the script with ANY strategy which allows to change input series used by selecting data series like code below. You can use ordinary RSI. (see code below)
3) set idx to 1
4) check strategy performace results in view/ strategy performance
5)set idx to 2
6) check strategy performace results in view/ strategy performance. You will see that results are wrong i.e. trades are with prices from idx=1 (data1)
if you make another chart with series data2 only and apply this strategy, backtest will give you different results then from fist chart when idx=2.
7) the same bug occurs when you will use optimizer i.e. when you iterate over idx, chart one for idx=2 gives different results than strategy with data2 in second chart
I detected this bug when I tried to reproduce optimizer backtest results using Python backtester. I made EL code which makes a backtest in EL script
and data is feeded to EL script correctly but at the same time reserved variables GrossProfit and GrossLoss are set incorrectly internally so when you make a view in strategy performance or optimizer results it give wrong results .
Please see my initial message and screenshots.
Krzysztof
Code: Select all
Inputs: idx(1); //dataindex(1),
Inputs: RSILength(14);
Vars: oResult1(0), ObLevel(0.8), OsLevel(-0.8), Price(0), Price1(0, Data1), Price2(0, Data2);
if idx = 1 then begin
Price1 = Close data1;
Price = Price1;
end;
if idx = 2 then begin
Price2 = Close data2;
Price = Price2;
end;
//Var: Close2( 0, data2 );
//Close2 = Close data2;
//Price = Close of Data(dataindex);
oResult1 = JohnEhler_My_RSI( RSILength, Price );
if oResult1 crosses under 0 then
SellShort("0crossSell") next bar at Market
else if oResult1 crosses over 0 then
Buy("0crossBuy") next bar at Market ;
if oResult1 crosses under ObLevel then
SellShort("ObCross") next bar at Market
else if oResult1 crosses over OsLevel then
Buy("OsCross") next bar at Market;