Paul McGalloway:
How was the trade closed ? If you close it manually then the magic is 0.
You should post the relevant code. Now you posted some code and show the output log of an other code which we can't see.
Had a similar problem once and it was because I was forgetting to set the magic number, also idk about your code but the ChartID in the strategy tester is always zero and you can't do anything that switches ChartIDs between charts in the strategy tester. Found this out when trying to draw objects on different charts using ObjectCreate() in a multisymbol EA. There isn't anything you can do about it. If you still want something that switches between different charts then you have to test it on a live or demo account you can't do it inside the strategy tester(from what I understand at least I could also be wrong but I'm pretty sure I am not). I think ChartID will always return 0 inside the strategy tester.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have seriously lost it, my patience has snapped with this thing.
I am so sick of absolutely screaming and going bat shit crazy just because MQL5 can't do something as simple as retrieve a magic number.
It is not difficult for this thing to comprehend something so simple, but I have never been so angry in my entire as am right now with this thing.
This computer is going to be on the receiving end of an axe if MQL5 does not start going as it's told.
I hae a programme which utilizes the `OnTradeTransaction` even handler.
Petty simple, right?
Evidently not.
Clearly! Because that would make my life - just for change, just one - just that little bit more simpler.
Oh no!
The Issue:
I have the same symbols over multiple timeframes, I also have to identify which chart period the EA is referring to - so I declared the `ChartID` variable & I have declared this globally.
The `ChartID` variable is the magic number, as per the trade request in my MRE. The `ChartID` is unique to the period, as well as the symbol.
Re-producable Example
This is my OnTradeTransaction setup
Global Declaration
Now, I am going to ask, very calmly, very quietly and very rational, because I am so fuming right now I'm am going to have a break down. I am so tired of nothing I do ever working, I am so tired of trying so hard, just for MQL5 to decided to throw it back in my face. I am sick sick sick sick to bloody death of it.
These are the logs:
Why does the `request_deal_magic` revert to zero when the deal closes?
One more error message or issue and it's going to get the axe.