setting Stops and Targets based on the executed price

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #136134 quote
    Jaldidee
    Participant
    Average

    Hello Everybody,

    I have a question aboiut a part of a code I am working on. Basically I tell to enter a trade at the high of a bar.

    I the set my stop at the low of the bar and I calculate the difference between these two points. I then multiply this by 2 and that will be my target.

    Now after a while I find that due to slippage the entry point is usual a few points above the bar high. Is there a possibility to use the actual executed price in the calculation of stop and target?

    mylimitbuy = high[1] + 0.2
    mystoplong = low[1]-4
    mytargetlong = mylimitbuy + (2*(mylimitbuy-mystoplong))
    
    // Conditions to enter long positions
    IF not onmarket and (tradeindex(1)< myindex) and  mylimitbuy > 0 AND positionsizelong < maxpositionsize AND not daysForbiddenEntry THEN
    BUY positionsizelong CONTRACT AT mylimitbuy STOP
    endif
    
    sell at mystoplong stop
    sell at mytargetlong limit

    Hope someone can help me.

    Kind Regards,

    Jaldidee

    #145463 quote
    robertogozzi
    Moderator
    Master

    Please Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.

    Thank you 🙂

    1. I suggest that you move lines 10-11 to a new line just before line 8, so that they don’t move each new bar due to lines 1-3.

    2. TradePrice (or PositionPrice when cumulating positions) is only known when the bar where the trade entered CLOSES, so you can check when you are OnMarket but weren’t the previous bar (using If OnMarket AND Not OnMarket[1]) then re-calculate SL & TP according to the real price and setting them again will overwrite the previous one.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

setting Stops and Targets based on the executed price


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Jaldidee @jaldidee Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
5 years, 5 months ago.

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