1 short and 1 long per day max

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

    Hi, is there a way to limit 1 short trade or 1 long trade per day?

    I know that it is possible to code a strategy by limiting it to 1 trade per day by using and playing around with the “barindex” functions.

    But I specifically only need the strategy to perform a maximum of 1 short trade per day or 1 long trade per day (so in total maximum 2 trades per day),
    and I can’t figure out how to do it, is it possible to do it somehow?

    thanks in advance for the help

    #229458 quote
    robertogozzi
    Moderator
    Master

    There you go:

    MaxTrades = 1
    IF IntraDayBarIndex = 0 THEN
       LongTally  = 0
       ShortTally = 0
    ENDIF
    IF myLongConditions  AND LongTally < MaxTrades THEN
       BUY 1 Contract at Market
       LongTally = LongTally + 1
    ENDIF
    IF myShortConditions AND ShortTally < MaxTrades THEN
       SELLSHORT 1 Contract at Market
       ShortTally = ShortTally + 1
    ENDIF

    you may set MaxTrades to 2, to allow 2 trades for each direction, etc…

    #229679 quote
    Tropic
    Participant
    New

    thx Roberto this should work fine.

    #229688 quote
    justisan
    Participant
    Junior

    hi, I found it also very useful to use below functions, especially if one triggers entries not “at market” but with “stop” (or “limit”):

    if longtriggered = 1 then…

    if shorttriggered = 1 then…

    cheers

    justisan

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

1 short and 1 long per day max


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Tropic @tropic Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by justisan
1 year, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/08/2024
Status: Active
Attachments: No files
Logo Logo
Loading...