@RajVoCash you have a block "For each closed position", very simple to get the closed profit using that block and "modify variables". No need to use custom code.
Technically its possible to use custom functions by either
Making a custom block in the studio Taking the inside part of the function (the stuff within {}) and putting that to custom mql block, and finally putting the result (that would normally be the "return" statement) into a standard fxdreema variable.These 2 methods will be 50x more difficult than using the standard blocks, but youre welcome to try if you like making things difficult lol