Custom daily indicators based on intraday values

I have very successful indicator that I’m trying to migrate from WealthLab. The basis for “daily” indicator is the result of intra-day processing. of minute data. While i understand how to create a custom indicator using a function and running the loops, there are few things that elude me:

1 ) I would typically use the strategy on a “daily” interval and within the function to change to intra-day for processing. I’m not too sure how to approach this with Seetu…?
2) Secondly, how would you determine the start and last bar for each intra-day segment?

Typically would look something like the following:
(this is not my actual formula but rather a sample formula of sum of period high minus the period low)

SetOption("ApplyFromTime", "2016-11-01");
SetOption("Symbols","MSFT"); 
SetOption("Periodicity", DAILY);
function cust_Avg()
{
    for( bar = startbar; bar < BarCount; bar++ ) 
    { 
        SetOption("Periodicity", MINUTE1);   // Change to intraday mode

         // Calculation for intraday calculation
        custom_avg = 0;
        for (i = firstbar_of_day; i > lastbar_of_day; i--)   
        {  
        	custom_avg += High[i] + Low[i];
        }
        
        // Change back to daily & set value for day
        SetOption("Periodicity", DAILY);  
        result_DataSeries[bar] = custom_avg; 

	} 
    return result_DataSeries;
}
  1. Is there a way to just store a indicator outside of a strategy so it can be used within multiple trading strategies?

First of all, thanks for @BobSvan2 for his very detailed explanation. He is really doing his BEST to improve Seetu and develop a cloud based algorithmic trading infrastructure.

Here are the Answers for your Questions:


Allow me to describe the overall Seetu status at first.

  • We started it as a backtesting machine using just end-of-day (OHLC) US stocks data.
  • You write your code and click on “Run Backtest”.
  • Seetu must read data from some repository and run your code.
  • End-of-day data are “manageable”. We can download them after market close and store them in the database.
  • Then, we can just read the data and use them all day long.
  • It is fast and works well - unless someone wants really many symbols.

Well, time advanced and more and more traders want to trade intraday. One minute data are in demand.

What does it mean for Seetu when you click on “Run Backtest” (or Scan or Explore)?

  • It means it must incrementally acquire new one minute data from markets, store them in the database, read one minute data for the time range defined in strategy and run the strategy.
  • We developed that and it works. You can use intraday bars from one minute to one hour.

What we need now (and what does not work yet) is “time frame switching”.

See “Time Frame functions” (the last group of functions on the bottom) here:
https://www.amibroker.com/guide/a_catfunref.html

We need those functions now, but they are not yet implemented. (Well, I even did not expect we will need them ever, so they are not even included in our help…)

Now, back to your problem. Suppose we have “Time Frame functions” for a moment.


1. I would typically use the strategy on a "daily" interval and within the function to change to intra-day for processing. I'm not too sure how to approach this with Seetu..?

This is right the opposite. :slight_smile: You need to start with minutes and switch to daily. How it works in Seetu:

There is a SetOption(“Periodicity”, …) command there. It is a part of the global setup which tells Seetu what data to read and what to do on the beginning.

  • If the periodicity is daily (weekly,…) it just reads end-of-day OHLC data from the database.
  • If the periodicity is intraday, Seetu must update one minute repository at first and read data from that repository.

What it means: There is no way how to go from daily OHLC data to minute OHLC data. One needs to start with one minute data which are convertible to the daily data.

That conversion must be done using “Time Frame functions”. Here is a description how it will be implemented (more or less) in Seetu http://www.amibroker.com/guide/h_timeframe.html

Summary:

  • SetOption(“Periodicity”, …) is a global setup and must be used just once.
  • You need to start with minute data which are convertible to daily data using some of time frame commands (not yet implemented).

2. How would you determine the start and last bar for each intra-day segment?

Maybe this helps you: https://www.collective2.com/seetudoc/id_intraday_code_example_01.html


3. Is there a way to just store a indicator outside of a strategy so it can be used within multiple trading strategies?

No.


I hope this helps.

Lorant

Hello!

Thanks Lorant!

I have found a neat trick which - maybe - helps.

I am trying to avoid cycles as much as possible in my coding.
Cycles are slow and danger, specifically, if we do not have a debugger…

So here is a code wihout cycles. As a bonus the code is much much shorter.
Basically - 3 lines of the code! Not bad! :wink:


SetOption("ApplyFromTime", "2016-11-01 09:30:00");
SetOption("Symbols","MSFT"); 

// Use 1-minute time bars
SetOption("Periodicity",MINUTE1);          

// Prepare an array having TRUE in the first bar of the day 
firstBarOfDay = TimeNum() == 093000;

// Calculate cumulative (Low + High) since first bar of the day
cum_Low_High = CumuAdd( low + high ) - ValueWhen( firstBarOfDay, CumuAdd( low + high ) );

// We have 390 minute bars per day. 
// Calculate an average of the day on the last minute bar of the day.
// Store a result to all bars of the result_DataSeries. (We are still on 1 minute bars!)
result_DataSeries = ValueWhen(TimeNum() == 160000, cum_Low_High) / 390 ;

// Inspect data in Exploration
Filter = 1;
AddColumn(Low,"Low");
AddColumn(High,"High");
AddColumn(cum_Low_High ,"cum_Low_High ");
AddColumn(result_DataSeries,"result_DataSeries");
// Enjoy!

This is not a complete solution for your problem, because we still remain on 1 minute bars without time frame switch functions, but perhaps it can show a way.

Run Exploration and you will get following results.

The end of the first day:


The end of the second day:


You can see that a daily average is calculated at the last daily bar (at 16:00) and the result is stored in each bar of the current day in the result_DataSeries. It can be compared with other current day 1-minutes values then.
(I did not check it numerically. I hope it is correct.)

The trick is borrowed from Amibroker’s function “SumSince”

Enjoy!