Trying to Run Daily with Real Time Minute Data

Hey guys,

I'm having some issues, all related to having multiple timeframes. I read all the posts I can find (even my own) and I thought I had incorporated the proper code, but still something is off.

The following is just an example for me to better understand how this works.

I would just like a simple daily model to be updated throughout the day on minute data.

I'm trying to get to look at the MACD Daily to see if it is above 0, and the minute is to monitor how it trades throughout the day (1 min) and buy when the stock price close on that minute bar hits the close from yesterday (between 10am and 3:30pm) and at that price (yesterday's close).

I thought the following should work, but for some reason it does not. I tried to AddColumn and see what the data is, but nothing pops up on Exploration either (no trades at all).

Any idea of what I am doing wrong?

Thanks so much for any help or suggestions!

//Daily used with 1min real time data
SetPositionSize(10, spsPercentOfEquity);

dailyTM = inDaily;
TimeFrameSet (dailyTM);
DMACDPos = MACD (12,26) > 0;
DMACDNeg = MACD (12,26) < 0;
YClose = Ref (Close, -1);
TimeFrameRestore();

expand_mode = expandLast ;
DMACDPos = TimeFrameExpand(DMACDPos, dailyTM, expand_mode);
DMACDNeg = TimeFrameExpand(DMACDNeg, dailyTM, expand_mode);
YClose = TimeFrameExpand(YClose, dailyTM, expand_mode);

Time = TimeNum();
startTime = 100000;
endTime = 153000;
TimeCheck = Time >= startTime AND Time <= endTime;

Buy =
DMACDPos
AND Close < YClose
AND TimeCheck
AND BuyPrice = YClose
;

Sell = DMACDNeg;

AddColumn( C, "Close" );
AddColumn( DMACDPos, "DMACDPos" );
AddColumn( DMACDNeg, "DMACDPos" );
AddColumn( YClose, "DMACDPos" );

Hello Krazycanuck,

  1. You have to define your Filter correct, use to display everything "Filter = 1"
  2. Re-think your conditions to "Filter", for example "BuyPrice = YClose" should be "BuyPrice == YClose"
  3. Select in "Analysis settings" - Periodicity [Daily]
  4. Check your conditions are working correct by showing results in your Exploration Window
//Daily used with 1min real time data
SetPositionSize( 10, spsPercentOfEquity );

dailyTM = inDaily;
TimeFrameSet( dailyTM );
DMACDPos = MACD( 12, 26 ) > 0;
DMACDNeg = MACD( 12, 26 ) < 0;
YClose = Ref( Close, -1 );
TimeFrameRestore();

expand_mode = expandLast ;
DMACDPos = TimeFrameExpand( DMACDPos, dailyTM, expand_mode );
DMACDNeg = TimeFrameExpand( DMACDNeg, dailyTM, expand_mode );
YClose = TimeFrameExpand( YClose, dailyTM, expand_mode );

Time = TimeNum();
startTime = 100000;
endTime = 153000;
TimeCheck = Time >= startTime AND Time <= endTime;

Buy =
    DMACDPos
    AND Close < YClose
    AND TimeCheck
    AND BuyPrice == YClose;

Sell = DMACDNeg;

Filter = 1;

AddColumn( C, "Close" );
AddColumn( DMACDPos, "DMACDPos" );
AddColumn( DMACDNeg, "DMACDPos" );
AddColumn( YClose, "DMACDPos" );
AddColumn( Buy, "Buy" );
AddColumn( Sell, "Sell" );

image

Regards,
Peter

1 Like

Thank you Pietro.

Just a follow-up, if I am trying to obtain signals on a 1 minute scale, should I not use the shortest timeframe in Periodicity and then change the time to a longer period through TimeFrameSet? I read that in the Amibroker guide " you can only compress data from shorter interval to longer interval "

Maybe I wasn't clear but I'm trying to get the model to look on a daily basis for X and Y (whatever filters) from yesterday, if yes for X and Y then run it on a 1 minute basis for today to trigger etc...

So, for example, if MACD from yesterday (daily) was > 0 and the current 1 minute close is < yesterday's EOD close, buy it at yesterday's closing price.

Is the code correct for this goal? Because when I run a backtest for the past couple of days with 1 min periodicity, there are 0 stocks that have MACD greater than 0 and a price drop during the day (1 minute) below the prior close(day), which I know is wrong.

I must be doing something wrong with the multiple period situation, but can't figure out what. Is my use of TimeFrameSet/TimeFrameExpand etc... incorrect?

Hello Krazycanuck,

My approach is always to check the values in your case "Daily" periodicity to become comfortable with these data to expand later in the lower periodicity. So i switch first to "Daily" in Exploration setting, execute the Exploration, dump out the results and compare these values with those stored quotes of the AB database. Second i switch periodicity to "1 Minute" and execute again ... The Analysis Window values out of "Daily" periodicity will be expanded and matched to the 1 Minute now.

In this example i changed some parameters and do not customize the Filter.

//Daily used with 1min real time data
SetPositionSize( 10, spsPercentOfEquity );

dailyTM = inDaily;

TimeFrameSet( dailyTM );
DMACDPos = MACD( 6, 13 ) > 0; // current array position macd
DMACDNeg = MACD( 6, 13 ) < 0; // current array position macd
YClose = Ref( Close, -1 ); // !!! previous array position close
TimeFrameRestore();

expand_mode = expandFirst;

DMACDPos = TimeFrameExpand( DMACDPos, dailyTM, expand_mode ); // !!! expand array to 1 min timeframe
DMACDNeg = TimeFrameExpand( DMACDNeg, dailyTM, expand_mode );
YClose = TimeFrameExpand( YClose, dailyTM, expand_mode );

Filter = 1;

AddColumn( C, "Close" );
AddColumn( DMACDPos, "DMACDPos" );
AddColumn( DMACDNeg, "DMACDNeg" );
AddColumn( YClose, "YClose" );

Exploration result in Daily:

image

Exploration result in 1 Minute:

image

Regards,
Peter

2 Likes

Thanks so much Pietro, I greatly appreciate it!!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.