Skip or paus trading signal until X happens

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #241862 quote
    Vicke1990Vicke1990
    Participant
    New

    Hi fellow traders and programmers,

    I have an issue that I would really appreciate some help with, and if possible hopefully resolve.

    I want my algo to skip/ paus/ ignore all long OR short signals or
    If I have 2 consecutive losses in the same direction, and dont trade the same direction again until after a trade the opposite direction has occurred or until after a certain time-period.

    Is this at all possible?

    Thank you so much,

    With kind regards,
    Victor

    #241871 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    In your sentence “I want my algo to skip/ paus/ ignore all long OR short signals or

    What is missing after the last OR?

    #241904 quote
    Vicke1990Vicke1990
    Participant
    New

    In your sentence “I want my algo to skip/ paus/ ignore all long OR short signals or

    What is missing after the last OR?

    Hi Robertoogozzi,

    Sorry, the last OR is wrong.

    Kind regards, Victor

    #241949 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    ONCE LONGlosses  = 0
    ONCE SHORTlosses = 0
    ONCE TradeLONG   = 1
    ONCE TradeSHORT  = 1
    ONCE Nbars       = 20    //Number of bars (time) after which trading in a directuion is resumed
    ONCE BARtally    = 0
    // when a direction is disabled, increment the BAR count, till it reaches Nbars to reenable that direction
    IF (TradeLONG = 0) OR (TradeSHORT = 0) THEN
       BARtally = BARtally + 1
       IF BARtally >= Nbars THEN
          TradeLONG  = 1
          TradeSHORT = 1
          BARtally   = 0
       ENDIF
    ENDIF
    IF (StrategyProfit < StrategyProfit[1]) THEN
       // in case of a LOSS, increment the counter to tell when there are 2 consecutive losses in the same direction
       IF LongOnMarket[1] THEN
          LONGlosses  = LONGlosses + 1
          SHORTlosses = 0
          IF LONGlosses  = 2 THEN
             TradeLONG   = 0
             BARtally    = 0
          ENDIF
       ELSIF ShortOnMarket[1] THEN
          SHORTlosses = SHORTlosses + 1
          LONGlosses  = 0
          IF SHORTlosses = 2 THEN
             TradeSHORT  = 0
             BARtally    = 0
          ENDIF
       ENDIF
    ELSIF (StrategyProfit > StrategyProfit[1]) THEN
       // in case of a WINNING trade, clear the consecutive LOSS count for both directions
       LONGlosses  = 0
       SHORTlosses = 0
    ENDIF
    // LONG  positions
    IF Not OnMarket AND (close CROSSES OVER  average[20,0](close)) AND TradeLONG  THEN
       BUY 1 Contract at Market
       TradeSHORT  = 1
    ENDIF
    // SHORT positions
    IF Not OnMarket AND (close CROSSES UNDER average[20,0](close)) AND TradeSHORT THEN
       SELLSHORT 1 Contract at Market
       TradeLONG   = 1
    ENDIF
    // SL & TP
    SET STOP   %LOSS   1
    SET TARGET %PROFIT 2
    //     debugging aids
    //graph LONGlosses  coloured("Blue")
    //graph SHORTlosses coloured("Red")
    //graph BARtally    coloured("Fuchsia")
    //graph TradeLONG
    //graph TradeSHORT
    Iván González and Vicke1990 thanked this post
    #242120 quote
    Vicke1990Vicke1990
    Participant
    New

    Thank you so much for your help robertogozzi 🙂

    robertogozzi thanked this post
Viewing 5 posts - 1 through 5 (of 5 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

Skip or paus trading signal until X happens


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vicke1990 @vicke1990 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Vicke1990Vicke1990
1 year, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/28/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...