Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/20/24 06:09
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (flink, Edgar_Herrera), 695 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Series, shifting and timeframes #486573
09/06/22 18:03
09/06/22 18:03
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Dear all,

Could you help me understand what am I missing?

Code
function run(){

    BarPeriod = 1;
    LookBack = 240*100;
    StartDate = 20100101;
    EndDate = 20100201;

    set(NOSHIFT);           //shift manually
    asset("EURUSD");
    
    vars priceM1 = series();
    vars priceM5 = series();

    if (is(INITRUN)){
        priceM1 = series(0, 100);
        priceM5 = series(0, 100);
    }
    
    TimeFrame = 1;
    shift(priceM1, priceClose(), 100);
    TimeFrame = 5;
    if (frame(0)) shift(priceM5, priceClose(), 100);

    if (!is(LOOKBACK)){
        int i, j;
        for (i=0; i<10; i++){
            printf("\n--- M5: %.5f", priceM5[i]);
            for (j=0; j<5; j++){
                printf("\n M1: %.5f", priceM1[i*5+j]);
            }
        }
        quit(0);
    }
}


I attached the results.
How is it possible that the M1 middle candle is determining the closing price of the M5 candle? Shouldn't it be the last one?
The expected result are the following:

Code
--- M5 priceE
M1 priceA
M1 priceB
M1 priceC
M1 priceD
M1 priceE
...


Thank you!

Attached Files middle_candle.png
Re: Series, shifting and timeframes [Re: NorbertSz] #486575
09/06/22 18:19
09/06/22 18:19
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
I did the custom shifting because the automatic shifting (as suggested in the example codes in TimeFrame help) did exactly the same. And because I did not understand why it does, I tried to "implement", but same results. So the following code, the automatic shifting acts just exactly the previously posted:

Code
function run(){

    BarPeriod = 1;
    LookBack = 240*100;
    StartDate = 20100101;
    EndDate = 20100201;

    asset("EURUSD");

    TimeFrame = 1;
    vars priceM1 = series(priceClose(), 100);
    TimeFrame = 5;
    vars priceM5 = series(priceClose(), 100);

    if (!is(LOOKBACK)){
        int i, j;
        for (i=0; i<10; i++){
            printf("\n--- M5: %.5f", priceM5[i]);
            for (j=0; j<5; j++){
                printf("\n M1: %.5f", priceM1[i*5+j]);
            }
        }
        quit(0);
    }
}

Last edited by NorbertSz; 09/06/22 18:23.
Re: Series, shifting and timeframes [Re: NorbertSz] #486576
09/06/22 20:00
09/06/22 20:00
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Your if statement with the loops did not check for frame(0).

Re: Series, shifting and timeframes [Re: AndrewAMD] #486580
09/07/22 05:46
09/07/22 05:46
Joined: Jan 2022
Posts: 58
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 58
Ahh I guess I understand now.
If I just print the prices as the come:

Code
function run(){
    BarPeriod = 1;
    LookBack = 240*100;
    StartDate = 20100101;
    EndDate = 20100201;

    asset("EURUSD");

    TimeFrame = 1;
    printf("\nM1: %.5f", priceClose());
    TimeFrame = 5;
    if (frame(0)) printf("\n --- M5: %.5f", priceClose());
}


The results are the expected: the last M1 candle closePrice() is the same that M5 candle closePrice(), as seen in the first attachment of this post. Now I understand that if the LookBack finishes not exactly in TimeFrame 5 frame(0) then the whole M1 series will be shifted, because it got new elements but the M5 series did not. Attachment.

One possible solution for printing is shifting the data inside the series:

Code
function run(){

    BarPeriod = 1;
    LookBack = 240*100;
    StartDate = 20100101;
    EndDate = 20100201;

    asset("EURUSD");

    TimeFrame = 1;
    vars priceM1 = series(priceClose(), 100);
    //printf("\nM1: %.5f", priceClose());
    TimeFrame = 5;
    vars priceM5 = series(priceClose(), 100);
    //if (frame(0)) printf("\n --- M5: %.5f", priceClose());

    if (!is(LOOKBACK)){

        //shift some data
        int i, j, shift;
        TimeFrame = 5;
        for (i=0; i<4; i++){
            if (frame(i)) shift = i + 1;
        }

        //print
        for (i=0; i<10; i++){
            printf("\n--- M5: %.5f", priceM5[i]);
            for (j=0; j<5; j++){
                printf("\n M1: %.5f", priceM1[shift + i*5 + j]);
            }
        }
        quit(0);
    }
}


Thank you!

Attached Files end_candle.pngshifting.png
Last edited by NorbertSz; 09/07/22 05:47.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1