avg spread every tick

Posted By: Grat

avg spread every tick - 08/11/20 08:09

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
Posted By: Morris

Re: avg spread every tick - 08/11/20 09:53

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);
}
Posted By: Grat

Re: avg spread every tick - 08/11/20 10:34

Super, thank's
© 2024 lite-C Forums