I'm trying to code simple scan in Tradestation but can't figure out how to use 2 different timeframes. Hope somebody can help. This is what I'm trying to code: on 5 min chart looking for highest(high, 60) and on daily chart needs to be above bolligerband upperband I'm scanning in radarscreen, all symbols 5 min interval Thank you in advance!
the functions HighD, LowD, and CloseD are helpful for what you are trying to do. They reference daily HLC values from within an intraday chart (bartype < 2). For the simple case of price being the close of the daily bar, you can simply use CloseD to reference the past N daily closes, including the current unfinished close if the session is active. For bollinger bands, you first need to calculate the average: avg = 0; for index = 0 to N - 1 begin avg = avg + (1 / N) + CloseD(index); end; next is the standard deviation: var = 0; for index = 0 to N - 1 begin var = var + (1 / (N - 1)) * square(CloseD(index) - avg); end; std = squareroot(var); last thing is to calculate the band values: upperband = avg + numStd * std; lowerband = avg - numStd * std; your filtering criteria is then closeD(0) > upperband; hope this helps, rt
to copy & paste maybe it could help others Inputs: Period( 20 ), NumDevs( 2 ); Variables: mean(0), sumSqr(0), stdDev(0), i(0), x(0), UpPerBand(0), LowerBand(0); sumSqr = 0; mean = 0; for x = 0 to Period - 1 do mean = mean + CloseD(x); mean = mean / x; For i = 0 To Period - 1 Do sumSqr = sumSqr + Sqr( CloseD(i) - mean ); If sumSqr > 0 And period > 0 Then stdDev = Sqrt( sumSqr / Period ) Else stdDev = 0; UpperBand = mean + NumDevs * stdDev; LowerBand = mean - NumDevs * stdDev; if UpperBand > 0 then plot1( UpperBand ); if LowerBand > 0 then plot2( LowerBand );
Two ways: - Create one list with a daily interval and modify the BB code to write current values to a global variable. Create a second list set to 5min and read the global variable to perform your test. - The second requires a single 5min list, but is a bit more difficult to implement since you need to use ADE to create the daily bars synthetically.