accounting for and adjusting for slippage POSITIONPRICE vs expectedPositionPrice

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #128532 quote
    David
    Participant
    Veteran

    Hi team

    I’m trying to adjust future stop entry orders based on past slippage lets say for FX.

    I’m thinking a WHILE loop is the way to address this but struggling to get my head around it and also adding discount factor.

    Thanks for your help.

    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
    
    #128546 quote
    David
    Participant
    Veteran

    I think this will work for the expectedPositionPrice calculation?

    expectedPositionPrice = (tradeprice[countofposition] + (entryStep * (countofposition-1)))/2

    and would this be the correct WHILE LOOP?

    WHILE COUNTOFPOSITION > 1 DO
    i = i + 1
    expectedPositionPrice = tradeprice[i] + expectedPositionPrice
    expectedPositionPrice = expectedPositionPrice / countofposition
    WEND
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

accounting for and adjusting for slippage POSITIONPRICE vs expectedPositionPrice


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
David @dwgfx Participant
Summary

This topic contains 1 reply,
has 1 voice, and was last updated by David
5 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/28/2020
Status: Active
Attachments: No files
Logo Logo
Loading...