only open a 2nd position if the 1st one was a loser?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #104757 quote
    Thally
    Participant
    Average

    Hi all,

    Ive encountered a problem for which I cannot find a solution in the manual or in previous forum posts. If I have a strategy that can only open a maximum of 2 trades per day. How would you stop the 2nd position from being opened if the 1st trade was a winner? I.e. I only want to open the 2nd trade if the 1st attempt was unsuccessful.

    I have tried using the

    POSITIONPERF(1)

    function but I don’t think that works because what happens to the very 1st trade of the strategy – i.e. when there is no previous trade to reference?

    Thanks

    Roj

    #104760 quote
    Vonasi
    Moderator
    Master

    Compare STRATEGYPROFIT to STRATEGYPROFIT from the bar before and if it is more then set a flag to not trade. At the end of the day reset the flag.

    Something like this:

    if time = 000000 then
    inprofit = 0
    tradecount = 0
    endif
    
    if strategyprofit > strategyprofit[1] then
    inprofit = 1
    endif
    
    if (your entry conditions) and not inprofit and tradecount < 2 then
    buy 1 contract at market
    tradecount = tradecount + 1
    endif
    Thally thanked this post
    #104765 quote
    Thally
    Participant
    Average

    Thank you Vonsai. That works a treat. Very smart solution!

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

only open a 2nd position if the 1st one was a loser?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Thally @rodger_dodger Participant
Summary

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

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