Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,167 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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: 70
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 70
Budapest
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: 70
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 70
Budapest
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,806
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,806
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: 70
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 70
Budapest
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