Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
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
4 registered members (dBc, clonman, TipmyPip, 1 invisible), 18,946 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
Rotate script #487992
12/17/23 10:09
12/17/23 10:09
Joined: Oct 2017
Posts: 56
Munich
K
kalmar Offline OP
Junior Member
kalmar  Offline OP
Junior Member
K

Joined: Oct 2017
Posts: 56
Munich
Hi all,

There is a rotate.c script in Strategy folder. Is there any description what it could be used for? I'm reading it, but would be useful if there is more explanation.

Thx

Re: Rotate script [Re: kalmar] #487993
12/17/23 14:53
12/17/23 14:53
Joined: Sep 2017
Posts: 164
TipmyPip Online
Member
TipmyPip  Online
Member

Joined: Sep 2017
Posts: 164
Thank you for your interest, The rotate.C strategy is a portfolio management. The strategy functions as a mathematical model for portfolio optimization, drawing from a matrix-like dataset to align current asset holdings with predefined targets. It employs vector comparisons to calculate trade adjustments, ensuring alignment through sequential logic. Human oversight is integrated through a confirmation step before trade execution. The strategy then iteratively adjusts each asset's position, mirroring the process of solving a system of equations. Post-execution, a detailed log akin to an annotated mathematical proof records the strategy's actions, encapsulating a blend of algorithmic precision and strategic decision-making.

Re: Rotate script [Re: kalmar] #487995
12/17/23 20:41
12/17/23 20:41
Joined: Oct 2017
Posts: 56
Munich
K
kalmar Offline OP
Junior Member
kalmar  Offline OP
Junior Member
K

Joined: Oct 2017
Posts: 56
Munich
Sounds like Zorro GPT answer laugh

Re: Rotate script [Re: kalmar] #487999
12/20/23 12:38
12/20/23 12:38
Joined: Sep 2017
Posts: 164
TipmyPip Online
Member
TipmyPip  Online
Member

Joined: Sep 2017
Posts: 164
Well, your income sure depends on how flexible you can be, and adapt Technology.

Re: Rotate script [Re: kalmar] #488019
12/28/23 14:47
12/28/23 14:47
Joined: Sep 2017
Posts: 164
TipmyPip Online
Member
TipmyPip  Online
Member

Joined: Sep 2017
Posts: 164
Has anyone tried this code and found a way to improve it? Zorro S version has functions that can incorporate better remote algorithmic control

Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TO_CSVHDR "Asset,Weight%%,Margin,Lots,MarginCost"
#define TO_CSV "\n%s,%.0f,%.0f,%.0f,%.0f"

char* Filename = "Data\\MyStrategy.csv"; // rotation list
char* Fileformat = "ss,f,f,f";
char* Outfile = "Log\\Rotation.log";
char* TickerSymbol = "*";
// char* TickerSymbol = "*-STK-SMART-USD!STOOQ:*";
#define NEWWEIGHT 1 // weight percent field number
#define NEWLOTS 3   // lots field number
#define LEVERAGE 1

double AssetInt[12]; // Assuming AssetInt is an array of doubles

void folioTrade(int LS) {
    // Assuming used_assets is an array of asset names
    for (int i = 0; i < sizeof(used_assets) / sizeof(used_assets[0]); i++) {
        asset(used_assets[i]);
        if ((OpenLots > NewLots && LS < 0) || (OpenLots < NewLots && LS > 0)) {
            enterLong(NewLots - OpenLots);
        }
    }
}

int main() {
    int i;
    int Records;
    double Invest = 0;

    LookBack = 0;
    StartDate = NOW;
    set(LOGFILE);
    SaveMode = 0;

    Filename = file_select("Data", "Rotation Lists\0*.csv\0\0");
    Records = dataParse(1, Fileformat, Filename);
    if (!Records) {
        return quit("CSV file not found");
    }

    printf("\nSubscribing %i assets..", Records);
    brokerCommand(SET_PRICETYPE, 8); // get prices fast
    char Box[50000] = "\n---------------------------------";
    int Changed = 0;

    for (i = 0; i < Records; i++) {
        printf(".");
        char* Ticker = dataStr(1, i, 0);
        assetAdd(Ticker, TickerSymbol);
        if (!asset(Ticker)) continue;
        NewLots = dataVar(1, i, NEWLOTS);
        OpenLots = brokerCommand(GET_POSITION, Ticker);
        double Margin = NewLots * priceC(0) / LEVERAGE;
        Invest += Margin;

        if (OpenLots != NewLots) {
            Changed = 1;
            strcat(Box, strf("\n%s \t%d -> %d@%s ($%.2f)",
                Asset, OpenLots, NewLots, sftoa(priceC(0), 2), Margin));
        } else if (OpenLots) {
            strcat(Box, strf("\n%s \t%d@%s ($%.2f)",
                Asset, OpenLots, sftoa(priceC(0), 2), Margin));
        }
    }

    strcat(Box, "\n---------------------------------");
    strcat(Box, strf("\nTotal margin $%s at %s",
        sftoa(Invest, 4), strdate(YMDHMS, NOW)));

    if (!Changed) {
        printf("\nPortfolio unchanged");
    } else {
        strcat(Box, "\nModify Portfolio?");
        if (msg(Box)) {
            strcat(Box, " Y");
            setf(TradeMode, TR_GTC);
            folioTrade(-1); // Short
            folioTrade(1);  // Long
            file_append(Outfile, Box, 0);
            exec("Editor", Outfile, 0);
        } else {
            printf("\nNo positions entered");
        }
    }

    return 0;
}

Re: Rotate script [Re: kalmar] #488020
12/28/23 14:58
12/28/23 14:58
Joined: Feb 2017
Posts: 1,806
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,806
Chicago
Code
for (int i = 0; i < sizeof(used_assets) / sizeof(used_assets[0]); i++) {
This GPT-generated code clearly does not know how the Zorro macros work. It seems to think the macro is a struct.

You should discipline your GPT.

Re: Rotate script [Re: AndrewAMD] #488025
12/29/23 18:19
12/29/23 18:19
Joined: Sep 2017
Posts: 164
TipmyPip Online
Member
TipmyPip  Online
Member

Joined: Sep 2017
Posts: 164
Thank you for your suggestion Andrew, we always want to improve on our knowledge, and abilities to cooperate.

The code is meant for users to explore, learn, and try out new ideas... If I will share code without errors, no one will learn anything new, and just forget about it in 4 hours. (In addition, when you are inspired by different ideas, you improve your level and go beyond your limits, because loops aren't structures, rather than building blocks that require you to dig deeper, and find ideas you have not thought about.)

It would be even more informative for you to work with it together and improve your own ideas... We are all here to learn together.

In addition, users will enjoy your input even more, when you too share some code and explain yourself, we are all here to enjoy your contribution, please...

And remember you are always blessed, with happiness and money as well as new ideas.

Last edited by TipmyPip; 12/29/23 18:43.
Re: Rotate script [Re: AndrewAMD] #488026
12/30/23 16:48
12/30/23 16:48
Joined: Sep 2017
Posts: 164
TipmyPip Online
Member
TipmyPip  Online
Member

Joined: Sep 2017
Posts: 164
Dear Andrew, I believe that you are a very clever person and a great programmer...

Would you kindly please share with us your understanding, and knowledge of what is the reason you think the following statement has anything to do with struct and why are you referring to macros?

Code
for (int i = 0; i < sizeof(used_assets) / sizeof(used_assets[0]); i++) {


We truly want to learn from you... Thank you.

Last edited by TipmyPip; 12/30/23 16:48.

Moderated by  Petra 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1