Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, SBGuy, TipmyPip, ozgur), 859 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Xor Memory Problem. #487932
11/23/23 18:41
11/23/23 18:41
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Dear Programmers, I have the following code of which I am trying to run in Zorro lite-C but it crashes all the time.

Does anyone know how to implement dynamic memory allocation within lite-C?



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

#define INT_BITS 32

typedef struct TrieNode {
    struct TrieNode* bit[2];
} TrieNode;

TrieNode* newTrieNode() {
	TrieNode* newNode = (TrieNode*)malloc(sizeof(TrieNode));
    if (newNode != NULL) {
        newNode->bit[0] = newNode->bit[1] = NULL;
    }
    return newNode;
}

void insert(TrieNode* root, int number) {
    TrieNode* current = root;
    for (int i = INT_BITS - 1; i >= 0; i--) {
        int bit = (number >> i) & 1;
        if (current->bit[bit] == NULL) {
            current->bit[bit] = newTrieNode();
		}
		current = current->bit[bit];
	}
}

int findMaxXOR(TrieNode* root, int number) {
    TrieNode* current = root;
    int maxXOR = 0;
    for (int i = INT_BITS - 1; i >= 0; i--) {
        int bit = (number >> i) & 1;
        if (current->bit[1 - bit] != NULL) {
            maxXOR |= (1 << i);
            current = current->bit[1 - bit];
        } else {
            current = current->bit[bit];
        }
    }
    return maxXOR;
}

void freeTrie(TrieNode* root) {
    if (root != NULL) {
        freeTrie(root->bit[0]);
        freeTrie(root->bit[1]);
        free(root);
    }
}

int getMaxXOR(int* arr, int size) {
    TrieNode* root = newTrieNode();
    int maxXOR = 0;
    for (int i = 0; i < size; i++) {
		insert(root, arr[i]);
		int currentXOR = findMaxXOR(root, arr[i]);
        if (currentXOR > maxXOR) {
            maxXOR = currentXOR;
        }
    }
    int result = maxXOR;
    freeTrie(root);
    return result;
}

int main() {
    int arr[] = {3, 10, 5, 25, 2, 8};
    int size = sizeof(arr) / sizeof(arr[0]);
    int result = getMaxXOR(arr, size);
    printf("Maximum XOR: %d\n", result);
	return 0;
}


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487933
11/25/23 13:53
11/25/23 13:53
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago

Re: Xor Memory Problem. [Re: TipmyPip] #487934
11/25/23 16:36
11/25/23 16:36
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The array size calculation looks wrong. See the remarks about the sizeof macro in the manual.

https://zorro-project.com/manual/en/structs.htm

Re: Xor Memory Problem. [Re: AndrewAMD] #487936
11/26/23 08:25
11/26/23 08:25
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
>Did you troubleshoot your code?
>https://zorro-project.com/manual/en/chart.htm
>https://zorro-project.com/manual/en/trouble.htm
>https://zorro-project.com/manual/en/errors.htm

Thank you for your response, Have you tried running my code in a regular C compiler? Do you know what this code performs? and why?
Why do you think I am asking the question in the forum?

>The array size calculation looks wrong. See the remarks about the sizeof macro in the manual.
>https://zorro-project.com/manual/en/structs.htm

Please explain and show me what is the right size of calculation in relation to the problem, and what calculation you expect, please, I would love to understand deeper, so we can solve the problem in lite-C,

Thank you


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487940
11/26/23 20:53
11/26/23 20:53
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by TipmyPip
Thank you for your response, Have you tried running my code in a regular C compiler? Do you know what this code performs? and why?
Why do you think I am asking the question in the forum?
I'm not paid to lurk here. Now oP Group support is paid, so you can always try them.

Also, jcl is right. Read the referenced manual page and run your own tests.

Re: Xor Memory Problem. [Re: AndrewAMD] #487941
11/27/23 00:24
11/27/23 00:24
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
I am sorry, This was not a question for paid support, The question was for curious minds, who don't care for money... because the money comes back on its own.
But you are right, if your time is very precious, I guess you would have other means of making money, every minute of the day.

We all need to improve on our logic Sir, I am here with the question because the reference manual will not answer tricky questions.
Only programmers, who can go beyond their own limits of their imagination.

Thank you in any case for your precious time.

Last edited by TipmyPip; 11/27/23 00:25.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487942
11/27/23 16:05
11/27/23 16:05
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Did you not see that your question was answered?

