This code snippet is designed to calculate and visualize the costs associated with holding positions overnight in trading systems, specifically focusing on the DAX 40 index. It accounts for broker fees, interest rates, and the impact of dividends, which are crucial for traders who hold positions overnight. The code also adjusts fees for positions held over the weekend.
Here is the ProBuilder code:
IF CurrentTime=220000 AND OpenDayOfWeek>0 then
SONIArate=4.75
if longonmarket then
int = (3 + SONIArate) * 0.01
myrate = - (abs(countoflongshares) * close * int)
endif
if shortonmarket then
int = (3 - SONIArate) * 0.01
myrate = - (abs(countofshortshares) * close * int)
endif
if onmarket then
mymonthrate = myrate / 12
mydayrate = myrate / 365
mytotalint=mytotalint+mydayrate
if opendayofweek=5 then
mytotalint=mytotalint+(mydayrate*2)
endif
endif
// DAX dividend adjustment
if longonmarket then
mydiv=(countoflongshares*close*0.0225)/260
mytotaldiv=mytotaldiv+mydiv
endif
if shortonmarket then
mydiv=-(countofshortshares*close*0.0225)/260
mytotaldiv=mytotaldiv+mydiv
endif
// Plot graphs
graph mytotalint coloured(100,40,100) AS "Interest"
graph mytotaldiv coloured(100,60,100) AS "Dividends"
graph mytotalint+mytotaldiv coloured(100,80,100) AS "Combined"
ENDIF
Explanation of the Code:
This snippet is a practical example of how to integrate financial considerations into trading algorithms, ensuring that all costs are accounted for in strategy evaluations.
Check out this related content for more information:
https://www.prorealcode.com/topic/calculating-overnight-fees-interest-and-dividends/#post-243755
Visit Link