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
    ThallyThally
    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
    VonasiVonasi
    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
    ThallyThally
    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 ThallyThally
7 years, 1 month ago.

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