Exiting with ATR

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #164319 quote
    assafn
    Participant
    Average

    Hello,

    I need help with creating a code that exits a trade 2 ATR’s above entry price:

    ex.

    if close>high[1] then
    buy 10000 cash at market

     

    Is that Possible?

    Thanks

    #164325 quote
    Vonasi
    Moderator
    Master

    When you place your buy order you can not know the entry price you will get so we have to assume it is the same as the close price. Once we are ‘onmarket’ we can adjust the exit price based on our actual entry price as we now know it.

    We use pending limit orders to exit at the better price.

    p = 10 //ATR period
    
    if not onmarket and close>high[1] then
    buy 1 contract at market
    myatr = averagetruerange[p](close)*2
    tp = close + myatr
    sell at tp limit
    endif
    
    if onmarket then
    tp = positionprice + myatr
    sell at tp limit
    endif
    #164330 quote
    assafn
    Participant
    Average

    Thanks Vonasi!

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

Exiting with ATR


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
assafn @assafn Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by assafn
4 years, 11 months ago.

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