pine-script

Correct usage of strategy.order

亡梦爱人 提交于 2021-01-29 16:50:22
问题 I am trying to use strategy.order for shorts in order to have 3 take profit levels (level 1 lowest TP and Level 3 highest TP) and execute when my stop loss is reached to exit the remaining position. if (strategy.position_size >= 0 and high[1] < close) strategy.entry(id="EnterShort", long=false, qty = 1) shortHighEntery := close shortHighEnteryStoppLoss :=high +1 else shortHighEntery := shortHighEntery[1] shortHighEnteryStoppLoss :=shortHighEnteryStoppLoss[1] exitShort = shortHighEntery *0.995

Updating values or creating a new series

孤街醉人 提交于 2021-01-29 15:18:49
问题 This script is developed to generate waves with cumulative volume according to the specified conditions. On the last bars, there are cases when conditions do not determine which wave is formed up or down. This is accepted as a fact and we agree to wait for the next bars to form. After new bars determine the direction of the wave, the previous bars should be added as the beginning of this new wave. It was assumed that the fulfillment of the conditions for the formation of a wave will be stored

TradingView Alerrt Message Question - (alertcondition custom message question)

强颜欢笑 提交于 2021-01-29 14:22:33
问题 I am hoping someone help me.I know this is probably really simple, but I couldn't figure it out. In a pivots script , it has the user can input the pivot type: pivotType = input(title="Pivot Type", options=["Daily", "Intraday", "Weekly"], defval="Daily") In the alert message, I want it to state the pivot type hit when the alert goes off. I want the message to say "Daily Pivot level hit", or "Weekly Pivot level hit". I tried the following below, but it didn't appear to work.: alertcondition

Cannot use a mutable variable as an argument of the security function

浪子不回头ぞ 提交于 2021-01-29 12:21:48
问题 The script below does not compile. It throws the error Cannot use a mutable variable as an argument of the security function I don't understand why. The arguments I use in the security function are not mutable variables. When I comment out the line h := h * 3 , the script compiles ok. Does anybody know what's going on here? Could this be a Pine script bug? //@version=4 study("My Script") [h, l, c] = security(syminfo.ticker, "D", [high,low,close], lookahead = barmerge.lookahead_on) // actual

Calculating standard deviation of last N elements of in a pine series

☆樱花仙子☆ 提交于 2021-01-29 11:39:11
问题 Try to calculate the standard deviation of last 5 elements of a series below is the implementation I copied from TradingView official's ADX implementation //@version=4 study(title="DMI movement out of 2SD in last 10 points", shorttitle="StrategyX", format=format.price, precision=4, resolution="") lensig = input(14, title="ADX Smoothing", minval=1, maxval=50) len = input(14, minval=1, title="DI Length") up = change(high) down = -change(low) plusDM = na(up) ? na : (up > down and up > 0 ? up : 0

How to access the last indicator values

老子叫甜甜 提交于 2021-01-29 10:01:15
问题 I've got an indicator which shows pivot points: //@version=4 study("Trend", overlay=false) leftBars = input(3) rightBars = input(3) ph = pivothigh(high, leftBars, rightBars) pl = pivotlow(low, leftBars, rightBars) How can I check if the last ph was higher than the ph before? (I'd like to check for an uptrend or downtrend) 回答1: You can try the following code (including your original, as you see): //@version=4 study("Trend", overlay=false) leftBars = input(3) rightBars = input(3) ph = pivothigh

Plotting within a Loop, Cannot use 'plot' in local scope. (TradingView Pine Script)

心已入冬 提交于 2021-01-29 08:21:56
问题 I am having trouble figuring out the proper implementation while trying to clean up my code and I found a section that seemed ripe for a For-loop, however, I receive the following error: Cannot use 'plot' in local scope. When trying to do the following example: a = 10 b = 5 for i = 1 to b j = a * i plot(highest(j), title="Resistance", color=b, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true) My original code is as follows: a=10 plot(highest(a*1), title="Resistance"

Pinescript: Recursively delete lines if price crosses above/below them

久未见 提交于 2021-01-29 07:03:47
问题 Overview I have created a script that identifies fractals If a fractal is identified a line is created and extended to the right If price passes above/below the y1 value of the line then the line gets deleted Problem - inconsistent behaviour/errors Script works for FX:CADJPY on Daily timeframe: Picture of working example Tradingview says "Too many drawings, cannot delete the oldest" if I move to H4 timeframe on same instrument: Picture of error1 Tradingview says "Internal server study error"

How to check if the candle is the largest one in Pine-Script?

做~自己de王妃 提交于 2021-01-29 06:54:20
问题 I wanna to make pine script code to check is that candle the largest one of the previous 50 candles and color it yellow i tried hard ,but i can't 回答1: You could use: r = high - low barcolor(rising(r,50) ? color.yellow : na) 来源: https://stackoverflow.com/questions/62582115/how-to-check-if-the-candle-is-the-largest-one-in-pine-script

Is it possible to draw a line into the future?

蹲街弑〆低调 提交于 2021-01-28 17:53:42
问题 For intraday timeframes. Is it possible to draw a horizontal line on the first bar of the session, that has a length until the end of that session? So, essentially drawing a line into the 'future'. Something like this: 回答1: It seems to be possible. Code below is based on the answer of PineCoders-LucF to one of my previous questions line.new draws 2 lines instead of 1 //@version=4 study("FutureLine", overlay=true) start = timestamp(2020,03,13,10,30,0) stop = timestamp(2020,03,16,16,00,0) level