Coding Help needed – delay new trade after one closes

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #245359 quote
    OggyFluff77
    Participant
    New

    good afternoon all,

    i need some coding help please.

    i would like to add a parameter to the below code which defines how many bars to wait before re-entering a trade – assuming the conditions to trade are still being met.

    code is not finalised but being built out bit by bit. will be using 1m bars

    // Conditions for Entry of Long Positions
    IF CLOSE<EMA(20) AND NOT ONMARKET THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP $LOSS StopLoss
    ELSIF SHORTONMARKET AND (CLOSE-TRADEPRICE)  THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP $LOSS StopLoss
    ENDIF

    Hope it makes sense

    thanks in advance

    #245378 quote
    Iván González
    Moderator
    Master

    Hi. You could add something like this:

    // this will control how many bars your system is not onmarket
    if not onmarket then
    barsOut=barsOut+1
    else
    barsOut=0
    endif
    
    // You have to define how many bars (X) waiting out of market
    if not onmarket and yourconditions and barsOut>x then
    buy 1 contract at market
    endif
    robertogozzi and OggyFluff77 thanked this post
    #245404 quote
    OggyFluff77
    Participant
    New

    many thanks Ivan, the code works perfectly.

    thanks for your help, much appreciated

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

Coding Help needed – delay new trade after one closes


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by OggyFluff77
10 months, 3 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/27/2025
Status: Active
Attachments: No files
Logo Logo
Loading...