pine-script

How to plot the result from highest defining the number of bars with barssince

自作多情 提交于 2020-06-18 04:48:12
问题 Try to plot the value of the highest bars between current bar and the last cross of ema(50) and ema(200) using barssince(cross(ema50,ema200)) . The function highest() wants an integer and the Barssince gives a series integer . All variants getting the error that pine connot compile with error: line 4: Cannot call `highest` with arguments (series[integer]); available overloads: highest(series, integer) => series; highest(integer) => series Script. //@version=3 study("My Script") o = 0 o :=

How to plot the result from highest defining the number of bars with barssince

蓝咒 提交于 2020-06-18 04:47:10
问题 Try to plot the value of the highest bars between current bar and the last cross of ema(50) and ema(200) using barssince(cross(ema50,ema200)) . The function highest() wants an integer and the Barssince gives a series integer . All variants getting the error that pine connot compile with error: line 4: Cannot call `highest` with arguments (series[integer]); available overloads: highest(series, integer) => series; highest(integer) => series Script. //@version=3 study("My Script") o = 0 o :=

Highest high “of the last n days”, not “n days ago”

眉间皱痕 提交于 2020-06-18 02:52:47
问题 If I want to compare the close of today with the high of the last 4 days, what is the format? I have used _hi = close > high[4] ? 1 : 0 But that only counts the high 4 days ago, not the days in between. I have tried _hi = close > high[1,2,3,4] ? 1 : 0 Error message 回答1: You can use highest() for that purpose. highest(source, length) → series You need to be careful though. close > highest(close, 4) can never be true . Because, if the current bar's close price is the highest among those 4 bars,

How to code a user-configurable session indicator that draw a LINE (i.e. time/range bound)

时光总嘲笑我的痴心妄想 提交于 2020-06-17 16:24:34
问题 I started with a question on how to programmatically draw a time/range based box/rectangle to frame a trading session, but came to the realization that Pine is not capable of doing so... However, I understand Pine v4 introduces the ability to draw line objects and wonder if anyone can point me in the right direction for code to draw session lines instead. By that I mean hi & Lo for the start/end time specified (i.e. highest & lowest value for the time period) would be much appreciated? I am

How to code a user-configurable session indicator that draw a LINE (i.e. time/range bound)

被刻印的时光 ゝ 提交于 2020-06-17 16:24:34
问题 I started with a question on how to programmatically draw a time/range based box/rectangle to frame a trading session, but came to the realization that Pine is not capable of doing so... However, I understand Pine v4 introduces the ability to draw line objects and wonder if anyone can point me in the right direction for code to draw session lines instead. By that I mean hi & Lo for the start/end time specified (i.e. highest & lowest value for the time period) would be much appreciated? I am

function returning 2 values to global variable

故事扮演 提交于 2020-06-17 10:26:24
问题 In light of this post I'd like to ask why the script hereunder works for [a,b] but doesn't work for [c,d] . Cannot find any documentation that explains why this doesn't work. This example is only for 2 return values, but in reality I'm going to create a function with 6 or more variables to be returned in one go. I'm trying to avoid having to enter 6 different lines, because I'll be entering this data every trading day (the function will be date-depentent and I already have code for that). So

Timezone convertion between tickers (part 3)

烈酒焚心 提交于 2020-06-09 05:38:04
问题 As mentioned in the answer to Timezone convertion between tickers by Dennis T, we can use the security() function to get the time in another timezone. Now I was trying to get times from 2 different timezones. Ticker CL1! trades on Nymex in New York, in timezone UTC-4 . Ticker ES1! trades on CME in Chicago, in timezone UTC-5 . We can see that from the symbol info In order to visualize that time difference, I've created a small script that plots the time in both timezones. //@version=4 study(

Plotting custom data - daily = ok, weekly = not ok

流过昼夜 提交于 2020-05-24 05:13:48
问题 This is my example script //@version=4 study("", overlay=true) // Colors C_FORECAST_HIGH = color.red C_FORECAST_LOW = color.red C_FORECAST_CLOSE = color.blue C_ERROR_HIGH = color.yellow C_ERROR_LOW = color.yellow C_ERROR_CLOSE = color.lime // Plot styles P_STYLE_FORECAST = plot.style_line // } // ————— Hide the connection line when we plot horizontal levels // When plotting with plot.style_line or plot.style_linebr, lines are normally connected. // We are plotting the levels as horizontal

Tradingview Pine Script adding % stop loss

陌路散爱 提交于 2020-05-17 06:46:06
问题 enter image description hereIm trying to make a strategy that buys at the 55 day high and sells at the 20 day low. The probles is that i want to add a stoploss. The stoploss needs to be at 5 procent from the entry. This is what i already tried. //@version=4 strategy("Turtle Project",overlay= true) entry_long_2 = input(55, title="entry_long_2_input" ,minval=2) profit_long_2 = input(20, title="profit_long_2_input",minval=1) cond_L_2 = float(na) cond_L_2:= if high[entry_long_2] >= highest(high

(non)persistance of VAR initializations in functions

风流意气都作罢 提交于 2020-05-16 06:59:08
问题 This is a follow-up to my previous question Plotting custom data - daily = ok, weekly = not ok. The comments on the accepted answer suggests that the state of a var inside a function is persisted throughout successive calls to that function. This proved to be correct, because removing the var solved my problem. However, I now have a test case that seems to prove the opposite. In the script below, variable b seems NOT to be persisted. Function f2() has to be called on every bar in order to