Exit position once a condition happens twice

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #124100 quote
    eckaw
    Participant
    Veteran

    Hi all,

    Is it possible to code an exit code that would exit a position once a certain condition is met the second time around?

    The exit condition I’m trying to achieve is when CDC ATR Trailing Stop v2.1 indicator turns red the second time around (on long positions) and turns green the second time around (on short positions). So it would not exit the position the first time the CDC ATR Trailing Stop v2.1 changes color.

    How would one go about coding this? Please see attached screenshot.

    Thanks in advance.

    Screenshot-2020-03-31-at-15.30.31.png Screenshot-2020-03-31-at-15.30.31.png
    #124103 quote
    Vonasi
    Moderator
    Master

    Simply set a flag.

    if your entry conditions then 
    buy 1 contract at market
    flag = 0 
    endif
    
    if longonmarket and (my exit condition happens) then
    flag = flag + 1
    endif
    
    if longonmarket and flag = 2 then
    sell at market
    flag = 0
    endif
    
    
    eckaw thanked this post
    #124141 quote
    GraHal
    Participant
    Master

    Above added as Log 204 here …

    Snippet Link Library

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

Exit position once a condition happens twice


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
eckaw @eckaw Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by GraHal
5 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/31/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...