DEFPARAM CumulateOrders = True // Cumulating positions activated
entryStep = 0.001
IF NOT ONMARKET THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF ONMARKET THEN
// 2nd trade
IF COUNTOFPOSITION = 1 THEN
BUY 1 CONTRACT AT tradeprice(1)+entryStep STOP
ENDIF
// lets adjust the next Stop entry to account for the slippage
// When there is more than 1 position we can start to compare
// the executed tradeprice VS the expected tradeprice
// based on the average price
IF COUNTOFPOSITION > 1 THEN
expectedPositionPrice = 0
// let's get the expectedPositionPrice
// PART 1 where I'm stuck
WHILE COUNTOFPOSITION > 1 DO
i = i + 1
expectedPositionPrice = (tradeprice[i] + )/ COUNTOFPOSITION
WEND
// this would be the slippage
actualSlippage = POSITIONPRICE - expectedPositionPrice
// PART 2 where I'm stuck
// I know we cannot just tighten the entry based on the slippage
// we need to reduce it further to get us closer to the expectedPositionPrice
// it must be by somefactor but what factor?
adjustedEntryStep = entryStep - (actualSlippage * somefactor?)
BUY 1 CONTRACT AT tradeprice(1)+adjustedEntryStep STOP
ENDIF
ENDIF