What I'm trying to accomplish:
An Exploration trading strategy that incorporates a 5 minute moving avg crossover and some actions based on 1 second bars.
Using a 1-second IQFeed database, and Analysis Periodicity set at 5 minutes, I ran an Optimization to find the best short and long moving averages (MA1 and MA2). I then plugged the MA1 and MA2 values in and ran an Exploration. With Periodicity set to 5 minutes, the resulting rows in the Exploration output are in 5 minute increments. So far so good. However, because I also want to evaluate 1 second bars, I thought it made sense to set Periodicity to 1 second, and use the TimeFrameSet function configured as in5minutes, so I could get both 1 second and 5 minute bars.
Where I'm confused:
I thought that the results of running these two Optimizations would produce the same MA1 and MA2 values:
A 1 second interval database with Periodicity = 5 minutes. See AFL 1 below.
A 1 second interval database with Periodicity = 1 minutes, and TimeFrameSet = to 5 minutes (in5minutes). See AFL 2 below.What I found is that the Optimization results are not the same. Should the results be the same? If not can somebody explain why... that might get me to finally understand. Did I code the timeframeset and timeframeexpand incorrectly???
I've been struggling with this for several days and have read all the relevant references and posts and I just can't seem to figure this out. This would be easy if all I wanted was 5-minute bars. It's the combo of 5 minute and 1 second bars that has me stumbling. Can somebody help me get my lights turned on?
One other thing worth mentioning... I've done some chart trading using real-time IQFeed and IB data during trading hours. Under that circumstance, it was easy to get real-time tick data, do some evaluations on it, write results to text files, and incorporate the results in the 5 minute moving avg crossover.. I'm struggling to do the same with real-time Explorations and I'm quite sure the issue is me and not Amibroker.
// AFL 1 - Periodicity set to 5min //============================================== MALength1 = Optimize("MA Length 1", 2, 2, 50, 5); MALength2 = Optimize("MA Length 2", 4, 2, 250, 5); ema1 = EMA( C, MALength1 ); ema2 = EMA( C, MALength2 ); Buy = Cross( ema1, ema2 ); Sell = Cross( ema2, ema1 ); Short = Sell; Cover = Buy; Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); Short = ExRem( Short, Cover ); Cover = ExRem( Cover, Short ); // AFL 2 - Periodicity set to 1sec //===================================================== MALength1 = Optimize("MA Length 1", 2, 2, 50, 5); MALength2 = Optimize("MA Length 2", 4, 2, 250, 5); TimeFrameSet(in5Minute); ema1_5min = EMA( C, MALength1 ); ema2_5min = EMA( C, MALength2 ); TimeFrameRestore(); Buy = Cross( TimeFrameExpand(ema1_5min, in5Minute), TimeFrameExpand(ema2_5min, in5Minute) ); Sell = Cross( TimeFrameExpand(ema2_5min, in5Minute), TimeFrameExpand(ema1_5min, in5Minute) ); Short = Sell; Cover = Buy; Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); Short = ExRem( Short, Cover ); Cover = ExRem( Cover, Short );