This code snippet demonstrates how to calculate the profit of a trading strategy in points or pips, adjusting for the size of the position and the point value of the instrument. This is particularly useful for evaluating the performance of a trading strategy in a standardized unit, regardless of the contract size or leverage used.
minContract = 1
if(strategyprofit<>strategyprofit[1]) then
pnl = strategyprofit-strategyprofit[1]
size = max(minContract,abs(countofposition[1]))
onepos = pnl/size
pointprofit = onepos/pointvalue
strategyprofitpoint = strategyprofitpoint+pointprofit
endif
Explanation of the Code:
minContract is set to 1, ensuring that the minimum size of the position considered is always at least one contract.if statement checks if the current strategy profit (strategyprofit) is different from the previous period’s strategy profit (strategyprofit[1]). This is to ensure calculations are only performed when there is a change in profit.pnl (profit and loss) is calculated as the difference between the current and previous strategy profits.size is determined by taking the maximum value between minContract and the absolute value of the position count from the previous period (abs(countofposition[1])). This ensures that the size is at least one and reflects the actual position size.onepos calculates the profit per position by dividing pnl by size.pointprofit is calculated by dividing the profit per position (onepos) by the point value of the instrument (pointvalue). This standardizes the profit to the smallest measurable move of the instrument.strategyprofitpoint) is updated by adding the profit for the current period (pointprofit).This snippet is a practical example of how to manage and evaluate trading strategy performance in terms of points or pips, which is crucial for comparing strategies across different instruments or markets.
Check out this related content for more information:
https://www.prorealcode.com/topic/strategyprofit-of-points/#post-89205
Visit Link