Looks like...
Each time through your loop, Profit1 and Profit2 are set to 0 when they are declared.
One of them gets set to the profit of a ticket.
So, the test
if ( ProfitTotal >= SecureProfit )
is not doing what you want.
ProfitTotal is equal to Profit1 +0 or it equals 0 + Profit2 at the time of the test.
Looks like...
Each time through your loop, Profit1 and Profit2 are set to 0 when they are declared.
One of them gets set to the profit of a ticket.
So, the test
if ( ProfitTotal >= SecureProfit )
is not doing what you want.
ProfitTotal is equal to Profit1 +0 or it equals 0 + Profit2 at the time of the test.
Thanks phy,
What you're saying makes total sense, I just can't figure out how to correct it. I'm thinking that maybe I need to add the profits together in a loop, then check to see if the ProfitTotal has been met, then close the orders in another loop.
If you have any suggestions, please let me know!
Thanks
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I'm coding a hedging strategy where I enter a trade on a symbol and place an opposite direction trade on the hedge symbol. When the sum of the profits of the two orders are >= a set profit amount in dollars, I want to close both orders.
My problem is that the expert seems to close both orders as soon as one of the the orders hits the desired profit level and not when the sum of the two orders is at the desired profit level.
Below is a sample of the code, can anyone help me figure out what I'm doing wrong? Keep in mind that more often than not, one order will have a positive profit and the other one will have a negative profit.
The base symbol is given MagicNumber 1 and the hedge trade is given MagicNumber 2. I have included a Comment instruction that shows the ProfitTotal and it shows the correct value, but for some reason
the expert seems to only look at the individual order profits when deciding to close both orders.
Thanks in advance for any help!!!