Gamestudio Links
Zorro Links
Newest Posts
IG plugin initial release
by sodiumchloride. 09/22/20 20:53
Using STL in Zorro strategies
by AndrewAMD. 09/22/20 17:01
Rubbish data from Yahoo
by DanielX. 09/22/20 14:37
assert
by Grat. 09/22/20 12:14
MT4 - use more Zorro script
by Grat. 09/22/20 06:49
Single advise model for portfolio
by jmlocatelli. 09/21/20 19:41
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
4 registered members (Dooley, kvm, AndrewAMD, jmlocatelli), 445 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
NewBorn, 3dvg, secretagentman, distribution, EditeY
18515 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
avg spread every tick #481181
08/11/20 08:09
08/11/20 08:09
Joined: May 2015
Posts: 302
Czech Republic
G
Grat Online OP
Senior Member
Grat  Online OP
Senior Member
G

Joined: May 2015
Posts: 302
Czech Republic
Hi,

I need calculate AVG spread - every tick. I trying this:

Code
#include <profile.c>
vars Data10 = series(0,30);
//------------------------ 
void tick(){
    
    var s= Spread;
    Data10=series(s,30);
    var aAvg=Median(Data10,30);
    print(TO_INFO,"%f",s);

}

// --------------------------- Main-----------------------------
function run()
{
    LookBack = 0;
    print(TO_WINDOW,"%f",Spread);
}



but I get this erro:

Error 041: series/loops defined outside run!
Error 111: Crash in tick: tick() at bar 1


Do you any idea, how make this?

Thanks

Re: avg spread every tick [Re: Grat] #481182
08/11/20 09:53
08/11/20 09:53
Joined: May 2020
Posts: 20
Germany
M
Morris Offline
Newbie
Morris  Offline
Newbie
M

Joined: May 2020
Posts: 20
Germany
Well, like the error message says: You should not define a series outside of run(). The idea of a series is that it is shifted automatically with every run() -- but that is not what you want here. So you want to declare your series with a negative length and manually shift your series with every tick().

This works:
Code
#include <profile.c>
vars Data10;
//------------------------ 
void tick() {
    var s = Spread;
    shift(Data10, s, 30);
    var aAvg = Median(Data10, 30);
    print(TO_INFO,"Avg=%f", aAvg);
}

// --------------------------- Main-----------------------------
function run() {
    Data10 = series(0, -30);
    LookBack = 0;
    print(TO_WINDOW,"\nSpread=%f", Spread);
}

Re: avg spread every tick [Re: Grat] #481183
08/11/20 10:34
08/11/20 10:34
Joined: May 2015
Posts: 302
Czech Republic
G
Grat Online OP
Senior Member
Grat  Online OP
Senior Member
G

Joined: May 2015
Posts: 302
Czech Republic
Super, thank's


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1