Staying on market at least x bars

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

    Hello guys, here’s a function that closes the positions after x bars:

    IF OnMarket AND (BarIndex - TradeIndex) >=x THEN
    SELL      AT MARKET
    EXITSHORT AT MARKET
    ENDIF

    But what if i would like to implement a function that does not close the position for at least x bars? Then just after that x bars let the system works normally with sl/tp/ts etc…?

    Probably it’s more simple then i think, but i ask you for security.

    #135635 quote
    FrancescoFrancesco
    Participant
    Veteran

    Update: i managed to do that 🙂

    IF OnMarket AND (BarIndex - TradeIndex)<=x THEN
    set stop %loss 0
    ENDIF
    

    Yes, that was simple as i thought

    #135646 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You will have to add an ELSE condition to set the SL after those X bars.

    Francesco thanked this post
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

Staying on market at least x bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/11/2020
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...