How can I code ATR for position sizing and stops ?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #84876 quote
    hendymk
    Participant
    New

    Hi,

    I am trying to create a very basic code that I can then improve upon but I am really struggling to ATR stop. Everything I have tried comes back with an error. Can someone please help me ?

     

    Thanks people

     

    // Conditions to enter long positions
    IF NOT LongOnMarket AND Average[50](close) crosses under DClose(1) THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND Average[50](close) crosses over DClose(1) THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND Average[50](close) crosses over DClose(1) THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND Average[50](close) crosses under DClose(1) THEN
    EXITSHORT AT MARKET
    ENDIF

    I

    #84882 quote
    TempusFugit
    Participant
    Veteran

    Hi Hendymk,

    I use this code with some of my systems:

    //Variables
    NATR = A //ATR Period
    SATR = B // ATR Multiplier for Stop
    PATR = C// ATR Multiplier for Profit
    
    //Stop and Target
    SET STOP LOSS SATR*AverageTrueRange[NATR](close)
    SET TARGET PROFIT PATR*AverageTrueRange[NATR](close)

    Does it work for you?

    Nicolas and hendymk thanked this post
    #85051 quote
    hendymk
    Participant
    New

    Hi Tempus,

    I will try this over the weekend, appreciate your help. Thank you.

    #85177 quote
    GraHal
    Participant
    Master

    I use this code with some of my systems:

    I added your code as Row 78 to the Snippet Library.

    #109436 quote
    sulimaster
    Participant
    Average

    Hi Tempus

    Would this code work with SET STOP pTRAILING as well?

    //Variables
    NATR = A //ATR Period
    SATR = B // ATR Multiplier for Stop
    PATR = C// ATR Multiplier for Profit
    
    
    //Stop and Target
    SET STOP LOSS SATR*AverageTrueRange[NATR](close)
    SET TARGET PROFIT PATR*AverageTrueRange[NATR](close)

     

    Thanks
    Sachin
    #109443 quote
    Vonasi
    Moderator
    Master

    sulimaster – please always use the ‘Insert PRT Code’ button when putting code in your posts as it makes it far easier for others to read. I have tidied up your post for you! 🙂

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

How can I code ATR for position sizing and stops ?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
hendymk @hendymk Participant
Summary

This topic contains 5 replies,
has 5 voices, and was last updated by Vonasi
6 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/14/2018
Status: Active
Attachments: No files
Logo Logo
Loading...