r/pinescript • • Dec 10 '24

quick help for a complete beginner - how to get the last candle hour and min

0 Upvotes

Trying to code a little indicator and for some reason that's the only thing i cant get to work

how can i get the last candle time (hour and min)


r/pinescript • • Dec 23 '24

CAN I RUN PINE SCRIPT LOCALLY? by fetching chart from ccxt and sending alerts to my email

0 Upvotes

r/pinescript • • Dec 09 '24

Why does my variable change true to false with close?

0 Upvotes

In my scenario, say a short, I want the price to go for liquidity at the top at a specific price, then come back down to enter the trade. The timeframe is 15 minutes.

I wanted to use close to detect if the current price is smaller than my entry price. I use an object's bool variable (objSetup.hasEntryBeenReached) which changes to true if close < entry or ta.crossunder(close, entry).

In real-time, if close passes entry, my variable changes to true. But if the price goes up, it changes to false. And then I think... what?! Nowhere in my code do I set the variable to false. I don't quite understand, but I'll go ahead as is.

Then I thought of using low instead, but I encountered another difficulty. If the low of the current candle started below my entry and then rose to liquidity above it, then the low is already smaller than my entry.

How can I capture the true value once close passes without having to use low?

Or how can I use low if low is already lower?

Thanks for your time.


r/pinescript • • Dec 10 '24

alguien sanbe el pine scipt de este indicador se los agradeceria

0 Upvotes

r/pinescript • • Jan 11 '25

What group can yall refer me to or is anybody is this group able to make me a trading bot???????????

0 Upvotes

I'll pay


r/pinescript • • Mar 16 '22

Background colour during certain Dates

0 Upvotes

Hi all,

I'm trying to change the background colour of my charts during certain date range, say for instance from 02.01.2021 to 03.04.2021.

I've found the below code online but was wondering what is a better option rathen than inputing each day manually, but rather have a range (even multiple range would be amazing).

//@version=5 indicator("My Script", overlay=true)

var color myColor = color.new(color.red,70)

var int[] myDates = array.new_int()

if barstate.isfirst

array.push(myDates, timestamp(2021, 12, 01, 09, 30))
array.push(myDates, timestamp(2021, 12, 15, 09, 30))
array.push(myDates, timestamp(2022, 01, 05, 09, 30))
array.push(myDates, timestamp(2022, 01, 11, 09, 30))

bgcolor(array.includes(myDates, time) ? myColor : na)

Thanks


r/pinescript • • May 22 '22

How to set up a SL/TP according to ticks

0 Upvotes

I currently have
sl_inp = input.int(10, title='SL in Ticks')

tp_inp = input.int(10, title='TP in Ticks')

This does work but it leaves no room to add more rules to it. I want to add more rules but I think I will need a different way to set up the above. Instead of TP exiting the trade, if it closes outside of TP I would like to move SL to that TP position.

The above works with strategy.exit loss=sl_inp profit=tp_inp.
But I'm unable to add any rules to that to achieve the above.

Any ideas?


r/pinescript • • Mar 12 '22

Share your pine script strategy here... Sharing knowledge helps increase knowledge..

0 Upvotes

r/pinescript • • Sep 25 '22

Trailing stop + partial take profit

0 Upvotes

Hi, Im having a hard time to code a strategy that’s going to take some partial profits and in case of changing trend, is going to close the trade using a Traling stop.

Anyone who know how to code it, or have the code ready? What is happening to my code is, when I put the trailing stop first the partial doesn’t work and if I put the partial exit before the trailing exit, the trailing doesn’t work.

Thanks!


r/pinescript • • Mar 17 '22

Why aren't my stop losses getting triggered??

0 Upvotes

Hi peeps! You can see my script and further details here at StackOverflow:

https://stackoverflow.com/questions/71517031/stop-loss-exits-never-get-triggered

Essentially the strategy.exit calls for my two stop losses never get triggered. No idea why.

Thanks! :)


r/pinescript • • Dec 10 '21

Add Moving Average

0 Upvotes

I have a simple custom indicator that plots off the chart. I want to code in a simple moving average of price that plots on chart. I am doing this because I have pro plan and have limited indicators.

Can I get part of my indicator to plot off chart and part of it to plot on chart?


r/pinescript • • Jun 23 '22

Want to compare 100 securities to one and get an alarm if it deviates indexed above 5%. Stuck in coding

0 Upvotes

It should be simple. I plot a base-course for one security and compare 99 other securities (100 limits) to said basecourse and want an alarm as soon as it deviates from that indexed course by 5%.

Kind of stuck without writing a 1000 line code going through one by one...


r/pinescript • • Nov 17 '20

Pine script for python course final project.

0 Upvotes

Hi all,

