Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (SBGuy, dr_panther, Ayumi, Quad, AndrewAMD), 920 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 9 1 2 3 4 5 6 7 8 9
Re: Major future features [Re: hughbriss] #410223
10/30/12 17:00
10/30/12 17:00
Joined: Oct 2012
Posts: 1
M
Matt_32 Offline
Guest
Matt_32  Offline
Guest
M

Joined: Oct 2012
Posts: 1
Would it be possible to import MT4 strategies and use them with Zorro?

Re: Major future features [Re: Matt_32] #410256
10/31/12 08:20
10/31/12 08:20
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Theoretically yes. The language is the same, you just have to write a C header that translates the variables and functions. This is however a diligence challenge and no real fun.

Re: Major future features [Re: jcl] #410834
11/09/12 18:23
11/09/12 18:23
Joined: Oct 2012
Posts: 16
Aix en Provence, France
Squalou Offline
Newbie
Squalou  Offline
Newbie

Joined: Oct 2012
Posts: 16
Aix en Provence, France
Hi


I have a request about something that i'm sure many MT4/5 coders are probably struggling with (at least I am...) :

"TA" and "price" functions are not multi-timeframe.

I explain:

If i test/run my script in Daily charts, I set BarPeriod=1440.

However, all TA functions such as ATR(), EMA(), LowPass(), etc only have a "int TimePeriod" argument, but no equivalent of the MT4 "timeframe" argument.

Therefore, when i call

Code:
var atr = ATR(60);



this will return the ATR(Daily,60) value if i'm running my script with BarPeriod=1440 and TimeFrame=1.

If i switch to another BarPeriod, say 5,
then ATR(60) will return the equivalent of ATR(M5,60).

There is no way to get the ATR(Daily, 60) whatever BarPeriod/TimeFrame i would be using for my test.

What makes things even more confusing is that the "TimePeriod" argument of TA functions not only depend on BarPeriod, but ALSO on TimeFrame...

How do we (simply!) solve this ?

I would be really happy to have a separate "int timeframe" argument that clearly specifies the timeframe on which the "timeperiod" argument applies, just like MT4 has.

These 2 arguments together would then make the TA function calls completely independent on the BarPeriod and TimeFrame global variables that otherwise affect the trade functions

My "daily ATR" request woudl then always look identical like this (for instance):

Code:
var atr = ATR(PERIOD_D1,60);



regardless of the BarPeriod and TimeFrame arguments that are set to run the script.

Note that this should also likely apply to the price functions (priceOpen(), etc).

The current way it is implemented is very confusing, and makes it very difficult to code scripts that can be run on any BarPeriod values.

Thanks.

Sq

Re: Major future features [Re: Squalou] #410836
11/09/12 18:42
11/09/12 18:42
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
In lite-C, TimeFrame is a simple variable, not an extra argument to all functions. For a daily ATR(60) just write:

ATR(60 * 1440/Barperiod)

or

TimeFrame = 1440/Barperiod;
ATR(60);

No extra functions required.

Re: Major future features [Re: Squalou] #410842
11/09/12 19:02
11/09/12 19:02
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline
Junior Member
PriNova  Offline
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
I would like to see this too.
this is surely why my backtest in Zorro is different. And i know now why, after reading the TimeFrame-function:

Quote:
# The run function is always called once per bar, and stop and profit limits are tested every bar, regardless of the TimeFrame setting.


i think it would be better, if the run-function will be called every Tick.


i think what helps here is always test in M1 and if we like to have values from other TF's we have to use the TimeFrame-function like:

Code:
TimeFrame = 60;                      //fetch 60 Minute values
 var *prices = series(priceClose(0));
 var MA = SMA(prices, 21);

 TimeFrame = 15;                      //fetch 15 Minutes values
 var *prices2 = series(priceClose(0));
 var rsi = RSI(prices2, 14);



but i don't know if this works and if it works tick-wise instead Open-Bar-wise