Try putting a dummy struct variable upstream of your sizeof calls. And then test sizeof to confirm it is outputting the expected values.

Re: Xor Memory Problem. [Re: AndrewAMD] #487943
11/28/23 09:56
11/28/23 09:56
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
>Try putting a dummy struct variable upstream of your sizeof calls. And then test sizeof to confirm it is outputting the expected values.

Have you tried your solution? Did it create any errors, If not please share the code, so I could understand by your code how did you resolve the issue.

But if you have not tried your solution and you only rely on your imagination, Please explain to me the logic by code, and clear syntax so I can see and understand your solution.
Thank you very much for your precious time, and positive contribution solution, that way, I could become a serious programmer like you.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487944
11/28/23 10:18
11/28/23 10:18
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
I’m happy to give you free supervision as you troubleshoot your code that is incompatible with Lite C. Good luck!

Re: Xor Memory Problem. [Re: AndrewAMD] #487945
11/28/23 10:36
11/28/23 10:36
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
But you already gave very good suggestions of "putting a dummy struct variable upstream of your sizeof calls."
Please show me in code what and how do you do that, if you understand what you mean.

Do you know what the code above performs?

Supervision can be given only on proper code. Not on poetic notions of code.

You always project your own boundaries on reality, which you want to go beyond, but only a few who walk the talk can put it into code...

Last edited by TipmyPip; 11/28/23 10:43.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487946
11/28/23 11:07
11/28/23 11:07
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
I'm not new to Lite C. And you missed this from the manual:
Quote
!! Unlike C/C++, sizeof(some struct) requires that at least one instance of the struct exists. Otherwise sizeof will return 0.
!! Arrays are internally treated as a pointer to a memory area. So, sizeof(some array) and sizeof(some pointer) always evaluates to 4 because that is the size of a pointer.
https://zorro-project.com/manual/en/structs.htm

You throw standard code at a nonstandard language and expect standard behavior? It won't always work.

Re: Xor Memory Problem. [Re: AndrewAMD] #487947
11/28/23 11:30
11/28/23 11:30
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Dear Andrew, Please consider, that I have already read the manual, I have requested from anyone who has more experience in programming, more abstract ideas, and a more creative mind,
to try to solve the problem, not refer me to the manual, which I have already done, and I have already written the code in lite-C, but I wish not to share my ideas,
I want to find the creative one, who is blessed with much more money to contribute his knowledge and time, that way, we can exchange ideas more with clear minds instead of competing on
poetic notions of unrealistic imagination.

But I guess I already asked you if you know what the code above performs...


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487948
11/28/23 14:03
11/28/23 14:03
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
I'm satisfied with the effort I put into this problem, but only because I'm not interested in solving it myself. If you really must have someone fix your code, you can always pay someone to do it for you.

Re: Xor Memory Problem. [Re: TipmyPip] #487949
11/28/23 14:23
11/28/23 14:23
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
I do understand, And I respect the wisdom of your choices, But if you can describe your solution with half a sentence, how come you can't show me what is the meaning of: "putting a dummy struct variable upstream of your size of calls"
it seems that sentence is describing initializing a struct with whatever you have difficulty describing in code because most likely you don't want to try to solve a problem which you don't have a solution for, let alone the money you don't have time for.

But you do have the time to prove your wisdom with no intentions by describing partial solutions that don't exist.

Our Future interactions might be beyond the wisdom of your current limitations, where I suppose you can't imagine other ways to make money.
If you think I need to pay for a limitation that lite-C can't resolve.

(The fact you stated: "but only because I'm not interested in solving it myself," proves your so-called suggestion doesn't have any logical basis, because you have already stated that you are not interested in solving it for yourself, meaning you don't have a clue of how to solve it, which also means you share your suggestions only to get some emotional credit for showing of your unlogical description of whatever you can't imagine with "putting a dummy struct variable upstream of your size of calls" in relation to the code I have written, This also proves that giving sarcastic supervision, doesn't make you a professional programmer, Sir.)

Last edited by TipmyPip; 11/28/23 15:03.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487981
12/13/23 10:55
12/13/23 10:55
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Here is an Abstract Strategy Example for those who can find the relation between the above C program and Financial Properties in relation to conditional attributes under certain market imbalances which can be mathematically calculated with logic gates
But, in order to solve the problem faster, and statistically find the most beneficial probabilities you will need to use advanced engineering ideas with Zorro Trader GPT.

