1 registered members (AndrewAMD),
1,089
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Rotate script
[Re: kalmar]
#488019
12/28/23 14:47
12/28/23 14:47
|
Joined: Sep 2017
Posts: 82
TipmyPip
Junior Member
|
Junior Member
Joined: Sep 2017
Posts: 82
|
Has anyone tried this code and found a way to improve it? Zorro S version has functions that can incorporate better remote algorithmic control #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,729 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,729
Chicago
|
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: 82
TipmyPip
Junior Member
|
Junior Member
Joined: Sep 2017
Posts: 82
|
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: 82
TipmyPip
Junior Member
|
Junior Member
Joined: Sep 2017
Posts: 82
|
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? 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.
|
|
|
|