Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, kzhao), 901 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
A stochf problem #430231
09/25/13 22:45
09/25/13 22:45
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Hi all,
I'm trying to replicate a multi-time frame stoch ea.
But every 4 hours the stochs for H4, 1 and M15 are the same. I understand how they could be the samae, but every 4 hours seems wrong.
I've looked and looked and don't see a problem, but there has to be one.
Thanks for any help.
P

#define D1 (1440/BarPeriod)
#define H4 (240/BarPeriod)
#define H1 (60/BarPeriod)
#define M15 (15/BarPeriod)

function run()
{
BarPeriod = 15;
TimeFrame=H4;
vars PriceH4=series(price());
StochF(5,3,MAType_SMA);
vars StoH4=series(rFastK);
TimeFrame=H1;
vars PriceH1=series(price());
StochF(5,3,MAType_SMA);
vars StoH1=series(rFastK);
TimeFrame=M15;
vars PriceM15=series(price());
StochF(5,3,MAType_SMA);
vars StoM15=series(rFastK);
Lots=1;
StartDate=20080102;
EndDate=20080631;
Margin=0;
Spread=2*PIP;
set(LOGFILE|PLOTNOW|PLOTPRICE);

Asset=("AUDUSD");

printf("# \n");
printf("# Price Stoc \n");
printf("# H4 %5.5f %5.5f \n", PriceH4[0],StoH4[0]);
printf("# H1 %5.5f %5.5f \n", PriceH1[0],StoH1[0]);
printf("# M15 %5.5f %5.5f \n", PriceM15[0],StoM15[0]);

//Oversold
if((NumOpenTotal<2)&&(StoH4[0]<20)&&(StoH1[0]<20)&&(StoM15[0]<20)) {
exitShort();
enterLong();
}

//Overbought
if((NumOpenTotal<2)&&(StoH4[0]>80)&&(StoH1[0]>80)&&(StoM15[0]>80)) {
exitLong();
enterShort();
}

plot("StoH4",StoH4[0],NEW,RED);
plot("StoH1",StoH1[0],NEW,BLUE);
plot("StoM15",StoM15[0],NEW,GREEN);

}

Re: A stochf problem [Re: Pork] #430238
09/26/13 06:21
09/26/13 06:21
Joined: May 2013
Posts: 627
Bonn
Sundance Offline
User
Sundance  Offline
User

Joined: May 2013
Posts: 627
Bonn
Hi. Just a quick look...

You defining M15,H1,H4,D1 with the help of BarPeriod. The manual says:

BarPeriod
The duration of one bar in minutes (default = 60). This is the smallest possible time frame in the script. If not explicitely set up, it is determined by the [Period] slider. The run function is called at the end of every bar.


So before the first run you set D1 = (1440/60) = 24 ??
In the run function you the nset BarPeriod to 15 ...

I think this is the first prob you have.

Re: A stochf problem [Re: Sundance] #430244
09/26/13 07:35
09/26/13 07:35
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The Period slider jumps to 15 when the BerPeriod is set to 15 in the script. So the time frames are ok.

You're defining H4, H1, etc. price series, but don't do anything with them. You cannot, because the stoch function from the TA library has no data series parameter. It just uses the current asset price series. Thus it can not support different time frames.

If you want the functionality of the stoch for different time frames, you can use the Normalize function or better, the Fisher transform. Both work with any data series. We can of course also implement a traditional stoch for different time frames in a future version. We had not done this so far because we did no see any real use for the stoch function.

Re: A stochf problem [Re: jcl] #430261
09/26/13 10:12
09/26/13 10:12
Joined: May 2013
Posts: 627
Bonn
Sundance Offline
User
Sundance  Offline
User

Joined: May 2013
Posts: 627
Bonn
I don't understand the BarPeriod thingy.
When I start the script. First there will be executed the #define lines and after that the run function will be executed. So when the define command executes BarPeriod is 60 not 15 or does Zorro internally handle it the other way around!?

Re: A stochf problem [Re: Sundance] #430265
09/26/13 10:26
09/26/13 10:26

A
acidburn
Unregistered
acidburn
Unregistered
A



#define is a C pre-processor thingy. Think of it as a templating system. Wherever in the code you see D1, you replace it (either in your mind, or for real) with (1440/BarPeriod). It's only there in the code that it is actually executed, #defines are declarations only.

Re: A stochf problem [Re: ] #430267
09/26/13 10:32
09/26/13 10:32
Joined: May 2013
Posts: 627
Bonn
Sundance Offline
User
Sundance  Offline
User

Joined: May 2013
Posts: 627
Bonn
I knew this but you are right. Sometimes my head hasn't woken up and only my body is at work :-)

Re: A stochf problem [Re: Sundance] #430285
09/26/13 12:48
09/26/13 12:48
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Thanks all. Once again very helpful.
Nice to know how the stoch actually works.
I'm starting to see a pattern that maybe I should adjust my thinking to eliminate the old mt4 indicators and start using the new, to me, statistical indicators.
Looks to me like more reading and less coding is needed.
Quickly references the reading list grin
Thanks All
P

Re: A stochf problem [Re: Pork] #430289
09/26/13 13:21
09/26/13 13:21
Joined: May 2013
Posts: 627
Bonn
Sundance Offline
User
Sundance  Offline
User

Joined: May 2013
Posts: 627
Bonn
In Zorro you can have one line doing things where MT4 needs a whole function. That is right and I 'am too must change my mind when programming in Zorro.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1