Last edited by PriNova; 11/09/12 19:03.
Re: Major future features [Re: PriNova] #410844
11/09/12 19:21
11/09/12 19:21
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I remember that an every-tick run function was implemented in an early Zorro version - but I think this feature is no longer supported, as apparently no one found any use for it. But if you can give me an example for what purpose an every-tick run function could be used in strategy testing, we can certainly re-implement it.

The shortest bar periods I've seen in serious strategies were M5, but on those short time frames the prices are mostly noise and systematic trading is difficult. Most profitable strategies use H1, H4, or D1.

Re: Major future features [Re: jcl] #410845
11/09/12 20:04
11/09/12 20:04
Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
P
PriNova Offline
Junior Member
PriNova  Offline
Junior Member
P

Joined: Sep 2012
Posts: 74
Niedersachsen, Germany
If I understand everything correctly, multitimeframe-trading forward or backward should be made from bottom-up.
How will zorro handle this:
I run a backtest in the 1 minute timeframe and fetch the ATR-value of the 60 minute timeframe, will I get the value from the actual 1 hour candle or from the past 1 hour candle?

If yes, then function run in tick makes really no sense

Last edited by PriNova; 11/09/12 20:06.
Re: Major future features [Re: PriNova] #410848
11/09/12 20:54
11/09/12 20:54
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
You can get both:

ATR(n * 60) // ATR from the last n*60 minutes up to the current minute

or

TimeFrame = 60;
ATR(n); // ATR from the previous n 1-hour bars

Re: Major future features [Re: jcl] #410849
11/09/12 22:14
11/09/12 22:14
Joined: Oct 2012
Posts: 16
Aix en Provence, France
Squalou Offline
Newbie
Squalou  Offline
Newbie

Joined: Oct 2012
Posts: 16
Aix en Provence, France
Originally Posted By: jcl
In lite-C, TimeFrame is a simple variable, not an extra argument to all functions. For a daily ATR(60) just write:

ATR(60 * 1440/Barperiod)

or

TimeFrame = 1440/Barperiod;
ATR(60);

No extra functions required.


ok, when playing with BarPeriod and TimeFrame yesterday, i came up with something similar to your second solution.
Although it is not ideal as you expose it, because it means you are messing up with TimeFrame, and if you want to use other TimeFrame-sensitive functions (TA or price functions), then you have to make sure you set TimeFrame every time.
Or restore it to its previous value once you've used it...
Which is the solution i came up with yesterday.

Here is actually how i "solved" this :
- i created 2 "general-purpose" functions to set and restore TimeFrame;
- for EACH TA function( ATR(),EMA(), etc), i created a function made of an extra "layer" on top of the Zorro function, which saves TimeFrame, calls the Zorro TA function, restores TimeFrame, and returns the result...

Here is an example with ATR():

Code:
//------------------------------------
int __saved_tf;
void set_timeframe(int tf_minutes)
{ // set Zorro's TimeFrame based on the required tf_minutes and the script's BarPeriod
	// save globals that we need to change
	__saved_tf = TimeFrame;
	// set Zorro's TimeFrame based on the required tf_minutes and the script's BarPeriod
	TimeFrame = tf_minutes/BarPeriod;
}
		
//------------------------------------
void restore_timeframe()
{
	TimeFrame = __saved_tf;
}
	
//------------------------------------
var atr(int tf_minutes, int length)
{
	// tf_minutes : timeframe in minutes,
	// to feel like in MT4!
	// length: <=> 'period' in MT4 
	// (num of 'bars' in the given timeframe)

	set_timeframe(tf_minutes); // set Zorro's TimeFrame based on the required tf_minutes and the script's BarPeriod
	
	// now that TimeFrame is set properly according to Zorro specs, we can calculate the ATR()

	var atr = ATR(length);
	
	// restore TimeFrame as it was before entering this function
	restore_timeframe();

	return(atr);
}