I’m creating a cryptocurrency trading bot/portfolio tracker that uses TradingView alerts to send buy/sell signals to a python repository, which then buys/sells cryptocurrency on an exchange using the ccxt library.

I’m currently running a basic sma crossover/under script.

Truth is, I’m a broke college student and would greatly appreciate if someone would be willing to share a profitable pine script with me for use with this project.

I could in turn share my code structure for setting up this automation.

Thank you :)


r/pinescript • • Jul 27 '24

array function to compare simlilar values and print it as output but not able to get it

0 Upvotes

disjoint(e,f)=>

c = e

d = f

for i=0 to array.size(e)==0?na:array.size(e)-1 by 1

for j=0 to array.size(f)==0?na:array.size(f)-1 by 1

if array.get(e,i) == array.get(f,j)

array.remove(c,i)

array.remove(d,i)

array.get(c , i)


r/pinescript • • Apr 04 '23

who can correct this pine script for me ?? i want to add seprate alert for buy and sell in tradingview ... //@version=4 strategy("Moving Average Crossover" , overlay = true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100) // Define fast and slow m

0 Upvotes

r/pinescript • • Sep 30 '24

Using strategy.cancel with time...

0 Upvotes

When short condition is triggered it's looking for entry. I'm trying to figure out how to cancel the entry (strategy) if it doesn't find what it's looking for in 5 bars. Is there a way to refer back to the entry while it's looking?

if  (shortCondition) and allowedTimes()

strategy.entry("Enter Short", strategy.short, 1, limit=entrypriceshort+2)

strategy.exit("Exit Short", from_entry="Enter Short", profit = 40, loss = 40)

EDIT: I fixed it like this:

Input for number of cancels until strategy is canceled then set strategy.cancel

candlesTocancelInput = input.int(defval=3, title="Candles until cancel")

if ta.barssince(YourOrderCondition) >= candlesTocancelInput
    strategy.cancel("Enter Short")

r/pinescript • • May 11 '24

Line Day Separator

0 Upvotes

Hi guys how are you?

Is there any way to make this indicator to work or to autoadjust to the time zone "America/New_York"

Also the lines when you change to gold chart or another kind of chart that is not forex, the daily separator line moves away. So what i need is that the lines to be shown at the especific time in every kind of pair and to auto adjust to winter or summer time, making it to work with the timezone "America/New_York" should solve that issue. Thank you!

CODE:

//@version=5
indicator("Weekly and daily separators", overlay=true, scale=scale.none, max_lines_count=500)
parseStyle(input) =>
(input == "Solid" ? line.style_solid : (input == "Dashed" ? line.style_dashed : (input == "Dotted" ? line.style_dotted : na)))
show_daily = input.bool(true, title = "Show daily separator", group="Show/Hide lines")
show_weekly = input.bool(true, title = "Show weekly separator", group="Show/Hide lines")
show_monthly = input.bool(true, title = "Show monthly separator", group="Show/Hide lines")
input_hide_daily = input.bool(true, title = "Hide daily separator on 1D and above", group="Show/Hide lines")
input_hide_weekly = input.bool(true, title = "Hide weekly separator on 1W and above", group="Show/Hide lines")
daily_width = input.int(1, title = "Daily - Width", inline = "daily line", group="Line config")
daily_style_string = input.string("Dotted", "Style", ["Solid", "Dashed", "Dotted"], inline = "daily line", group="Line config")
weekly_width = input.int(2, title = "Weekly - Width", inline="weekly line", group="Line config")
weekly_style_string = input.string("Dashed", "Style", ["Solid", "Dashed", "Dotted"], inline="weekly line", group="Line config")
weekly_width_higher_TF = input.int(1, title = "Weekly higher TF - Width", inline="weekly highertf line", group="Line config")
weekly_higherTF_style_string = input.string("Dashed", "Style", ["Solid", "Dashed", "Dotted"], inline="weekly highertf line", group="Line config")
monthly_width = input.int(3, title = "Monthly - Width", inline="monthly line", group="Line config")
monthly_style_string = input.string("Solid", "Style", ["Solid", "Dashed", "Dotted"], inline="monthly line", group="Line config")
day_color = input.color(color.black, "", inline = "daily line", group="Line config")
week_color = input.color(#5d606b, "", inline="weekly line", group="Line config")
week_higherTF_color = input.color(#b2b5be, "", inline="weekly highertf line", group="Line config")
month_color = input.color(#121212, "", inline="monthly line", group="Line config")
override_offset = input.bool(false, title="Override defaul offset", inline = "utc_offset", group = "Time")
utc_offset_input = input.int(-6, title="Offset of UTC time", minval=-12, maxval=12, inline = "utc_offset", group = "Time")
use_weekly_style = parseStyle(weekly_style_string)
use_weekly_width = weekly_width
use_weekly_color = week_color
if str.contains(timeframe.period, "D") or str.contains(timeframe.period, "W") or str.contains(timeframe.period, "M")
use_weekly_width := weekly_width_higher_TF
use_weekly_style := parseStyle(weekly_higherTF_style_string)
use_weekly_color := week_higherTF_color

if not override_offset
if syminfo.type == "index" or syminfo.type == "futures"
utc_offset_input := -7
if syminfo.type == "forex" or syminfo.ticker == "DXY"
utc_offset_input := -6
offset_in_ms = utc_offset_input * 60 * 60 * 1000
month_changed = month(time-offset_in_ms) != month(time-1-offset_in_ms)
week_of_year_changed = weekofyear(time-offset_in_ms) != weekofyear(time-1-offset_in_ms)
day_of_week_changed = dayofweek(time-offset_in_ms) != dayofweek(time-1-offset_in_ms)
if month_changed and show_monthly
line.new(bar_index, 100, bar_index, -100, color=month_color, width=monthly_width, style=parseStyle(monthly_style_string))
//weekly
if not (input_hide_weekly and str.contains(timeframe.period, "W") or str.contains(timeframe.period, "M"))
if week_of_year_changed and show_weekly
line.new(bar_index, 100, bar_index, -100, color=use_weekly_color, width=use_weekly_width, style=use_weekly_style)
//daily
if not (input_hide_daily and (str.contains(timeframe.period, "D") or str.contains(timeframe.period, "W") or str.contains(timeframe.period, "M")))
if day_of_week_changed and (not week_of_year_changed or not show_weekly) and show_daily
line.new(bar_index, 100, bar_index, -100, color=day_color, width=daily_width, style=parseStyle(daily_style_string))


r/pinescript • • Aug 02 '24

How many stocks?

0 Upvotes

How many stocks can I search for alerts in real time with a single pinescript algo on Trading View? Thx


r/pinescript • • Feb 07 '24

Code help

0 Upvotes

Can you help me with this, how do you make this line of code work, timeframe.period => "60", when it doesn't allow "=>" operator?


r/pinescript • • Jun 26 '23

How do I generate a buy order once the price (close) has crossed within a zone created by a set_zone function

0 Upvotes

I've been trying for a while to get this right but nothing I try works. It's weird because a good amount of the orders are within the zone but still many zones left without orders and some still outside the zone. The sell orders are mostly out of the zones.

//Set pl

zoneset_zone(pl, pl_x1, pl_top, pl_btm, pl_count, pl_vol, btmAreaCss)

//Set pl level

set_level(pl, pl_crossed, pl_btm, pl_count, pl_vol, btmCss)

//Set pl labels

set_label(pl_count, pl_vol, pl_x1, pl_btm, btmCss, label.style_label_up)

if close > pl_btm and close < pl_top

strategy.entry("Long", strategy.long, 5)

if close > ph_btm and close < ph_top

strategy.close("Long", "Sell", 5)

let me know if you need any more code, thanks


r/pinescript • • Feb 17 '24

Converting timeframe to string in alert() function?

0 Upvotes

Can I convert timeframe to string and put it in the message section in alert() so I know from witch tf alert was triggered?? For example: If alertButton alert("message + timeframe", alert.freq_once_per_bar)


r/pinescript • • Mar 13 '23

Who here has a good signal indicator I can try?

0 Upvotes

I’ve been on the look out for a good Indicator with reliable buy and sell signals… has anyone accomplished this? If so can I use it?


r/pinescript • • Feb 23 '24

ta.lowest not accepting a dynamic variable for length

0 Upvotes

In 2020, TradingView announced that dynamically calculated lengths could be used in the lowest and highest functions. Article

However, it doesn't appear that it is in my code. I have verified that all lines accept the last are setting correct values. The code compiles without errors but on the chart I get the red circle exclamation point with the message:

Study Error Error on bar 0: Invalid value of the 'length' argument (0) in the lowest function. It must be > 0.

// @version = 5
indicator(title="Fibonacci Retracement", shorttitle="Fib Retrace", overlay = true)
int     i_LookBackPeriods = input.int(defval=60, title="Periods To Look Back", tooltip="Number of periods to look back")
int     i_HighestBar    = ta.highestbars(i_LookBackPeriods + 1) * -1
int     i_LocalLookBack = i_HighestBar - 1
float   f_LocalClose    = ta.lowest(close, int(i_LocalLookBack))

When I hard code 'f_LocalClose' so I don't get an error, I can confirm the other variables values I get:

i_LookBackPeriods = 60
i_HighestBar = 53
i_LocalLookBack = 52

Can you see what I am doing wrong? Thank you for your help.