Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- The NexusFi team
(If you already have an account, login at the top of the page)
1. I want to use a counter in a method. This does not yet work thread safe.
Sample 1a would be encapsulated but does not return a correct value.
Sample 1b works, but is not thread-safe (==> Sample2)
2. How can I use predecessor values in a method?
Sample 3 shows that no previous value is determined with this procedure.
Analog Sample 1b I can initialize the series outside the method; this solution is also not thread safe.
I gave the examples because I want to simplify my request.
I make 5 calculations with different values, but they always have the same conditions.
This requires a TickCounter and a previous value.
That's why I want to do the calculations in a method, using thread-safe variables.
My programming example shows that reusing a variable does not work if it is initialized outside the method.
I would have to use 5 variables or series for my 5 calculations, so that the method actually makes no sense.
Finally, methods should simplify the code and "save" variables.
There are suggestions on how I can solve the problem?
Thank you!
Best
user10
PS: Are there any examples of function programming in the forum; I did not find any.
Can you help answer these questions from other members on NexusFi?
Thanks for the hint.
In the meantime, I've learned that threadsafe is probably the wrong name.
I calculate values in periods whose beginning and end are indefinite. At the end of the period I would like to do another calculation;
because the condition is wrong at this time, I need to access the predecessor value.
In real-time operation, this condition is true for one bar, but the condition should only be true for a tick to execute the calculation once.
These 5 calculations are performed with different values and periods and all five should access one method.
I understand that I can initialize variables and series outside the method.
Then both the counter and the return of the previous value will work.
In my example barCounterF () and barCounterThread () I increase the same variable barCounterFuncIn once by 1 and once by 2 and return it.
Although I assign a different variable (functionValue1 and functionValue2) to the respective return value, the methods influence each other.
If I change the barCounterThread () method to another variable e.g. assigning barCounterFuncIn1, both methods provide the correct result.
I added the code for verification.
If I want to simplify my code, this must not happen. It also makes no sense to use exactly the variables and series that I would have to use without any method.