Skip to content

Commit fce45a1

Browse files
author
EarnForex
authored
Merge pull request #12 from akhater/patch-1
"Fixed" position size splitting to take a full total position size with multiple TPs when rounded down PS would result in reduced total PS. Needs also a relevant change to the calculator.
2 parents a20fe8b + ce0b770 commit fce45a1

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

MQL4/Scripts/PSC-Trader.mq4

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,14 @@ void OnStart()
395395
}
396396

397397
// Going through a cycle to execute multiple TP trades.
398-
for (int j = 0; j < n; j++)
398+
// ak
399+
double AccumulatedPositionSize = 0;
400+
double ArrayPositionSize[];
401+
402+
ArrayResize(ArrayPositionSize, n + 1);
403+
404+
for (int j = n; j >= 0; j--)
399405
{
400-
double order_sl = sl;
401-
double order_tp = NormalizeDouble(ScriptTPValue[j], _Digits);
402406
double position_size = PositionSize * ScriptTPShareValue[j] / 100.0;
403407

404408
if (position_size < MinLot)
@@ -420,6 +424,28 @@ void OnStart()
420424
Print("Adjusting position size to the broker's Lot Step parameter.");
421425
}
422426

427+
// ak
428+
if ( j > 0)
429+
{
430+
AccumulatedPositionSize += position_size;
431+
}
432+
else
433+
{
434+
position_size = PositionSize - AccumulatedPositionSize;
435+
}
436+
437+
Print(PositionSize, "-----------", position_size);
438+
439+
ArrayPositionSize[j] = position_size;
440+
}
441+
442+
for (int j = 0; j < n; j++)
443+
{
444+
double order_sl = sl;
445+
double order_tp = NormalizeDouble(ScriptTPValue[j], _Digits);
446+
double position_size = ArrayPositionSize[j];
447+
448+
423449
// Market execution mode - preparation.
424450
if ((Execution_Mode == SYMBOL_TRADE_EXECUTION_MARKET) && (entry_type == Instant))
425451
{
@@ -526,4 +552,4 @@ int CountDecimalPlaces(double number)
526552
}
527553
return(-1);
528554
}
529-
//+------------------------------------------------------------------+
555+
//+------------------------------------------------------------------+

0 commit comments

Comments
 (0)