Thanks 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
endif
set 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”)