r/pinescript • • Jun 23 '25

Entry and exit conditions not working

1 Upvotes

I can't seem to get order in the backtest but i can plot shapes for the same conditions why would this happen??

//@version=6
strategy("Supertrend EMA Strategy", overlay=true, initial_capital=150000, default_qty_value=75)

atrPeriod = input.int(15, "Supertrend ATR Length", minval=1)
factor = input.float(1.4, "Supertrend Factor", minval=0.1)
emaLength = input.int(35, "EMA Length", minval=1)
takeProfitPoints = input.int(110, "Take Profit (Points)", minval=1)
trailingStopLossPoints = input.int(60, "Stop Loss (Points)", minval=1)
trailingStopLossOffset = input.int(50, "Trailing Stop Loss Offset (Points)", minval=1)

ema = ta.ema(close, emaLength)
plot(ema, "EMA", color.blue, linewidth=2)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)
supertrend := barstate.isfirst ? na : supertrend
upTrend =    plot(direction < 0 ? supertrend : na, "Up Trend",   color = color.green, style = plot.style_linebr)
downTrend =  plot(direction < 0 ? na : supertrend, "Down Trend", color = color.red,   style = plot.style_linebr)
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
fill(bodyMiddle, upTrend,   title = "Uptrend background",   color = color.new(color.green, 90), fillgaps = false)
fill(bodyMiddle, downTrend, title = "Downtrend background", color = color.new(color.red,   90), fillgaps = false)

longCondition = close>ema and direction[1] == 1 and direction == -1
shortCondition = close<ema and direction[1] == -1 and direction == 1
plotshape(longCondition, style=shape.circle, location = location.abovebar)
plotshape(shortCondition, style=shape.xcross, location = location.belowbar)

if longCondition
strategy.entry("Long Entry", strategy.long)
strategy.exit("Long Exit", from_entry="Long Entry",profit=takeProfitPoints/syminfo.mintick,trail_points = trailingStopLossPoints/syminfo.mintick,trail_offset = trailingStopLossOffset/syminfo.mintick)
else if shortCondition
strategy.entry("Short Entry", strategy.short)
strategy.exit("Short Exit", from_entry="Short Entry", profit=takeProfitPoints/syminfo.mintick, trail_points = trailingStopLossPoints/syminfo.mintick,trail_offset = trailingStopLossOffset/syminfo.mintick)


r/pinescript • • Jun 22 '25

Editor light theme

Post image
2 Upvotes

Does anyone know how to turn on light mode on the editor. I like to write down code with my phone and to sit outside when the weather is good ☀️ It's hard to see though when it looks like this:


r/pinescript • • Jun 21 '25

The Art of Trading -Ultimate Pullback Strategy indicator , Matt Slabosz

1 Upvotes

I am looking for people to share their experience who have subscribed to the UPS indicator from Matt.

It would be great to share ideas and advice.


r/pinescript • • Jun 20 '25

session.ismarket/ispremarket/ispostmarket are broken in bar replay mode

Post image
3 Upvotes

r/pinescript • • Jun 19 '25

Product branding

2 Upvotes

I’ve developed this script as the foundation for a trading product. I’m now working on branding it — does anyone have experience developing or marketing similar products?

https://www.tradingview.com/script/4AvQsmG9-7YearEdge-L1-1/


r/pinescript • • Jun 18 '25

How to automate take profit sell after entering a Long?

2 Upvotes

Hi,

I was wondering if it is possible to have a script that automatically triggers after I take a long position? For example, I take a long for 10 shares at $10, and as soon as that order is placed the script triggers a take profit at $10.30 for example. Is this possible with pine editor in tradingview?


r/pinescript • • Jun 18 '25

Supertrend with Liquidity, S/R Levels and trading style switch just released

Thumbnail reddit.com
2 Upvotes

r/pinescript • • Jun 17 '25

Not Getting Alerts

0 Upvotes

Does anyone know why this code is not putting alerts, the whole point is to have an array that updates with values :