function run()
{
  set(PLOTNOW);
  BarPeriod = 60;
  TimeFrame = 1; // timeframe for builtin functions (series(),etc)
  StartDate = 2011;

  // we need to change LookBack to accomodate different BarPeriod and TimeFrame settings...
  LookBack = 100*1440/BarPeriod/TimeFrame;

  plot("adr(1440,60)", atr(1440,60)/PIP, NEW, BLUE);
  plot("ATR(60*1440/BarPeriod", ATR(60*1440/BarPeriod)/PIP, 0, RED);

  plot("BarPeriod",BarPeriod, NEW, BLUE);
  plot("TimeFrame",TimeFrame, 0, RED);

	//plot_balance_equity();

	PlotWidth   = 1000;
	PlotHeight1 = 100;
}

//end




It is heavy, but it works fine, and avoids mistakes with TimeFrame.
And it also gives a clear "atr(timeframe,length)" API.

No messing around with TimeFrame in the "active code", therefore no risk of miscoding it.

Just for THAT single reason : NO risk of hard-to-find errors in the code, i think this approach is much more robust.
You should really consider providing this kind of improvement in the APIs, this will make coders life easier, and less questions/answers in the forum in the future as well;
And believe me, i know exactly how it feels to be bombarded all day long with the same questions again and again because people don't know how to (correctly) use your APIs... wink


Back to my script example with ATR above :
i coded a simple run() function to compare the 2 methods :
- the first one you provided : ATR(60 * 1440/Barperiod)
- the second one, coded with my "enhanced" atr() function, which is equivalent to your second suggestion;

The script is very simple, it will plot both results on the same sub-window, just to make sure they return the same value;
Which it does!

It also plots a second subwindow showing the values of BarPeriod and TimeFrame values as they were set at the beginning of the script;

Now the catch is this :
although both atr methods give the same result (that was expected), if you change the BarPeriod value in the script, then the ATR value will give you a totally different range of values, although the curves have the same shape...

Try with BarPeriod=60, then BarPeriod=5, then 1440, you'll see what i mean.
They should all give the same value ranges and the same curve shapes.
The only one that is correct is when BarPeriod=1440 (120-160p)
In M1/EURUSD, it gives you a DAILY range of ... 2.5-4pips crazy


There's a bug somewhere.
Either in the way i am using ATR(), although both suggested solutions give the exact same (wrong) results,
or in the ATR() function itself!


Another somewhat confusing element is LookBack.
It must be set to a large enough value to accomodate the "longest" "timeperiod" parameter used in any of the TA or price functions.
When playing with daily timeframes, for instance ATR(60 days), if you want to run the script on M1 candles, you will need LookBack > 100*1440 (apparently, any lower value gives an error).
If we set BarPeriod to 1440, then only LookBack can go down to 100 only.

The minimum value also seems to be affected by the value of TimeFrame.

So i came up with this work-around :

LookBack = 100*1440/BarPeriod/TimeFrame+1;

which will accomodate up until ATR(60 days) at least.

But what if i want to calculate ATR(150 days) ?
Then i have to go back and change LookBack again.

This is quite important for backtesting because changing LookBack will greatly affect how far in the past we can backtest.
No way I would set it once for all to 100*1440;
We couldn't run any test with BarPeriod=1440...



Sq

Re: Major future features [Re: Squalou] #410856
11/10/12 06:55
11/10/12 06:55
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Thanks for the bug report! I can confirm the problem - ATR indeed returns a wrong value when TimeFrame is > 1. It's a bug. I'll forward this to the developers. This will be fixed.

- Your method to emulate the MT4 atr is correct, but a little heavy. You need only 2 lines for replacing all time frames with function arguments:

Code:
var atr(int tf_minutes, int length)
{
   TimeFrame = tf_minutes/BarPeriod;
   var r = ATR(length);
   TimeFrame = 1;
   return r;
}



- Your method to set the Lookback period does not look right. Maybe there's some misconception. LookBack is the number of bars before the test period. For 150 days, it's 150*1440/BarPeriod.

Page 2 of 9 1 2 3 4 5 6 7 8 9

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1