Code
#include <litec.h>
#include <trade.h>

#define INT_BITS 32
#define MAX_NODES 1024
#define DATA_SIZE 20

// Trie node structure
typedef struct TrieNode {
    struct TrieNode* bit[2];
} TrieNode;

TrieNode trieNodes[MAX_NODES];
int trieNodeCount = 0;

// Function prototypes
TrieNode* newTrieNode();
void insert(TrieNode* root, int number);
int findMaxXOR(TrieNode* root, int number);
int getMaxXOR(int* arr, int size);
var calculateMaximumXOR(var spreadData[]);
string generateTradingSignal(var maxXOR, var threshold);

void run() 
{
    BarPeriod = 60; // Set your bar period
    LookBack = 100; // Set your lookback period
    
    while(asset(loop("Asset1", "Asset2"))) {
        var spreadData[DATA_SIZE]; // Array to hold spread data
        // Populate spreadData with your financial data logic
        // Example: spreadData[i] = priceClose(i) - priceClose(i+1) for some i

        var threshold = 0.02;
        var maxXOR = calculateMaximumXOR(spreadData);
        string signal = generateTradingSignal(maxXOR, threshold);

        if (!strcmp(signal, "Buy")) {
            enterLong();
        } else if (!strcmp(signal, "Sell")) {
            enterShort();
        }
        // "No Action" case is implicitly handled by doing nothing
    }
}

var calculateMaximumXOR(var spreadData[]) 
{
    int intSpreadData[DATA_SIZE];
    for(int i = 0; i < DATA_SIZE; i++) {
        intSpreadData[i] = (int)(spreadData[i] * 10000); // Scale and convert to int
    }
    return getMaxXOR(intSpreadData, DATA_SIZE);
}

string generateTradingSignal(var maxXOR, var threshold) 
{
    if (maxXOR > threshold) {
        return "Buy";
    } else if (maxXOR < -threshold) {
        return "Sell";
    } else {
        return "No Action";
    }
}

TrieNode* newTrieNode() { /* ... */ }
void insert(TrieNode* root, int number) { /* ... */ }
int findMaxXOR(TrieNode* root, int number) { /* ... */ }
int getMaxXOR(int* arr, int size) { /* ... */ }


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #487989
12/15/23 16:25
12/15/23 16:25
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Here is another strategy to help those who find the relation between the abstract currency moves in different timeframes and their relation to other currency moves.
If anyone has great ideas to share, I am quite sure money is already flowing in your world of creation and inspired beyond this physical world of desire.

Code
// Function prototypes
void ConvertToBinary(vars priceData, int* binaryRepresentation, int length);
void XORBinaryLists(int* list1, int* list2, int* result, int length);
int FindMaximumXOR(int* xorResult, int length);

void run() 
{
    // Set parameters
    BarPeriod = 60; // 1-hour bars
    StartDate = 2020;
    EndDate = 2021;
    LookBack = 100; // Look back period for initialization

    // Define the list of currency pairs
    string pairs[] = {"EURUSD", "GBPUSD", "USDJPY", "GBPJPY", "USDCAD", "EURAUD", "EURJPY", "AUDCAD",
               "AUDJPY", "AUDNZD", "AUDUSD", "CADJPY", "EURCAD", "EURCHF", "EURGBP", "EURNZD", 
               "GBPCAD", "GBPCHF", "NZDCAD", "NZDJPY", "NZDUSD", "USDCHF", "CHFJPY", "AUDCHF", 
               "GBPNZD", "NZDCHF", "CADCHF", "GBPAUD"
    int numPairs = sizeof(pairs) / sizeof(string);

    // Loop through each currency pair
    for(int i = 0; i < numPairs; i++) 
    {
        asset(pairs[i]);
        vars ClosePrices = series(priceClose());

        // Prepare binary representations for XOR operation
        int length = LookBack;
        int binaryPriceX[length];
        int binaryPriceY[length];

        // Fill binary representations (example: comparing current prices with a moving average)
        ConvertToBinary(ClosePrices, binaryPriceX, length);
        ConvertToBinary(series(SMA(ClosePrices, 20)), binaryPriceY, length); // 20-period SMA for comparison

        // Perform XOR operation
        int xorResult[length];
        XORBinaryLists(binaryPriceX, binaryPriceY, xorResult, length);

        // Find Maximum XOR value
        int max_xor = FindMaximumXOR(xorResult, length);

        // Example trading logic based on Maximum XOR
        if(max_xor == 1) // Significant divergence detected
            enterLong();
        else
            exitLong();
    }
}

void ConvertToBinary(vars priceData, int* binaryRepresentation, int length) 
{
    int i;
    for(i = 0; i < length; i++) 
    {
        binaryRepresentation[i] = (priceData[i] > priceData[0]) ? 1 : 0;
    }
}

void XORBinaryLists(int* list1, int* list2, int* result, int length) 
{
    int i;
    for(i = 0; i < length; i++) 
    {
        result[i] = list1[i] ^ list2[i];
    }
}

int FindMaximumXOR(int* xorResult, int length) 
{
    int max_xor = 0;
    for(int i = 0; i < length; i++) 
    {
        if(xorResult[i] > max_xor) 
            max_xor = xorResult[i];
    }
    return max_xor;
}


Thank you to the Team of Zorro Trader, who have inspired my life.

Last edited by TipmyPip; 12/15/23 16:29.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: TipmyPip] #488002
12/24/23 17:32
12/24/23 17:32
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline
Newbie
NewtraderX  Offline
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
So , did you get the answer you were looking for? did you get it from gpt?

