Trailing Stop Loss from High

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #102783 quote
    WhiteWolf
    Participant
    New

    Hi All,

    Apologies if this has been asked before but I have searched the forums and couldn’t find how to do this. I am still a beginner at this but really enjoying it.

    I am trying to code a trailing stop loss which is a multiple of ATR from the last high since being in the market (i.e. Tradeprice). Once the close goes through this level then sell at next open.

    I thought using the Barindex-tradeindex like in code below was correct but sometimes it just sells the next day from purchase even if the move was in a profitable position.

    CURRENT CODE:

    if longonmarket and Close < ((Highest[Barindex-TradeIndex](High))-SL) then
    sell at market
    endif
    

    The SL is= ATR*3

    Really scratching my head at this so any help would be greatly appreciated.

    Thanks a million.

    #102785 quote
    Vonasi
    Moderator
    Master

    WhiteWolf – Welcome to the forums.

    The ‘General Trading Discussions’ forum is for….. well general trading discussions. Your question is automatic trading strategy coding related and so should be in the ProOrder forum. I have moved it – please try to post in the most relevant forum with future posts.

    #102786 quote
    Vonasi
    Moderator
    Master

    Try changing HIGH to HIGH[1] because close will more than likely always be less than the current high unless it is equal to it!

    WhiteWolf thanked this post
    #103430 quote
    WhiteWolf
    Participant
    New

    Apologies and thanks for your help.

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

Trailing Stop Loss from High


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
WhiteWolf @whitewolf Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by WhiteWolf
6 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/17/2019
Status: Active
Attachments: No files
Logo Logo
Loading...