Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 827 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 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 Online
Serious User
AndrewAMD  Online
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