bar counter for tradestation

Discussion in 'Strategy Development' started by gdtrader, May 26, 2005.

  1. Can anyone give me some code with barcounters I am really terrible with them. A few examples would be nice. If 52 week high then bar counter=1 then start searching for previous low. What ever anything I am just making example. Would really appreciate it thanks.
     
  2. Kermit

    Kermit

    Hi gdtrader:

    Don’t know if this will help:

    It basically scans for the highest price and the lowest price between the first bar on the chart and the last bar on the chart and records at which bar each took place (absolute) and how far ago they took place from the current last bar on the chart (relative).

    Kermit


    Code:
    Variable:
    	HighestHigh(0),
    	LowestLow(0),
    	highestBarlocation(0),
    	LowestBarlocation(0);
    	
    If BarNumber = 1 Then
    	Begin
    		HighestHigh = -99999;
    		LowestLow = 99999;
    	End;
    
    if high > highesthigh then   
    	Begin       
    		HighestHigh = high;
    		HighestBarlocation = currentbar;	
    	End
    Else
    	If low < lowestlow then             
    		Begin
    			LowestLow = low;               
    			LowestBarlocation = currentbar;
    		End;
     
    If LastBarOnChart = True Then
    	Begin
    		print(" ");
    		print("Current bar = ",currentbar:5:0);
    		print("The highest high was ",HighestHigh:4:4, 
    			  " took place at bar# ", HighestBarlocation:5:0, 
    			  " which was ", currentbar - HighestBarlocation:5:0, 
    			  " bars ago.");
    		print("Lowest low was ", LowestLow:4:4, 
    			  " took place at bar# ", LowestBarlocation:5:0, 
    			  " which was ", currentbar - LowestBarlocation:5:0, 
    			  " bars ago.");
    	End;