Order Accumulation Coding
Forums › ProRealTime English forum › ProBuilder support › Order Accumulation Coding
- This topic has 5 replies, 4 voices, and was last updated 2 months ago by Niklas87.
-
-
09/27/2024 at 8:50 AM #238119
Hello,
defparam cumulateorders=true
means you can have several positions open on the same instrument. However, it seems this also means stop losses and take profit will “average out”.
How can you code it so that each trade is “individual” but still that the system allows for several positions to be opened? defparam cumulateorders=false means just one position at a time….
thanks and best regards
09/27/2024 at 9:45 AM #238126Hello,
You are correct that defparam cumulateorders=true allows multiple positions to be opened on the same instrument, and in this mode, stop loss and take profit orders are often handled in a cumulative way. If you want to have more control over individual exits while still allowing multiple positions, you need to program different exit levels based on specific conditions.To achieve this, you can monitor the number of open positions and set different exit levels using stop and limit orders. Here’s how you can manage it:
1) Track the number of open positions: Keep track of how many positions are open and apply exit conditions accordingly.
2) Set different exit levels: Use SELL n CONTRACTS AT priceStopX STOP and SELL n CONTRACTS AT priceTPX LIMIT to define different exit levels based on your desired conditions.09/27/2024 at 10:12 AM #238130It means that you can open additional positions, after the first one, in the same direction.
Stop Loss and Profits will be averaged out (see attached pic and eXcel sheet).
Be warned that drawdown and required margins will increase accordinly.
09/27/2024 at 11:08 AM #238137Thanks a lot to both of you.
The code im using is here, this is for a short strategy. Is there a simple way to change the code so that each order is “individual” basis the same conditions…?
best regards
defparam cumulateorders=true
//v1.1. time settings + trailing stop modifications
//v1.2 – %trailing modified in points; quantity of orders per stoploss size (typical money management).// — TIME SETTINGS
StartHour = 120000
EndHour = 240000
// — ORDERS SETTINGS
InitialCapital = 10000 // capital at start of the strategy
// — CONSTANT SETTINGS
VolatilityPeriod = 15
DefaultRiskPercent = 1.33
HighVolatilityRiskPercent = 1.33
DefaultTrailingStopPercent = 3.0
//HighVolatilityTrailingStopPercent = 3.0
// — DATE SETTINGS
$Date[0] = 20241017
$Order[0] = 2
$Date[1] = 20241018
$Order[1] = 1
$Date[2] = 20241031
$Order[2] = 2
$Date[3] = 20241101
$Order[3] = 1
$Date[4] = 20241104
$Order[4] = 2
$Date[5] = 20241105
$Order[5] = 1
$Date[6] = 20241205
$Order[6] = 2
$Date[7] = 20241206
$Order[7] = 1
$Date[8] = 20241213
$Order[8] = 1
$Date[9] = 20241216
$Order[9] = 2
$Date[10] = 20241217
$Order[10] = 2
$Date[11] = 20241218
$Order[11] = 1// ————
tc = time >= starthour and time < endhour
// Calculate historical volatility
HistoricalVolatility = HistoricVolatility[VolatilityPeriod ](close)// Determine risk and trailing stop based on volatility
IF HistoricalVolatility > 25 THEN
RiskPercent = HighVolatilityRiskPercent
ELSE
RiskPercent = DefaultRiskPercent
ENDIF// Calculate the price movement in percentage terms from the entry price
IF shortonmarket THEN
priceMovement = (tradeprice – close) / tradeprice * 100
ELSIF longonmarket THEN
priceMovement = (close – tradeprice) / tradeprice * 100
ENDIF// Adjust trailing stop loss based on price movement
IF priceMovement >= 3.0 THEN
trailingStopLoss = 0.99
ELSIF priceMovement >= 1.5 THEN
trailingStopLoss = 1.75
ELSIF priceMovement >= 1.0 THEN
trailingStopLoss = 2.5
ENDIF// Calculate the amount to risk per trade based on account equity
//AccountEquity = strategyprofit + initialcapital
//RiskAmount = AccountEquity * RiskPercent / 100// Entries checking
EntryDatesShort = 0
for i = 0 to 11 do
if date = $date[i] then
EntryDatesShort = 1
if $order[i] = 0 then
continue
else
quantity = $order[i]
break
endif
endif
next//v1.2
//MM lot size
REM Money Management
StopLoss = (max(trailingStopLoss, DefaultTrailingStopPercent) * close) / pointsize
REM Calculate contracts
equity = InitialCapital + StrategyProfit
maxrisk = round((equity * RiskPercent) * quantity)
PositionSize = abs(round((maxrisk / StopLoss) / PointValue, 2) * pipsize)// initiate order
size = 0
if EntryDatesShort and tc and date <> lastentrydate then
size = PositionSize
sellshort size shares at market
lastentrydate = date
endif//set stop %trailing TrailingStopPercent
if trailingStopLoss > 0 then
trailsize = (trailingStopLoss / 100) * close
else
trailsize = (DefaultTrailingStopPercent / 100) * close
endifset stop trailing trailsize
//graph trailsize
//graph stoploss
//graph positionsize
//graph HistoricVolatility[VolatilityPeriod](close)
//graph historicalvolatility
//graph size
//graph entrydatesshort and tc
//graph riskpercent
//graph round((RiskAmount / close) * quantity, 1)
//graph (RiskAmount / close) * quantity coloured(“red”)09/28/2024 at 4:36 PM #238208Can you explain your question “so that each order is “individual” basis the same conditions…?” and possibly post an example?
10/07/2024 at 8:25 AM #238556You cant have seperate orders in the same stratergy.
cumulateorders=true will just add contracts to your current position.
The only way around that would be differnet exits for even/odd numbers off contracts or exits based on the amount off contracts in the market.
-
AuthorPosts
Find exclusive trading pro-tools on