Problem Executing Code in TS8.1

dima777

Member
Messages
85
Likes
1
Hi!
I am having difficulty running the following code in TS8. when i import it it verifies ok. but when i try to run it on a chart it gives the following error:"tried to reference future data". This code works fine in TS200i. Can you pease check it to see what should be modified to have it run ok in ts8?
thanks!
the code:
Code:
{==========================================DECLARATIONS=======================}

INPUTS: 
STRENGTH(3),
OCCUR(1),
LENGTH(50),
FREEZE(FALSE),
SHOBKOUT(TRUE);

VARS:
BKOUTVAL(0),
BKOUTBAR(0),
BREAKOUT(FALSE),
JLA_LINE(0),
W(0),
STR1(0),
STR2(0),
STR2A(0),
STR3(0),
STR3A(0),
JLA_CTR(0),
TDL1(0),
TDL2(0),
TDL3(0),
TDL1BAR(0),
TDL2BAR(0),
TARGET1(0),
TARGET2(0),
TARGET3(0),
JLA_FRZ(FALSE),
JLA_SLOPE(0);


{+++++++++++++++++++++++++++++FIND POINTS 1 AND 2++++++++++++++++}

     TDL1BAR = SWINGLOWBAR(OCCUR,TRUELOW,STRENGTH, LENGTH);
     TDL1 = L[TDL1BAR];
     TDL2BAR = 0;
     TDL2 = 999999;
     JLA_CTR = OCCUR + 1;
     WHILE TDL2 > TDL1 AND TDL2BAR <= LENGTH AND TDL2BAR <> -1
     BEGIN
        TDL2BAR = SWINGLOWBAR(JLA_CTR,TRUELOW,STRENGTH,LENGTH);
        TDL2 = L[TDL2BAR];    
        JLA_CTR = JLA_CTR + 1;
     END;
  IF FREEZE = TRUE THEN JLA_FRZ = TRUE;

{++++++++++++++++++++++++++LOOK FOR BREAKOUT+++++++++++++++++++++}

   IF TDL2BAR <> -1 THEN 
   BEGIN
        PLOT3[TDL2BAR](TDL2,"TARGET 3");
        PLOT3[TDL1BAR](TDL1,"TARGET 3");
       CONDITION15 = FALSE;
       BREAKOUT = FALSE;
       JLA_SLOPE = (TDL2 - TDL1) / (TDL1BAR - TDL2BAR);          
       JLA_CTR = TDL1BAR - STRENGTH; 
       JLA_LINE = 0;
       WHILE JLA_CTR >= 0 AND L[JLA_CTR+ 1] > JLA_LINE 
       BEGIN
             JLA_LINE = (TDL1 + (TDL1BAR - JLA_CTR) * JLA_SLOPE);
  		 IF L[JLA_CTR] < JLA_LINE THEN CONDITION15 = TRUE;
	      JLA_CTR = JLA_CTR - 1;
       END;
	      FOR W = TDL2BAR DOWNTO 0 
       BEGIN
          PLOT1[W](TDL2 + (TDL2BAR - W) * JLA_SLOPE,"UPTREND");
       END; 
  
{+++++++++++++++++++++++++BREAKOUT HAS OCCURRED+++++++++++++++++}

	IF CONDITION15 AND SHOBKOUT = TRUE THEN
      BEGIN
   		     BKOUTBAR = JLA_CTR + 1;
                 BKOUTVAL = JLA_LINE;                                  
                 PLOT2[BKOUTBAR](H[BKOUTBAR],"TARGET 2");	
 
{+++++++++++++++++++++++++++BREAKOUT QUALIFIERS+++++++++++++++++}

                 CONDITION1 = C[BKOUTBAR + 1] > C[BKOUTBAR + 2];
                 CONDITION2 = OPEN[BKOUTBAR] < BKOUTVAL  
                                          AND L[BKOUTBAR +1] > BKOUTVAL;
                 CONDITION3 =  2 * C[BKOUTBAR + 1] - MAXLIST(C[BKOUTBAR + 2], 							TRUEHIGH[BKOUTBAR + 1])  > BKOUTVAL;
                 IF (CONDITION1 OR CONDITION2 OR CONDITION3) THEN 


