Welcome to NexusFi: the best trading community on the planet, with over 150,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.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I wrote this simple code to have a MACD signal but with a martingale type Money management. It works quite well but I can't fix a problem. When the bot calculates the signal it is as if it divides the long and short traders and creates 2 separate martingales. I would like the martingale to be unique. How can I solve?
It is just a thought, but have you tried splitting this into a long and short signal (strategy)? Just add both signals to your chart and that should do it, I think.
The problem is opposite...Currently with the signals together the martingale behaves as if the long and short signals were separate. I would need the martingale to work for both signals at the same time. If I have a losing long signal and the next signal is not a long but a short I still need to apply the martingale factor. Now if I have a losing long signal the martingale factor is applied to the next long signal and not to the next one (both long and short).
Okay, I understand better. I am having difficulty visualizing this, so maybe you can diagram this in a process/program flowchart, which may help your thinking. Working through the code, you might need to add logic for Martingale short and long, or just keeping track of which direction you are going.
You code makes me think you are pyramiding, not applying Martingale. It looks like you are adding to a losing position (adding an additional contract/share). Adding a position in the other direction will close the current position. Martingale, as I understand it, applies to closed trades. So you need to track the last trade, both direction and whether it was a profit or loss.
Again, if I were you, I would flowchart this on paper or use a tool like draw.io / diagrams.net (https://app.diagrams.net/. This is what I use, and it usually helps me sort out flawed logic.