maxbars back error

202 views
Skip to first unread message

Robert K

unread,
Mar 7, 2015, 2:18:30 PM3/7/15
to adaptrad...@googlegroups.com
i get stuck on an error when I input the  strategy below:
"tried to reference more bars than allowed by the current maxbars back setting. Please increase...

{-------------------------------------------------------------------------------
 Trading Strategy Code
 Population member: 15
 Max bars back: 99

 Created by: Adaptrade Builder version 1.7.2.1
 Created:    3/7/2015 4:27:35 PM

 Scripting language: TradeStation 6 or newer

 Price file:  @ES5minutre 5 months.txt
 Build dates: 1/23/2015 to 2/19/2015

 Project file: 
-------------------------------------------------------------------------------}

{ Strategy inputs }
Inputs: NL1 (57),            { Indicator look-back length (bars), long trades }
        NL2 (81),            { Indicator look-back length (bars), long trades }
        NL3 (85),            { Indicator look-back length (bars), long trades }
        NL4 (99),            { Indicator look-back length (bars), long trades }
        NL5 (23),            { Indicator look-back length (bars), long trades }
        NS1 (10),            { Indicator look-back length (bars), short trades }
        NS2 (53),            { Indicator look-back length (bars), short trades }
        NS3 (82),            { Indicator look-back length (bars), short trades }
        NS4 (99),            { Indicator look-back length (bars), short trades }
        ShiftS1 (15),        { Indicator shift value (bars), short trades }
        MMStopSz (0),        { Value of fixed size money management stop per share/contract }
        TrailFlrL (0),       { Trailing stop floor value per share/contract, long trades }
        TrailPctL (81.0000), { Trailing stop percentage, long trades }
        TrailFlrS (0.2500),  { Trailing stop floor value per share/contract, short trades }
        TrailPctS (63.0000), { Trailing stop percentage, short trades }
        PSParam (100.00),    { Position sizing parameter value }
        RoundPS (true),      { Round-to-nearest (true/false) }
        RoundTo (1),         { Round-to position size value }
        MinSize (1),         { Minimum allowable position size }
        SizeLimit (100);     { Maximum allowable position size }

{ Variables for entry and exit prices }
Var:    LStop    (0),
        NewLStop (0),
        LTrailOn (false),
        SStop    (0),
        NewSStop (0),
        STrailOn (false);

{ Variables for entry and exit conditions }
Var:    VarL1     (0),
        VarL2     (0),
        VarL3     (0),
        VarL4     (0),
        VarL5     (0),
        VarL6     (0),
        VarS1     (0),
        VarS2     (0),
        VarS3     (0),
        VarS4     (0),
        EntCondL  (false),
        EntCondS  (false),
        ExCondL   (false),
        ExCondS   (false),
        EndofSess (false);

{ Variables for position sizing }
Var:    NShares  (0);

{ Entry and exit conditions }
VarL1 = CloseD(1);
VarL2 = ZLTrend(VarL1, NL1);
VarL3 = RSI(VarL2, NL2);
VarL4 = SlowD(NL3);
VarL5 = DMIPlus(NL4);
VarL6 = DMIMinus(NL5);
VarS1 = DMIPlus(NS1);
VarS2 = Lowest(VarS1, NS2);
VarS3 = ADX(NS3);
VarS4 = ZLTrend(Volume, NS4)[ShiftS1];
EntCondL = VarL3 crosses below VarL4;
EntCondS = VarS2 <= VarS3;
ExCondL = VarL5 >= VarL6;
ExCondS = Volume crosses below VarS4;

EndofSess = false;
If DataCompression >= 1 and DataCompression <= 4 then
    EndofSess = (Time = SessionEndTime(0, 1));

{ Position sizing calculations }
NShares = PSParam;

If RoundPS and RoundTo > 0 then
    NShares = IntPortion(NShares/RoundTo) * RoundTo;

NShares = MaxList(NShares, MinSize);
NShares = MinList(NShares, SizeLimit);

{ Entry orders }
If (MarketPosition = 0 or EndofSess) and (EntriesToday(Date) < 5 or EndofSess) and EntCondL then begin
    Buy("EnMark-L") NShares shares next bar at market;
end;

If (MarketPosition = 0 or EndofSess) and (EntriesToday(Date) < 5 or EndofSess) and EntCondS and EntCondL = false then begin
    Sell short("EnMark-S") NShares shares next bar at market;
end;

{ Exit orders, long trades }
If MarketPosition = 1 and EndofSess = false then begin
    If BarsSinceEntry = 0 then begin
        LStop = 0;
        LTrailOn = false;
    end;

    If C - EntryPrice > TrailFlrL/BigPointValue then
        LTrailOn = true;

    If LTrailOn then begin
        NewLStop = EntryPrice + TrailPctL * (C - EntryPrice)/100.0;
        LStop = MaxList(LStop, NewLStop);
    end;

    If LTrailOn then
        Sell("ExTrail-L") next bar at LStop stop;

    If ExCondL then
        Sell("ExMark-L") next bar at market;
end;

{ Exit orders, short trades }
If MarketPosition = -1 and EndofSess = false then begin
    If BarsSinceEntry = 0 then begin
        SStop = Power(10, 10);
        STrailOn = false;
    end;

    If EntryPrice - C > TrailFlrS/BigPointValue then
        STrailOn = true;

    If STrailOn then begin
        NewSStop = EntryPrice - TrailPctS * (EntryPrice - C)/100.0;
        SStop = MinList(SStop, NewSStop);
    end;

    If STrailOn then
        Buy to cover("ExTrail-S") next bar at SStop stop;

    If ExCondS then
        Buy to cover("ExMark-S") next bar at market;
end;

SetStopShare;
SetStopLoss(MMStopSz);

SetExitOnClose;

Michael R. Bryant

unread,
Mar 7, 2015, 2:32:42 PM3/7/15
to adaptrad...@googlegroups.com

I’m not clear on what you’ve already tried, but, just to be clear, it’s saying the maxbarsback setting needs to be at least 99 bars, as shown in the strategy code heading block. This number is also listed in the Build Results tables. The process of transferring the strategy code to the platform is covered in the guide in Build Results, Strategy Code Window. On occasion, particularly with complex strategies that involve indicators of indicators of indicators, and so on, this number may need to be increased slightly.

 

Mike Bryant

Reply all
Reply to author
Forward
0 new messages