Profit Math
-
Hello experts. Sorry, cannot think of the correct topic.
I need help to do this, my idea in securing profit.For example.

Lets say the current profit is now 2200. And it can still go up&down.
So i want to make like this, the ea will record the highest total current profit achieved. As the picture show its 2200.
When the number decrease more than certain % from the highest current profit, e.g 60%, the ea will close all trade, and we secure the 40% profit.
Also to set the minimum current profit, lets say 1000. The rule applies when the current profit reach minimum 1000.
And so if highest is 1000, it will close at 400. Highest 2200 will close at 880. If the profit increase, the ea will record the new high to count the 60% decrement.Hope its easy to understand and can guide with the block arrangement.
Thanks a lot.
-
Use trailing stop, it has a "% of profit" option
-
So this is the same solution that i couldn't understand clearly before?
Hahaha... Thanks a lot @roar. Hopefully my understanding is correct now. And so i should use the group trailing for this, right?But how can i set the minimum profit to start the trailing?
-
if you put stop loss you need to put same value in trailing group
-
-
could you send SL you are using
-
-
@josecortesllobat Could you help me also with my TP average please? I want to code so that each child trade that is placed, make the take profit go to the average of of all trades running. This is what roar suggested but I can not get it to work correctly and also is based on random lot sizes, which it should not be.
0_1598185891976_AO - Test Average TP.mq5
The following picture is how I want it to work

I would really appreciate your help .. Thank you in advance!!
-
Hi @AlphaOmega , i use to see this in martingale version EA. But i also don't know how to set the TP.
@ramisignals , sorry i'm just thinking of the idea, but haven't set any specific SL yet.
@josecortesllobat , seems it has been done before, but when it comes to variables, hohohohoho..

*hoping someone can set for me to give it a try... -
Yes... It is similar bur there is also a twist in the money management because martin only can be dangerous... So i am hoping on someone to help me with this... The senior members has the answer.... Please consider helping here guys because I have no clue how to go about this.... Thank you in advance!
-
Hi @biztet
@roar built that amazing profit checker code. I can say that works greatfully and it was built using variables.

"the ea will record the highest total current profit achieved. As the picture show its 2200."
'maxprofit' == 0 (reset it as per you need)
If 'Equity' > 'maxprofit' -> 'maxprofit' == "Equity'"When the number decrease more than certain % from the highest current profit, e.g 60%, the ea will close all trade, and we secure the 40% profit0."
If 'Equity' <= 'maxprofit' -> calculate 'Ratio' as 'Equity' / 'maxprofit'
If 'Ratio' < MinRatio (0.6 for you) -> Close positions"Also to set the minimum current profit, lets say 1000. The rule applies when the current profit reach minimum 1000."
You just need to add condition blocks somewhere within your code to activate the 'profit checker'. This might be an approach:
Define -> bool ProfitCheckerON false (reset it as per your need)
Condition block -> If 'Equity' > 1000 -> ProfitCheckerON == true
Condition block -> If ProfitCheckerON == true -> true output is activated and the profit checker starts to workHi @AlphaOmega
Regarding to your question: TP average. Probably there is a much efficient way to code it because fxDreema allows to reach the same goal with multiple ways. I assume that each child trade has a fixed TP that probably will be the same as for the parent trade. Let´s call it 'TakeProfitPips'. Using your example,
nTrades == 0 (reset it as per your need)
TakeProfitPips == 100OpenPrice_ParentTrade == 1.00000
nTrades == 1TPLevel_ParentTrade == OpenPrice_ParentTrade + TakeProfitPips (as price fraction) = 1.00000 + 0.00100 = 1.00100
OpenPrice_ChildTrade1 == 1.00010
nTrades == 2TPLevel_ChildTrade1 == OpenPrice_ChildTrade1 + TakeProfitPips (as price fraction) = 1.00010 + 0.00100 = 1.00110
TakeProfitAv == (TakeProfitPips + (TPLevel_ChildTrade1 - OpenPrice_ParentTrade) "as pips")) / nTrades
= (100 + (1.00110 - 1.00000) "as pips" ) / 2
= (100 + 110) / 2 = 210 / 2 = 105Modify ChildTrade1 TP to 105 pips -> TP_ChildTrade == 105
OpenPrice_ChildTrade2 == 1.00020
nTrades == 3TPLevel_ChildTrade3 == OpenPrice_ChildTrade3 + TakeProfitPips (as price fraction) = 1.00020 + 0.00100 = 1.00120
TakeProfitAv == (TakeProfitPips + [(TP_ChildTrade ) + (TPLevel_ChildTrade2 - OpenPrice_ParentTrade) "as pips"]) / nTrades
= (100 + [(105) + (1.000120 - 1.00000) "as pips" ] )/ 3
= (100 + [(105) + (120)] )/ 3 = 325 / 3 = 108.3Modify ChildTrade2 TP to 108 pips -> TP_ChildTrade == 108
.... and so on
Not sure if that is what you are looking for strictily but might be a starting point.
-
Nice work @josecortesllobat .
Yes i did read most of the last 2-3years discussion on the topic. What i'm looking for is there.
But....i can only read.... :'(( -
@josecortesllobat .. Wow!! thank you so much for your reply... I will firstly try to understand what you have written because I have no coding skills as such and also secondly have never work with this variables/constants... Much appreciate that you took the time and trouble to help me here... Thank you!
-
Yeah, and after that you can help by sharing with me, right @AlphaOmega ?

-
Hi @roar , @josecortesllobat
Is this correct?
How can i add to make is start when the current profit reached certain amount, like $100/$500/$1000?
-
Is this correct? Only need these 2 variables, right?

-
@biztet you must put the condition "current profit is above maxprofit" before updating your maxprofit variable, otherwise "maxprofit" is actually just the current profit.
To set $100/$500/$1000 treshold, simply use "check profit"

-
Thanks @roar .
Btw, the EA is not running, got error i assume.
I just copy whats yours and create the variable maxprofit & ratio.Also pls guide how to reset the maxprofit value, if needed.
-
@biztet for example:

-
Is it enough if i just add like that ib my ea?