Re: Xor Memory Problem. [Re: TipmyPip] #488003
12/24/23 17:52
12/24/23 17:52
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline
Newbie
NewtraderX  Offline
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
where are the definition for these binaryPriceX and binaryPriceY

int binaryPriceX[length];
int binaryPriceY[length];

Re: Xor Memory Problem. [Re: TipmyPip] #488004
12/24/23 23:12
12/24/23 23:12
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline
Newbie
NewtraderX  Offline
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
Originally Posted by TipmyPip
Here is another strategy to help those who find the relation between the abstract currency moves in different timeframes and their relation to other currency moves.
If anyone has great ideas to share, I am quite sure money is already flowing in your world of creation and inspired beyond this physical world of desire.
...........................................
Thank you to the Team of Zorro Trader, who have inspired my life.


Another question,
have you tried your gpt to solve this issue with your script?

Re: Xor Memory Problem. [Re: NewtraderX] #488009
12/26/23 15:58
12/26/23 15:58
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
Which one of the scripts? There are more to come, BTW... You try using Zorro Trader GPT, improve the script, and share the ideas with all of us, like I am...

There are several paths to proceed with the development...

1. HFT - tick Trading with Hilbert Transforms
2. LFT - currency strength
3. and a Combination of the above.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: Xor Memory Problem. [Re: NewtraderX] #488010
12/26/23 16:02
12/26/23 16:02
Joined: Sep 2017
Posts: 82
T
TipmyPip Online OP
Junior Member
TipmyPip  Online OP
Junior Member
T

Joined: Sep 2017
Posts: 82
>int binaryPriceX[length];
>int binaryPriceY[length];


Thank you for your interest, the definition of the above is based on different ideas for trading, if you try Zorro Trader GPT, you can create your own definitions for new strategies, and it is not difficult, Very easy...
We encourage you to explore your ideas and share them with us...

For example :

binaryPriceX[MAX_LENGTH]: This array stores the binary representation of the current price data. The conversion to binary is based on a specific condition. In the example, this condition is whether each price is greater than the first price in the lookback period. This is done in the ConvertToBinary function. For each price in the ClosePrices data series:

If the price is greater than the first price in the series (ClosePrices[0]), the corresponding element in binaryPriceX is set to 1.
If the price is less than or equal to the first price in the series, the corresponding element in binaryPriceX is set to 0.
binaryPriceY[MAX_LENGTH]: This array stores the binary representation of the Simple Moving Average (SMA) of the price data. The SMA is calculated over a specified period (20 periods in your example). The conversion to binary follows the same logic as binaryPriceX, comparing each SMA value to the first price in the ClosePrices series.

If the SMA value is greater than ClosePrices[0], the corresponding element in binaryPriceY is set to 1.
If the SMA value is less than or equal to ClosePrices[0], the corresponding element in binaryPriceY is set to 0.
These binary representations are then used for further analysis, such as the XOR operation in your strategy. The XOR operation compares the corresponding binary values in binaryPriceX and binaryPriceY for each period. The result of this operation (stored in xorResult) can indicate differences or divergences between the current price trend and its moving average, which you use to make trading decisions.

Last edited by TipmyPip; 12/26/23 16:14.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Page 1 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | 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