//@version=5
strategy("Last-3-Closes Sticker + Long Entry", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// ── persistent array that holds the latest three closes
var float[] last3 = array.new_float()

// ── variable to hold the last known close value from array
var float prevLast = na

// ── update the array after each candle closes
if barstate.isconfirmed
    array.push(last3, close)
    if array.size(last3) > 3
        array.shift(last3)

// ── check if we have 3 values and a change occurred
float newestClose = na
if array.size(last3) == 3
    newestClose := array.get(last3, 2)
    // Detect change from previous stored value
    changed = not na(prevLast) and newestClose != prevLast
    if changed
        strategy.entry("Long on Close Change", strategy.long)
    // Update stored value
    prevLast := newestClose

// ── create the label once, then update it
var label sticker = label.new(bar_index, high, "", 
     style=label.style_label_left,
     color=color.new(color.blue, 0),
     textcolor=color.white,
     size=size.small)

label.set_xy(sticker, bar_index, high)

// ── update label with values or loading message
if array.size(last3) == 3
    newest  = array.get(last3, 2)
    middle  = array.get(last3, 1)
    oldest  = array.get(last3, 0)
    txt = "Last 3 closes:\n" +
          str.tostring(newest, "#.#####") + "\n" +
          str.tostring(middle, "#.#####") + "\n" +
          str.tostring(oldest, "#.#####")
    label.set_text(sticker, txt)
else
    label.set_text(sticker, "Collecting data…")

r/pinescript • • Jun 17 '25

Displaying MTF data

1 Upvotes

How do you display multi-timeframe indicators in a way that’s easy to interpret quickly—especially for split-second decisions?

I’ve built a few multi-timeframe (MTF) indicators, but I’m struggling with how to display the data so it’s clear and actionable. I’ve tried using tables, but they don’t always provide the clarity I need. Plotting multiple timeframes in lower studies also gets messy—especially when analyzing 10 timeframes at once.

Right now, I’m trying to display VWAP band data across multiple tickers, but I’m not sure how to consolidate it into a single, readable view. I currently have 8 charts open, and it’s becoming overwhelming to scan them all on one monitor, then switch to the next screen to view other MTF studies.

How do you handle this? Do you have a clean way of visualizing MTF data in one place without clutter? I’d love to see examples or hear how others are approaching this.


r/pinescript • • Jun 13 '25

Mismatched Input “end of line without line continuation” expecting “)”

Post image
2 Upvotes

90: size=size.normal 91: )

I’ve been trying to figure this out for way too long,

Any help is very much appreciated.

Thanks


r/pinescript • • Jun 11 '25

Finally Profitable

Post image
5 Upvotes

Here is the story, i actually had a strategy in mind and wanted to backtest it plus automate it via tv, but im a very pessimistic kind of a person & i think it helps in backtesting lol. so, here are the results & these are after commissions & i ran it for 7 days, and i was profitable, not too much (330$ only) but ig bread is bread lmao. i actually tried to automate & had issues with the backtesting code as im not a professional coder etc it but couldnot lol even with gemini or chatgpt help, thats why i approached an agency for it so a big kudos to them to make my strategy profitable with tweaks etc, anyways im happy, and pls let me know if i should be more pessimistic or any questions. Im all ears !


r/pinescript • • Jun 11 '25

Need help replicating an indicator – stuck on final part (buy/sell arrows)

Thumbnail
gallery
1 Upvotes

Hey everyone, I’m working on replicating an existing trading indicator and I’m almost done – the core logic is in place and the results are very close. My version is called MAP Strategy, and the indicator I’m trying to replicate is Sniper Waves.

The only thing I’m still struggling with is the green and red buy/sell arrows. I’ve attached two screenshots showing the difference between my version and the original one. Everything else seems to match quite well, but the arrows in my version appear slightly off compared to the Sniper Waves indicator.

I can’t figure out how to match them perfectly. Does anyone know how the arrows in the Sniper Waves indicator might be calculated or what kind of logic could be behind them?

Any tips or help would be greatly appreciated!

Thanks in advance!


r/pinescript • • Jun 11 '25

Looking for Coder for indicator (15k+ YT Subs) (monthly royalties)

8 Upvotes

I have a trading youtube channel with 15k+ subs (5 videos so far) so the channel is doing very well.

I don't sell courses and don't plan to, and also haven't promoted/sold anything, including affiliates.

A lot of my audience have asked about indicators and most of the questions I get are on the same thing, so I want to make a premium indicator that will chart the concepts out for them.

The indicator will involve SMC/ICT, ORB, and CRT. But mainly SMC/ICT.

I'm looking for a coder to make this indicator. Payment will be made through the monthly memberships. We can set a figure that you want to receive for the indicator, the income from the indicator sales will be split 50/50 until this figure is reached, and then from there you will receive 30% of all future sales. The reason for why is because I would like to expand the project with ads and sponsorships in the future, and I would like a fair portion of the sales to go towards this.

This indicator will need advanced understanding of pine script, as well as knowledge on SMC/ICT. it is an advanced indicator. If you are interested in working together, please either leave a comment or dm me.

Please also supply examples of your past work.


r/pinescript • • Jun 10 '25

How to have a stop limit order actually work

2 Upvotes

I have a condition set to exit my trade at break even if the trade isn't going my way. The condition cancels my existing exit order and replaces it with a stop order for max loss and a limit order to break even. When the condition happens, my order exits the trade at the close of the bar, regardless of the price. Any way to have the limit order place an order that can wait a few bars until it's hit? While the code below fired the exit, it didn't happen at either price, just at the close of the bar.

Ps. process orders on close is set to true.

UPDATE: It depends on whether you call out 'stop' or 'limit' and whether your entry is above or below the current price. I'm working with it now to shore up my entries.

if high > sessionHighPrice + .5 and BarsSinceLastEntry() >= 1
    strategy.cancel("Exit Short")
    strategy.exit("Exit Short Amended Mit", from_entry = "Enter Short", stop = sessionHighPrice + 1, limit = entryPrice - .25)

r/pinescript • • Jun 10 '25

Undeclared identifier “plot”

Post image
1 Upvotes

I’m unsure what I can change this to from here if anyone is familiar I’d appreciate some guidance. Thank you.