Gamestudio Links
Zorro Links
Newest Posts
Links dont work
by HamzaAhmed. 05/19/22 08:07
Unable to make new structures
by vinitrinh. 05/19/22 06:04
C++ scripts
by AndrewAMD. 05/18/22 16:43
Help with sorting data array
by degenerate_762. 05/18/22 12:24
How to use dataFromCSV
by AndrewAMD. 05/16/22 16:43
MT4, handling requote issues
by Grant. 05/15/22 00:04
Lapsa's very own thread
by Lapsa. 05/14/22 22:59
AUM Magazine
Latest Screens
DEAD TASTE
Tactics of World War I
Hecknex World
Scheherazade's Journey
Who's Online Now
8 registered members (HamzaAhmed, Grant, degenerate_762, vinitrinh, Quad, 3run, alibaba, Petra), 176 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Abdou, quandr, SGB1962, QuadraQuant, IcairDap
18781 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Multiple timeframes: prevent loading unnecessary data #485098
01/22/22 14:47
01/22/22 14:47
Joined: Jan 2022
Posts: 19
N
NorbertSz Offline OP
Newbie
NorbertSz  Offline OP
Newbie
N

Joined: Jan 2022
Posts: 19
Hello!

I want to use my script for analyzing multiple timeframes, 5 minutes to daily, all with 200 bars LookBack.
As I understand that the normal way to do that is something like this:

Code
BarPeriod = 5;
LookBack = 12*24*200;             // = 5 minutes * 12 * 24    (1 day)    *   200

TimeFrame = 1;
//...analyze the last 200 bars of M5...
TimeFrame = 3;
//...analyze the last 200 bars of M15...
TimeFrame = 12;
//...analyze the last 200 bars of H1...
TimeFrame = 12*4;
//..analyze the last 200 bars of H4...
TimeFrame = 12*24;
//..analyze the last 200 bars of D1...


My problem with this method is the unneccessarly huge amount of data loaded to RAM. Because with live trading (MT4 brigde) the script loads 12*24*200 bars of 5 minutes data per Asset to be able to calculate the Daily bars. But I just only need the last 200 bars for all of the TimeFrames, so basically 12*23*200 bars are useless at 5 minutes.

For larges timeframes, it could be much better and faster loading directly the larger bars, not calculate it by the smallers. Therefore I don't need to load 12*23*200 bars per asset, only 5*200.

Is there a way to do that?

Thank you!

Last edited by NorbertSz; 01/22/22 15:02.
Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485099
01/22/22 17:12
01/22/22 17:12
Joined: Jul 2017
Posts: 749
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 749
You can set LookBack =200, if you indeed need only 200 data points of each timeframe.

If it varies - try restricting length of series as needed : vars cls1H = series (priceC(), 200);



Last edited by Zheka; 01/22/22 17:27.
Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485100
01/22/22 21:09
01/22/22 21:09
Joined: Jan 2022
Posts: 19
N
NorbertSz Offline OP
Newbie
NorbertSz  Offline OP
Newbie
N

Joined: Jan 2022
Posts: 19
When I do this in run():

Code
LookBack = 200;
StartDate = Now;
asset("EURUSD");
BarPeriod = 1;
TimeFrame = 1;
vars Price = series(priceOpen());


I see this in Zorro terminal:

Code
...
Load EURUSD prices.. 600 min, gap 1378 min
Trade: testBarperiod EURUSD 2022-01-22
Lookback 200 bars, 2022-01-21..2022-01-21.
...


When I do this:
Code
LookBack = 200;
StartDate = Now;
asset("EURUSD");
BarPeriod = 1;
TimeFrame = 1000;   //!!!!
vars Price = series(priceOpen());


I see exactly the same in Zorro terminal:

Code
...
Load EURUSD prices.. 600 min, gap 1378 min
Trade: testBarperiod EURUSD 2022-01-22
Lookback 200 bars, 2022-01-21..2022-01-21.
...


It's impossible that 600 mins are enough since these are 1000 minutes bars, and I need 200 of them for LookBack. So LookBack is calculated only by BarPeriod, regardless of TimeFrame.

That's why I should do the LookBack in this case for proper operation:

Code
BarPeriod = 1;
LookBack = 1*1000*200 // It's just 200 when I switch to TimeFrame=1000;


...what I want to avoid because of startspeed and memory savings.
According to the code above, for my calulcations I only need:

- 200 bars of 1-minute
- 200 bars of 1000-minute

but this way I get 200,000 pieces of 1-minute, and calculate dynamically the 200 bars of 1000-minutes.

Last edited by NorbertSz; 01/22/22 21:16.
Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485101
01/22/22 22:06
01/22/22 22:06
Joined: Jul 2017
Posts: 749
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 749
1) to create 200 of 1000min candles you need/strongly advised to set(PRELOAD) such history from a *.t6 file.
2) then , try my second suggestion (and read the manual on series() )

Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485104
01/23/22 08:41
01/23/22 08:41
Joined: Apr 2008
Posts: 524
Austria
Petra Online
Support
Petra  Online
Support

Joined: Apr 2008
Posts: 524
Austria
Limit the series to 200, because that saves memory. But you will always need 12*24*200 lookback bars for that strategy. You cannot change the bar period during the lookback. Only the time frame.

Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485105
01/23/22 10:19
01/23/22 10:19
Joined: Jan 2022
Posts: 19
N
NorbertSz Offline OP
Newbie
NorbertSz  Offline OP
Newbie
N

Joined: Jan 2022
Posts: 19
Okay, I see, thank you for the answers!
But there is two problems with this method.

As testing I choosed M1 to H4 timeframes, and calculations for 400 bars:
Code
BarPeriod = 1;
LookBack = 1 * 60 * 4 * 400;

Problem 01

I attached a plotted result. As you can see there are a lot of useless data here, because my broker do not even store this amount of M1 candles. But I need them for calculating the old H4 candles. These are easily avaliable of couse if I go by BarPeriod = 60*4, TimeFrame = 1. But the above way I can't get the old H4 bars, because these are calculated by Zorro with the M1 candles - wich are not exists.

(I also want to avoid that I mix the previously downloaded historical M1 data and my broker's data.)

Problem 02

First loading of months of M1 data is incredibly slow and unneccessary if I calculating with 60 assets.

Possible solution

A solution can be that I run multiple Zorro instances - each one with different BarPeriod, and not changing TimeFrame at all. These scrips could be fast and simple, but for this I need to make a messaging bridge between them - for example some TXT files or interprocess communication.

Have you got a better idea?
Maybe I miss something? Maybe there is a way to download H4 candle data even if my BarPeriod is 1?

Attached Files m1.png
Last edited by NorbertSz; 01/23/22 10:57.
Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485106
01/23/22 11:59
01/23/22 11:59
Joined: Apr 2008
Posts: 524
Austria
Petra Online
Support
Petra  Online
Support

Joined: Apr 2008
Posts: 524
Austria
Use M1 data and PRELOAD. As Zheka said.

https://manual.zorro-project.com/mode.htm


Re: Multiple timeframes: prevent loading unnecessary data [Re: NorbertSz] #485118
01/24/22 15:52
01/24/22 15:52
Joined: Jan 2022
Posts: 19
N
NorbertSz Offline OP
Newbie
NorbertSz  Offline OP
Newbie
N

Joined: Jan 2022
Posts: 19
Thank you!


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1