Implementing Time-Based Position Management to Avoid Overnight Fees

12 Dec 2016
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to manage trading positions based on specific time conditions to avoid overnight fees. The strategy involves exiting positions just before the daily fee calculation time and re-entering them after the fee time has passed.


DEFPARAM CumulateOrders = False
myLongCond = average[10,0](close) CROSSES OVER average[100,0](close)
myShortCond = average[10,0](close) CROSSES UNDER average[100,0](close)
IF myLongCond THEN
    BUY 2 CONTRACTS AT MARKET
ELSIF myShortCond THEN
    SELLSHORT 3 CONTRACTS AT MARKET
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 200
ONCE Skipped = 0
IF ((OpenTime > 230000) OR (OpenTime > 0 AND OpenDay <> myDay)) AND Skipped THEN
    IF Skipped = 1 THEN
        BUY myLots CONTRACTS AT MARKET
    ELSIF Skipped = -1 THEN
        SELLSHORT myLots CONTRACTS AT MARKET
    ENDIF
    Skipped = 0
ENDIF
IF OpenTime = 225500 THEN
    myLots = abs(CountOfPosition)
    myDay = OpenDay
    Skipped = Longonmarket + ShortOnMarket*-1
    IF Skipped THEN
        SELL AT MARKET
        EXITSHORT AT MARKET
    ENDIF
ENDIF
//graph Skipped

This code snippet includes several key components:

  • Condition Definitions: The conditions for entering long and short positions are defined based on the crossover of moving averages.
  • Order Execution: Trades are executed based on the defined conditions. If the long condition is met, 2 contracts are bought. If the short condition is met, 3 contracts are sold short.
  • Stop Loss and Profit Targets: A stop loss of 100 and a profit target of 200 are set for each trade.
  • Time-Based Exit: The script checks the time and exits all positions at 22:55 (225500 in military time) to avoid overnight fees, which are typically charged based on positions held at 23:00.
  • Re-Entry Logic: After exiting, the script uses a variable Skipped to remember if the position was long or short. When the market opens the next day, it re-enters the position accordingly.

This approach helps in managing trading costs by avoiding overnight fees, which can significantly impact profitability especially in high-frequency trading scenarios.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/avoiding-cfd-financing-costs-overnight-positions/#post-229848

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...