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
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
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"
thank you both for the quick replies, I’ll test the codes as soon as I get time