Avoiding re-entering the market after target met

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #35836 quote
    Mashndivho
    Participant
    New

    I am struggling to code in order to avoid re-entering of trade once set profit target is met. For instance if I am long and set profit target is met, the code shouldn’t enter a new long trade although the conditions to go long is still true. Any help?

    #35840 quote
    Eric
    Participant
    Master

    Depends of the code, do you also have a sell conditon?

    i use sometimes a binary indicator buy = 1 and sell = -1 then i check if that indicator < 0 for buy

    #35849 quote
    Mashndivho
    Participant
    New

    Yes I do have sell condition as well

    #36172 quote
    AutoStrategist
    Participant
    Veteran

    It is taking another long position because the conditions you specified are still being met, if you don’t want it to take another position then you must change the long entry condition or refine it in some way.  What you haven’t stated is what you want the system to do after closing a long position, presumably you want it to be able to take another long position at some point?  You can tell e.g. to take another long position if the long entry conditions are met after so many bars since the close of the last trade or after a certain amount of  time has passed but you need to say what you want it to do.

    #36212 quote
    Mashndivho
    Participant
    New

    I would like the system to only take another long position after it had taken a short position, i.e. no 2 successive longs or shorts entries

    #36378 quote
    AutoStrategist
    Participant
    Veteran

    Assuming you have different conditions for entering longs and shorts then setting and testing a flag will do what you need, see example in attached code sample I used to test it.

    Defparam Cumulateorders = false
    
    LONG = 1
    SHORT = 2
    
    n = 1
    
    c1 =  close > Average[5](close)
    c2 = close < Average[3](close)
    
    if not onmarket then
    
    if c1 and LastTrade <> LONG then
    BUY n SHARES AT MARKET
    LastTrade = LONG
    endif
    
    if c2 and LastTrade <> SHORT then
    sellshort n shares at market
    LastTrade = SHORT
    endif
    
    endif
    
    c3 =  close < Average[5](close)
    c4 = close > Average[3](close)
    
    if c3 then
    sell at market
    ENDIF
    
    if c4 then
    exitshort at market
    endif
    
    
    #36468 quote
    Mashndivho
    Participant
    New

    Thanks, i.t really helped. Exactly what I have been looking for.

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

Avoiding re-entering the market after target met


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
Mashndivho @mashndivho Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Mashndivho
8 years, 9 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 05/17/2017
Status: Active
Attachments: No files
Logo Logo
Loading...