PositionProfitCustom (Function)
The PositionProfitCustom function calculates a customized position profit value based on a specified price, for either current position profit or maximum position profit.
Syntax
PositionProfitCustom(LongProfit, ShortProfit, MaxPosProfit)
Returns (Double)
A customized position profit value based on a specified price, for either current position profit or maximum position profit.
Parameters
Name |
Type |
Description |
LongProfit |
Numeric |
The price upon which the long-side profit calculation is based. Usually the High or Close of the bar is used. |
ShortProfit |
Numeric |
The price upon which the short-side profit calculation is based. Usually the Low or Close of the bar is used. |
MaxPosProfit |
Boolean |
A True/False value where, if it is set to True, the function calculates the Maximum Position Profit. If it is set to False, the function calculates the current position profit. |
Remarks
This function allows you to specify the price value upon which the profit calculation is based. When there is no position, the function will return the position profit value, based on the most recent position.
Examples
Assigns to Value1 the Maximum Position Profit calculated from the High on the long side and from the Low on the short side:
Value1 = PositionProfitCustom(High, Low, True);
Assigns to Value2 the current Position Profit calculated from the Close for both the long and short sides:
Value2 = PositionProfitCustom(Close, Close, False);
Additional Example
If you wanted to place a long and a short exit on the Close when the maximum position profit, based on the extreme values (High and Low), reached $500, you could use the following syntax:
If PositionProfitCustom(High, Low, True) >= 500 AND
MarketPosition <> 0 Then Begin
Sell This Bar on Close;
BuyToCover This Bar on Close;
End;