RollShort / RollLong Issue?

Posted By: BrainSailor

RollShort / RollLong Issue? - 01/11/24 10:53

Hi,
I have a question maybe an issue with Zorro 2.56.

Oanda is sending yearly Rollover Fees. So my idea is to convert them to daily fees. In theory it should be very easy with a line like this:

RollShort = RollShort / 365.

When I have that in my strategy no rollover costs are calculated at all.

Transaction costs -0.60$ spr, 0.0033$ slp, -0.0000000$ rol

I did try the same with the Alice 1a script and I have the same behavior.
So I thought it is a kind of rounding issue. I set the Rollover Cost in the Assetlist to some insane value and still no calculation of the rollover cost.

What bothers me really is the following line:
RollShort = RollShort * 1.;
This is working as expected.
I am lost. Any help is appreciated.

This is the code where I do my testing with. I am using EUR/USD for the tests and the latest Oanda instrument values (downloaded via MT5 bridge)

// Trend Trading ///////////////////
#include <profile.c>

function run()
{
Verbose = 3;
set(LOGFILE); // log all trades

StartDate = 2013;
EndDate = 2023; // fixed simulation period

BarPeriod = 15;

RollShort = RollShort / 365.;
RollLong = RollLong / 365.;

vars Prices = series(price());
vars Trends = series(Laguerre(Prices,0.05));

Stop = 10*ATR(100);
MaxLong = MaxShort = -1;

if(valley(Trends))
enterLong();
else if(peak(Trends))
enterShort();
}
Posted By: TipmyPip

Re: RollShort / RollLong Issue? - 01/12/24 06:53

Let's debug your code,

We can first print the RollOver values to see what are the values if it is daily or yearly?

Code
// Trend Trading ///////////////////
#include <profile.c>

function run()
{
    Verbose = 3;
    set(LOGFILE); // log all trades

    StartDate = 2013;
    EndDate = 2023; // fixed simulation period

    BarPeriod = 15;

    // Debug: Print original rollover values
    printf("\nOriginal RollShort: %f, RollLong: %f", RollShort, RollLong);

    // Adjusting rollover values
    RollShort = RollShort / 365.;
    RollLong = RollLong / 365.;

    // Debug: Print adjusted rollover values
    printf("\nAdjusted RollShort: %f, RollLong: %f", RollShort, RollLong);

    vars Prices = series(price());
    vars Trends = series(Laguerre(Prices,0.05));

    Stop = 10*ATR(100);
    MaxLong = MaxShort = -1;

    if(valley(Trends))
        enterLong();
    else if(peak(Trends))
        enterShort();
}
Posted By: AndrewAMD

Re: RollShort / RollLong Issue? - 01/12/24 11:25

run() is called repeatedly. RollLong and RollShort are global values associated with your asset. The more you divide it by 365, the more it approaches zero. So your script basically set them to a negligible value.

Consider using a fixed value. You can configure it in your asset list and leave it alone in your script.
Posted By: BrainSailor

Re: RollShort / RollLong Issue? - 01/12/24 11:55

Thanks AndrewAMD! You are absolutely right! I just did not think about the fact that the statements are called repeatedly!

In my original strategy I have a asset loop like:

while(asset(loop(Assets)))

I thought the parameters are initialized again after each asset switch. My mistake. I did not want to modify the assetlist as this can be forgotten when you are updating the list.
A simple

if (is(FIRSTRUN))

is doing the job now.
Thanks again Andrew!
Posted By: TipmyPip

Re: RollShort / RollLong Issue? - 01/12/24 12:48

Thank you Andrew, for paying attention to details :

Code
// Trend Trading ///////////////////
#include <profile.c>

function run()
{
    Verbose = 3;
    set(LOGFILE); // log all trades

    StartDate = 2013;
    EndDate = 2023; // fixed simulation period

    BarPeriod = 15;

    if(is(INITRUN)) {
        // Debug: Print original rollover values
        printf("\n[INIT] Original RollShort: %f, RollLong: %f", RollShort, RollLong);

        // Adjusting rollover values
        RollShort = RollShort / 365.;
        RollLong = RollLong / 365.;

        // Debug: Print adjusted rollover values
        printf("\n[INIT] Adjusted RollShort: %f, RollLong: %f", RollShort, RollLong);
    }

    vars Prices = series(price());
    vars Trends = series(Laguerre(Prices,0.05));

    Stop = 10*ATR(100);
    MaxLong = MaxShort = -1;

    if(valley(Trends))
        enterLong();
    else if(peak(Trends))
        enterShort();
}
© 2024 lite-C Forums