Dynamic MaxBarsBack ?
Posted: Apr 04 2019
Hi all,
I use the Portfolio Trader to load, say 100 symbols. Different symbols contain different number of bars. If the symbol has >= 250 bars, the highest high of the recent 250 bars is obtained. If the symbol has < 250 bars, the highest high of all the bars is obtained.
The code is shown below.
Now, the problem is that the maxbarsback is set to be 0 so that all symbols can be loaded into the Portfolio Trader, but then there will be runtime error showing that I have tried to reference back more bars (1) ..... If the maxbarsback is set to be 250, the symbols with less than 250 bars will not be loaded into the Portfolio Trade at the beginning but I just want to include all of the symbols.
I know maxbarsback cannot be changed at runtime by code, so any other means to achieve what I want to do?
Thanks in advance.
I use the Portfolio Trader to load, say 100 symbols. Different symbols contain different number of bars. If the symbol has >= 250 bars, the highest high of the recent 250 bars is obtained. If the symbol has < 250 bars, the highest high of all the bars is obtained.
The code is shown below.
Code: Select all
if LastBarOnChart then
begin
if BarNumber >= 250 then
high_250d = highest(high, 250)
else
high_250d = highest(high, BarNumber);
end;
I know maxbarsback cannot be changed at runtime by code, so any other means to achieve what I want to do?
Thanks in advance.