I am long and I want to sell if it has been more than 12 hours and I a

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #263029 quote
    kvacksa87
    Participant
    Junior

    if I’m long I want to sell if it’s been more than 12 hours since I placed the order only if I’m in the red and then I want to sell if it reaches the middle of the Bollinger bands on the 4 hour graph

    #263033 quote
    turame
    Participant
    Master

    Hello,

    Try this.I didn’t tested it.

    mm20=average[20] (close) //bollinger middle
    
    IF barindex-tradeindex(1) >= 12 and close < tradePrice then
     sell at mm20 limit
    endif
    
    Iván González and kvacksa87 thanked this post
    #263034 quote
    Iván González
    Moderator
    Legend

    Hi. Let’s see if this helps.

    DEFPARAM CumulateOrders = False
    
    // --- Settings ---
    bbPeriod   = 20   // Bollinger period (middle band = SMA of that period)
    barsFor12h = 12   // bars = 12h ON YOUR CHART TF (15m->48, 30m->24, 1h->12, 4h->3)
    
    // --- 4H Bollinger middle band, no repainting ---
    TIMEFRAME(4 hours, updateonclose)
    midBB = average[bbPeriod](close)
    TIMEFRAME(default)
    
    // --- DEMO ENTRY: replace with your own entry logic ---
    IF NOT LongOnMarket AND close CROSSES OVER average[50](close) THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // --- Bars elapsed since the entry (0 when flat) ---
    IF LongOnMarket THEN
       barsInTrade = barindex - tradeindex
    ELSE
       barsInTrade = 0
    ENDIF
    
    // --- Exit 1: 12h in the trade and still in the red ---
    IF LongOnMarket AND barsInTrade >= barsFor12h AND close < positionprice THEN
       SELL AT MARKET
    ENDIF
    
    // --- Exit 2: price reaches the 4H middle band ---
    IF LongOnMarket AND close crosses under midBB THEN
       SELL AT MARKET
    ENDIF
    
    // --- Graph ---
    GRAPH barsInTrade AS "bars in trade"
    GRAPHONPRICE midBB AS "4H BB middle"
    
    


    kvacksa87 and robertogozzi thanked this post
    #263036 quote
    kvacksa87
    Participant
    Junior

    thank you both for the quick replies, I’ll test the codes as soon as I get time

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

I am long and I want to sell if it has been more than 12 hours and I a


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kvacksa87 @kvacksa87 Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by kvacksa87
4 days, 4 hours ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/30/2026
Status: Active
Attachments: No files
Logo Logo
Loading...