Exiting with ATR

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #164319 quote
    assafnassafn
    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
    VonasiVonasi
    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
    assafnassafn
    Participant
    Average

    Thanks Vonasi!

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 assafnassafn
5 years, 6 months ago.

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