|
Xor Memory Problem.
#487932
11/23/23 18:41
11/23/23 18:41
|
Joined: Sep 2017
Posts: 82
TipmyPip
OP
Junior Member
|
OP
Junior Member
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? #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;
}
|
|
|
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
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,725
Chicago
|
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
TipmyPip
OP
Junior Member
|
OP
Junior Member
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.
|
|
|
Re: Xor Memory Problem.
[Re: AndrewAMD]
#487945
11/28/23 10:36
11/28/23 10:36
|
Joined: Sep 2017
Posts: 82
TipmyPip
OP
Junior Member
|
OP
Junior Member
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.
|
|
|
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
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,725
Chicago
|
I'm not new to Lite C. And you missed this from the manual: !! 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.htmYou 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
TipmyPip
OP
Junior Member
|
OP
Junior Member
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...
|
|
|
Re: Xor Memory Problem.
[Re: TipmyPip]
#487949
11/28/23 14:23
11/28/23 14:23
|
Joined: Sep 2017
Posts: 82
TipmyPip
OP
Junior Member
|
OP
Junior Member
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.
|
|
|
Re: Xor Memory Problem.
[Re: TipmyPip]
#487981
12/13/23 10:55
12/13/23 10:55
|
Joined: Sep 2017
Posts: 82
TipmyPip
OP
Junior Member
|
OP
Junior Member
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. #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) { /* ... */ }
|
|
|
Re: Xor Memory Problem.
[Re: TipmyPip]
#487989
12/15/23 16:25
12/15/23 16:25
|
Joined: Sep 2017
Posts: 82
TipmyPip
OP
Junior Member
|
OP
Junior Member
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. // 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.
|
|
|
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
Newbie
|
Newbie
Joined: Mar 2021
Posts: 35
Ocean county, Florida
|
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]
#488010
12/26/23 16:02
12/26/23 16:02
|
Joined: Sep 2017
Posts: 82
TipmyPip
OP
Junior Member
|
OP
Junior Member
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.
|
|
|
|