Hello,
I am stuck again with this error message "Tried to reference back more bars (..) than allowed by the current MaxBarsBack setting".
I tried it all but I cant figure it out.
Is it my way to setup the code?
The barssinceentry could be the problem but I don't understand why?
Thanks for the help and any suggestion more than welcomed,
Best,
N.
inputs:
Length(14),
OverSold(-45),
OverBought(45);
variables:
var_CCI(0),
current_CCI_High(0),
cum_CCI(0),
open_bars_count(0),
var1(0),
var2(0);
var_CCI = CCI(Length);
// ====================================================================================================================
{ Opening/Closing Long Position }
{ Open Long: CCI crosses above the Overbought level }
condition1 = (currentBar > 1) and (MarketPosition = 0) and (var_CCI crosses above OverBought);
if condition1 then
var1 = 1
else
var1 = 0;
condition2 = (CurrentBar > 1) and (MarketPosition = 1) and (cum_CCI >= 5);
if condition2 then
var2 = 1
else
var2 =0;
{ Enter a long trade }
if (var1 = 1) then begin
Buy ("LE") 100 shares next bar at market;
current_CCI_High = var_CCI;
end;
{ Close Long: 5 down bars since entr}
if (MarketPosition = 1) then begin
cum_CCI = 0;
for open_bars_count = 0 to barssinceentry begin
if (var_CCI[open_bars_count] > current_CCI_High) then begin
cum_CCI = cum_CCI + 1;
current_CCI_High = var_CCI[open_bars_count];
end;
end;
end;
{ Close a long trade }
if (var2 = 1) and (MarketPosition = 1) then begin
Sell ("LX") 100 shares next bar at market;
end;
Getting nuts with the "Tried to reference back more bars"
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Getting nuts with the "Tried to reference back more bars
ps. please use the code tags when posting codes.
-
- Posts: 21
- Joined: 16 Feb 2011
- Location: Switzerland
- Has thanked: 1 time
- Been thanked: 1 time
Re: Getting nuts with the "Tried to reference back more bars
Here it is
Cheers,
N.
Cheers,
N.
Code: Select all
inputs:
Length(14),
OverSold(-45),
OverBought(45);
variables:
var_CCI(0),
current_CCI_High(0),
cum_CCI(0),
open_bars_count(0),
var1(0),
var2(0);
var_CCI = CCI(Length);
// ====================================
{ Opening/Closing Long Position }
{ Open Long: CCI crosses above the Overbought level }
condition1 = (currentBar > 1) and (MarketPosition = 0) and (var_CCI crosses above OverBought);
if condition1 then
var1 = 1
else
var1 = 0;
condition2 = (CurrentBar > 1) and (MarketPosition = 1) and (cum_CCI >= 5);
if condition2 then
var2 = 1
else
var2 =0;
{ Enter a long trade }
if (var1 = 1) then begin
Buy ("LE") 100 shares next bar at market;
current_CCI_High = var_CCI;
end;
{ Close Long: 5 down bars since entr}
if (MarketPosition = 1) then begin
cum_CCI = 0;
for open_bars_count = 0 to barssinceentry begin
if (var_CCI[open_bars_count] > current_CCI_High) then begin
cum_CCI = cum_CCI + 1;
current_CCI_High = var_CCI[open_bars_count];
end;
end;
end;
{ Close a long trade }
if (var2 = 1) and (MarketPosition = 1) then begin
Sell ("LX") 100 shares next bar at market;
end;
-
- Posts: 742
- Joined: 09 Apr 2010
- Location: Texas
- Has thanked: 483 times
- Been thanked: 274 times
- Contact:
Re: Getting nuts with the "Tried to reference back more bars
I think one problem is, that I think you forgot to define what "cum_CCI " is ..you just have the variable set to 0;
- Stan Bokov
- Posts: 963
- Joined: 18 Dec 2009
- Has thanked: 367 times
- Been thanked: 302 times
Re: Getting nuts with the "Tried to reference back more bars
Why don't you increase your MaxBarsBack setting in your Strategy Properties?
-
- Posts: 21
- Joined: 16 Feb 2011
- Location: Switzerland
- Has thanked: 1 time
- Been thanked: 1 time
Re: Getting nuts with the "Tried to reference back more bars
Sptrader and Stan,
Thanks for the feedbacks.
The cum_CCI is a trigger: when it reaches the value >=5, there is a sell order.
I increased the barbacks to 100 but it doesnt change anything.
My guess is that one of my loop is not correctly set but I just cant figure it out.
Thanks,
N.
Thanks for the feedbacks.
The cum_CCI is a trigger: when it reaches the value >=5, there is a sell order.
I increased the barbacks to 100 but it doesnt change anything.
My guess is that one of my loop is not correctly set but I just cant figure it out.
Thanks,
N.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Getting nuts with the "Tried to reference back more bars
barssinceentry is giving you the pain.Sptrader and Stan,
Thanks for the feedbacks.
The cum_CCI is a trigger: when it reaches the value >=5, there is a sell order.
I increased the barbacks to 100 but it doesnt change anything.
My guess is that one of my loop is not correctly set but I just cant figure it out.
Thanks,
N.
-
- Posts: 21
- Joined: 16 Feb 2011
- Location: Switzerland
- Has thanked: 1 time
- Been thanked: 1 time
Re: Getting nuts with the "Tried to reference back more bars
Hi TJ,
Indeed but where I bug: how come it gives me the pain? I just can't figure it out.
By the way, does Powerlanguage enables you to check your code line by line "a la" VBA?
Thanks,
Nicolas
Indeed but where I bug: how come it gives me the pain? I just can't figure it out.
By the way, does Powerlanguage enables you to check your code line by line "a la" VBA?
Thanks,
Nicolas