{+++++++++++++++VALID BREAKOUT-SET TARGETS+++++++++++++++++++++++++}

                 BEGIN
                      BREAKOUT = TRUE;
                      IF CHECKALERT THEN ALERT = TRUE; {===this line moved 5/31/96=====}
                      STR1 = 0;
                      STR2 = 0;
  			    STR2A = 0;
                      STR3 = 0;
			    STR3A = 0;
                      FOR W = TDL2BAR DOWNTO TDL1BAR 
                      BEGIN
           	            JLA_LINE = (TDL2 + (TDL2BAR - W) * JLA_SLOPE);
           	            IF H[W] - JLA_LINE > STR1 THEN STR1 = H[W] - JLA_LINE;
               	      IF C[W] - JLA_LINE > STR2A THEN
				BEGIN
				  STR2A = C[W] - JLA_LINE;
				  STR2 = H[W] - JLA_LINE;
				 END;
               	      IF H[W] - JLA_LINE > STR3A THEN
				BEGIN
			 	   STR3A = H[W] - JLA_LINE;
				   STR3 = C[W] - JLA_LINE;
				END;
                      END; {FINISHED DEFINING STRENGTHS}
                      TARGET1 = BKOUTVAL- STR1;
                      TARGET2 = BKOUTVAL- STR2;
                      TARGET3 = BKOUTVAL- STR3;
                   
                END;  {FINISHED VALID BREAKOUT SETUP}  
       END;  {FINISH BREAKOUT SETUP}           

{+++++++++++PLOT STATEMENTS AFTER CONFIRMED BREAKOUT+++++++++++++}

      IF BREAKOUT = TRUE THEN
      BEGIN
         PLOT4[BKOUTBAR](H[BKOUTBAR],"BREAKOUT");
         W = BKOUTBAR;
         WHILE W >= 0  AND  L[W] > MINLIST(TARGET1, TARGET2, TARGET3)
         BEGIN
          PLOT2[W](TARGET2,"TARGET 2");
          PLOT3[W](TARGET3,"TARGET 3");
          W = W -1;
        END;  {FINISHED PLOTTING}
     END;{FINISHED  BREAKOUT = TRUE}  

{+++++++++++++++++++++++++++CLOSE REMAINING LOOPS++++++++++++++}

     END;  {NO POINT 2}
 
This issue will arise in TS8.1 ++ whenever you try to pass in a variable that can have a negative value to a pricing. This often occurs when a person is calling a function in TradeStation where the function will return a negative number if a certain condition is not found. Then this return value is passed as a variable to a price which will then subsequently fail. In your code example this is the case. The culprit is in this snippet of code

TDL1BAR = SWINGLOWBAR(OCCUR,TRUELOW,STRENGTH, LENGTH);
//TDL1 = L[TDL1BAR]; This can push a -1 into the price offset which will crash
TDL1 = L[iff( TDL1BAR >= 0, TDL1BAR, 0)];
TDL2BAR = 0;
TDL2 = 999999;
JLA_CTR = OCCUR + 1;
WHILE TDL2 > TDL1 AND TDL2BAR <= LENGTH AND TDL2BAR <> -1
BEGIN
TDL2BAR = SWINGLOWBAR(JLA_CTR,TRUELOW,STRENGTH,LENGTH);
//TDL2 = L[TDL2BAR];
TDL2 = L[iff( TDL2BAR >= 0, TDL2BAR, 0)];
JLA_CTR = JLA_CTR + 1;
END;
IF FREEZE = TRUE THEN JLA_FRZ = TRUE;

The SwingLowBar and SwingHighBar functions are a multiple output function which calls the underlying function named pivot. the pivot function will seek out a condition within a certain length of bars and if it finds the obbject then it will return the object, but if it does not find the object then it is going to return a -1 to let you know that you have an error. In the current versions of TradeStation they are going to throw an exception because you can't reference prices that haven't happened yet. They do this because people would use a code set on historical data and then this same code set would not work in real life. In the code snippet above, I show one method of preventing the future reference error. There are other methods depending on your desired end goals.

Greg
 
thanks a lot for your generously thorough reply...that explains everything...it helped a lot!)
 
Top