Take Profit for Multiple trades one pair (e.g. EURNZD 5 multiple trades)
Take Profit for Multiple trades one pair (e.g. EURNZD 5 multiple trades)
04 Aug 2016, 15:38
Hi All,
Can anyone tell me if there is code out there that has been developed that I can change multiple Take Profit with one input (that is if I want to target T/P of 1.5500 I will only need to punch in 1 price and changes are made to all open tickets for that pair & I don't have to input one price at a time). The same will apply to S/L. I know MT5 will aggregate all trades for the same pair and consolidate to one price. See picture below.
Replies
1007601
06 Aug 2016, 16:51
RE:
There might be a few ways:
(1) is to do a definite pip-position, the other is to have an overall account $ value for take profit:
I have tried this to find an average entry point of all positions, and then set a limit order:
// now recalculate average entry point; then setting a limit order for each position
// average entry +/- target;
double _avrgE = 0;
double _lotsE = 0;
double _Numm = 0;
double _tbP = 0;
foreach (var position1 in Account.Positions)
{
_avrgE = _avrgE + (position1.Volume * position1.EntryPrice);
_lotsE = _lotsE + position1.Volume;
if (position1.EntryPrice > highest_level) {highest_level = position1.EntryPrice;}
if (position1.EntryPrice < lowest_level) {lowest_level = position1.EntryPrice;}
}
// tradetype = buy;
if (DD == 1) // this is an overal value of direction of trade;
{
_tpB = Math.Round(_avrgE + Symbol.PipSize * _takeProfit, Symbol.Digits); //I had a pip size set to the _takeProfit variable
}
// tradetype = sell;
if (DD == 2) //ditto
{
_tpB = Math.Round(_avrgE - Symbol.PipSize * _takeProfit, Symbol.Digits); //ditto
}
// modify
foreach (var position in Account.Positions)
{
Trade.ModifyPosition(position, null, _tpB);
}
}
@1007601
... Deleted by UFO ...