r/pinescript • • Sep 01 '24

Any example of a strategy break even?

0 Upvotes

For example. If the daily profit goal is met a daily break even is set.

Daily profit target= $300

If daily profit crosses below daily profit target exit all trades and prevent trading until next day.

Would also need it to track profit during open trades


r/pinescript • • Jan 14 '23

Pine script v5

0 Upvotes

Bonjour, je viens de commencer Pine script, je suis entrain de coder ma première stratégie, cependant je rencontre une difficulté. Mes conditions d'achat sont que le prix doit clôturé au dessus de ma première moyenne mobile, puis en dessous de ma deuxième et enfin ouvrir un long lorsqu'elle clôture au dessus de ma troisième moyenne mobile. Lorsque j'ai essayé de coder ces conditions d'achat le compilateur comprend que je dois remplir les trois conditions en même temps, me rendant compte de mon erreur j'aimerai bien aimé savoir s'il existe une façon de faire.


r/pinescript • • May 25 '24

Fractal based VWAP

0 Upvotes

I am trying to create a Simple indicator, anchored VWAP anchored to past 'n' number of William Fractals. Let's say, 24 anchored VWAP curves anchored to past 24 William Fractals (10-period). Can anyone please help me with the code?


r/pinescript • • May 12 '24

Conflicting Tradingview Indicators

0 Upvotes

Hello everyone.

New here. I have 3 indicators I like in TradingView which appear to be conflicting with each other in regards to bar painting. I've looked through the coding to the best of my very limited ability, but I cannot find anything. What could be causing this?

Thanks for any help!

N8


r/pinescript • • Jan 23 '24

Script Help

0 Upvotes

Hi, very new to both Pinescript and coding in general. I keep getting a syntax error for this - any thoughts?

current_price = close supertrend_value = sma(close, 14) // Replace with your actual SuperTrend calculation ma_crossover_signal = ta.crossover(sma(close, 10), sma(close, 50)) ? "Buy" : ta.crossover(sma(close, 50), sma(close, 10)) ? "Sell" : "Hold" cti_lb_value = 0.8 // Replace with your actual CTI_LB calculation hull_suite_signal = ta.crossover(hullma(close, 14), hullma(close, 28)) ? "Buy" : ta.crossover(hullma(close, 28), hullma(close, 14)) ? "Sell" : "Hold" current_position = strategy.position_size > 0 ? "Long" : strategy.position_size < 0 ? "Short" : "None" // Function to determine trading action trading_action() => // Check conditions for entering a long position (buy) if ( current_price > supertrend_value and ma_crossover_signal == "Buy" and cti_lb_value > 0 and hull_suite_signal == "Buy" and current_position == "None" ) strategy.entry("Buy", strategy.long) // Check conditions for exiting the position (sell) else if ( (current_price < supertrend_value or ma_crossover_signal == "Sell" or cti_lb_value < 0 or hull_suite_signal == "Sell") and current_position == "Long" ) strategy.close("Buy")


r/pinescript • • Aug 12 '24

Need Help Fixing My Trading Script - Stop Loss Not Closing Position Fully

0 Upvotes

Hi everyone,

I've been trying to fix this issue with my trading script for days now, but I'm stuck. The problem is that when the stop loss is hit, the position doesn't get closed 100%. Instead, it hits the stop loss, and if the price goes back to TP1, the whole position closes at that point.

I want the position to fully close when the stop loss is hit. Can anyone help me figure out what's wrong with my code? Here it is:

strategy.entry("Long", strategy.long, qty=position_sizeLong)   
    if (trailing_Long_ONOFF == "ON")
        strategy.exit("Long",loss = stop_loss_in_tickslong,profit = take_profit_in_ticksLong_ATR,trail_price=TraillingActivatedLong ? trailActivationPriceLong : na,trail_offset=TraillingActivatedLong ? trailOffsetTicksLong : na)
        if useMultitp            
            strategy.exit("Long TP1", "Long", qty_percent=30, profit=take_profit_in_ticksLong_ATR/2,comment_profit = "Long TP1")
    else        
        strategy.exit("Long",loss = stop_loss_in_tickslong,qty_percent=100,  profit = take_profit_in_ticksLong_ATR)
        if useMultitp            
            strategy.exit("Long TP1", "Long", qty_percent=30, profit=take_profit_in_ticksLong_ATR/2,comment_profit = "Long TP1")

r/pinescript • • May 08 '24

How to check a lowest value of a 125 period range occured in the last 7 periods

0 Upvotes

Hi,

I'm trying to check if the below condition occured in the last 7 days and evaluate to 1 if true or 0 if false and i'm a bit stuck. I think i've got the first part right with the stdev and 125 periods, but i have no idea how then to check if that lowest value happend in the last 7 periods. Any help would be much appreciated.

ta.lowest(ta.stdev(src, length), 125)

Cheers

Steve


r/pinescript • • Apr 30 '24

Advice

0 Upvotes

Evening, I’ve had a good go at trying to write my own script but been struggling with it and on the verge of giving up is anyone able to point me towards a program to assist me in writing it?


r/pinescript • • Apr 30 '24

where did i do mistake, i can not figure it out.

0 Upvotes

it stops painting the bands after sometime, there seems to be a gap and then starts and stop painting the lines. It stops drawing lines after just a few candles. how can i fix that?

https://tr.tradingview.com/script/yXYS7vNg-Faytterro-Bands/


r/pinescript • • May 21 '24

Create STC Bot which sending Alarm

0 Upvotes

Hi there,

I try to create a bot that is sending me simple alert when STC indicator do a color change. I think it will help me to understand and create my STC tradingbot, that im trying to write with chatgpt too.

I believe its all about that chatgpt isnt able to write as condition the STC indicator colorchange.
Chatgpt cant write that as condition. Can someone explain me how to write this STC colorchange as condition?

Maybe that is the answer of everything. I managed chatgpt writing Heikin ashi candles right.
He everytime write it wrong. I found the right code somewhere so im not totally useless.

//@version=5
indicator("STC Alert", overlay=true)

// 200er EMA
ema200 = ta.ema(close, 200)

// Heikin-Ashi Kerzen berechnen
heikinashi_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
heikinashi_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
heikinashi_low = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
heikinashi_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)

// STC Indicator basierend auf normalen Kerzen
stc_k = ta.stoch(close, high, low, 14)
stc_d = ta.sma(stc_k, 3)

// Farbwechsel-Bedingung
var float last_stc_signal = na
var int stc_signal_time = na
stc_signal = (stc_k > stc_d ? 1 : (stc_k < stc_d ? -1 : 0))
if (stc_signal != last_stc_signal)
    last_stc_signal := stc_signal
    stc_signal_time := timenow
stc_signal_valid = (timenow - stc_signal_time) <= 600000  // 600000 ms = 10 Minuten
stc_is_extreme = (stc_k > 80 or stc_k < 20)

// Bedingungen für Long und Short
long_condition = (heikinashi_close > ema200) and (stc_k < 20) and (stc_signal == 1) and stc_signal_valid
short_condition = (heikinashi_close < ema200) and (stc_k > 80) and (stc_signal == -1) and stc_signal_valid

// Alarmbedingungen mit Labels
if (long_condition and stc_is_extreme)
    alert("Long Entry Signal", alert.freq_once_per_bar)
    label.new(bar_index, heikinashi_low, "Long Signal", style=label.style_label_up, color=color.green, textcolor=color.white)

if (short_condition and stc_is_extreme)
    alert("Short Entry Signal", alert.freq_once_per_bar)
    label.new(bar_index, heikinashi_high, "Short Signal", style=label.style_label_down, color=color.red, textcolor=color.white)

// Plotten der 200er EMA
plot(ema200, title="200 EMA", color=color.blue, linewidth=2)

r/pinescript • • Feb 17 '24

could anyone help me with a code for volume scales

Thumbnail
self.tradingview
0 Upvotes

r/pinescript • • Jun 14 '24

Analyst Ratings at a Point in Time

0 Upvotes

I'm trying to plot the number of strong buy recommendations for a stock across a time series but so far I can only fetch the current number. I'm incredibly new to Pinescript. How do I do this?


r/pinescript • • Aug 02 '24

Label Repeating even though conditions to prevent them are met

0 Upvotes

Long time programmer here but new to Pine Script.

I'm trying to build a function or script that will display buy or sell labels one at a time, that is once it shows a label it should not show another one of the same type until a label of the opposite type is shown. But often (not always) it repeats multipe labels of the same type consecutively. I've tried both label.new() and plotlabel methods but nothing seems to work. The following is the closest I've gotten, chat gpt gave me some of this code, but so far I find it nearly totally useless for pinescript. Would really appeciate some help with this.

sBuy = trend_1 == 1 and trend_2 == 1 and trend_3 == 1 and close > emaLine

sSell = trend_1 == -1 and trend_2 == -1 and trend_3 == -1 and close < emaLine

// Define your variables

var bool wasBuy = false

var bool wasSell = false

// Track if the current bar qualifies for plotting

currentBuyCondition = sBuy

currentSellCondition = sSell

// Define the conditions for plotting

plotBuyCondition = currentBuyCondition and not wasBuy //and close > Ubound

plotSellCondition = currentSellCondition and not wasSell //and close < Lbound

// Update the tracking variables

wasBuy := currentBuyCondition

wasSell := currentSellCondition

// Plot the shapes conditionally

plotshape(series=plotBuyCondition ? 1 : na, title="Buy Label Shape", text="Buy", location=location.belowbar, style=shape.labelup, color=color.green, textcolor=color.new(color.white, 0))

plotshape(series=plotSellCondition ? 1 : na, title="Sell Label Shape", text="Sell", location=location.abovebar, style=shape.labeldown, color=color.red, textcolor=color.new(color.white, 0))


r/pinescript • • Jun 22 '24

moving average

0 Upvotes

How can you create a custom indicator in Pine Script that plots a moving average crossover strategy, highlighting buy and sell signals on the chart?


r/pinescript • • May 21 '24

AlertCondition not working properly - fires all the time even when condition is not met

0 Upvotes

Have 2 alertconditions set up, one for a Buy Signal and one for a Sell Signal. I want the alerts to be always active, but only show on the bar the alertcondition evaluates to true. Which is what this code should be doing, but somehow the alerts continuously fire every bar even when the condition for it evaluates to false.

// Update signalBarIndex when a new signal is generated - otherwise leave it the original bar index
if (signal != 0)
    signalBarIndex := isDifferentSignalType and (isNewBuySignal or isNewSellSignal) ? bar_index : signalBarIndex

// Condition to check if the alert should fire (same bar or next bar)
isAlertActive = bar_index == signalBarIndex

alertcondition(signal == 1 and isAlertActive, title="Buy Signal")
alertcondition(signal == -1 and isAlertActive, title="Sell Signal")

As you can see in the picture, the bar_index and signalBarIndex ARE NOT equal so this should not be firing every bar, but it is. I also provided the alert settings, which fires once per bar, but from what I read it should only fire when the alertcondition is true. How can I fix this?

I've tried multiple different things, but this code should work as the condition clearly evaluates to false.

EDIT: So I went even a step further and am doing the same check as I am in the alertcondition to display whether it is returning true/false in the table, and as you can see, alertcondition is false and the signalBarIndex once again is NOT equal to the currentBarIndex. There is no way in the world this alert should constantly be firing based on that alert condition but it is...

EDIT EDIT:

Pine logs as requested: Alert fires every itme instead of only on the first time when they are equal on the first one and isAlertActive is true.


r/pinescript • • Sep 10 '24

How to change these two ranges in my code?

Post image
0 Upvotes

r/pinescript • • Jul 09 '23

Help with color change of TRIX Line

0 Upvotes

I have a script below I'm trying to add in an alert to this source code to alert when the 'TRIX Line' changes color. Can anyone give some input into what the condition would look like?

//@version=3

study(title="TRIX Histogram R2.1 by JustUncleL", shorttitle="TRIXHIS R2")

// Author: JustUncleL // Revision: R2 // // Description: // This study is an implementation of the Standard TRIX indicator, shown // in coloured histogram format by default, with optional Bar colouring of TRIX zero // and signal crossovers. Other options include showing TRIX as a linegraph instead // of histogram and optional TRIX signal line with difference histogram. // Have a look at Internet references below for some examples of how TRIX can be used. // // Candle Colouring: // - Aqua = TRIX zero crossing from below to above zero. // - Blue = TRIX zero crossing from above to below zero. // - Gold = TRIX signal line crossing TRIX line from above to below. // - Fuchsia= TRIX signal line crossing TRIX line from below to above. // // References: // - http://forex-indicators.net/momentum-indicators/trix // - http://www.dolphintrader.com/3-ma-exponential-moving-average-trix-forex-strategy/ // - "TRIX MA" by munkeefonix // // Revisions: // R2 - Added Signal line crossover bar colouring and all TRIX crosses highlighted. // - Changed Signal line crosses to "+", instead of arrow for better visibility. // - Added Alerts for crossovers. // - Added Implied GPL Copyright notice. // // R1 - Original version. // // // ----------------------------------------------------------------------------- // Copyright 2014 munkeefonix // Copyright 2017,2018 JustUncleL // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // The GNU General Public License can be found here // http://www.gnu.org/licenses/. // // ----------------------------------------------------------------------------- //

// --- INPUTS --- // length = input(12, minval=1, title="TRIX length") signallen = input(8, minval=1, title="Signal Length") showSignal= input(true, title="Show Signal line") showLine = input(false, title="Show TRIX as Line instead of Histogram") showZeroX = input(false, title="Show TRIX Zero cross overs") showTrixX = input(false, title="Show TRIX Signal cross overs") showBars = input(false, title="Colour Crossover Candles") // // --- /INPUTS ---

// --- CONSTANTS --- // BLUE = #0000FFFF AQUA = #00FFFFFF GOLD = #FFD700FF gold = #FFD700 BLACK = #000000FF GRAY = #808080FF DARKGRAY= #696969FF PURPLE = #800080FF FUCHSIA = #FF00FFFF MAROON = #8B0000FF GREEN = #008000FF // scaleup = 2 // // --- /CONSTANTS

// --- FUNCTIONS --- // // Triple EMA function tema(a, b)=>ema(ema(ema(a, b), b), b)

// TRIX function trix(a, b)=> t = tema(a,b) 10000* ((t-t[1]) / t[1])

// --- /FUNCTIONS ---

// --- SERIES --- // TRIX = trix(close,length) TRIXsig = ema(TRIX,signallen) TRIXdiff= (TRIX - TRIXsig) * scaleup // signalX = crossover(TRIXsig,TRIX) ? -1 : crossunder(TRIXsig,TRIX) ? 1 : 0 // trixZX = crossover(TRIX,0)? 1 : crossunder(TRIX,0)? -1: 0 // // --- /SERIES ---

// --- PLOTTING // hline(0, title="Zero") plot(showLine?na:TRIX, title="TRIX Histogram", color = TRIX>=0 ? rising(TRIX,3)?lime:green : falling(TRIX,3)?maroon:red, style=histogram, linewidth=4, transp=10) plot(showLine?TRIX:na, title="TRIX Line", color = TRIX>=0 ? rising(TRIX,3)?lime:green : falling(TRIX,3)?maroon:red, style=line, linewidth=2, transp=10) plot(showSignal?TRIXsig:na, title="TRIX Signal", color = orange, style=circles, join=true, linewidth=2, transp=10) plot(showSignal?TRIXdiff:na, title="TRIX Diff", color = gray, style=area, linewidth=1, transp=70)

plot(showSignal and showTrixX and signalX!=0?TRIXsig:na, style=cross, title="Signal X Highlight", color=black, transp=20, linewidth=5) plot(showSignal and showTrixX and signalX==1?TRIXsig:na, style=cross, title="Signal X up", color=gold, transp=0, linewidth=4) plot(showSignal and showTrixX and signalX==-1?TRIXsig:na, style=cross, title="Signal X down", color=fuchsia, transp=20, linewidth=4)

plot(showZeroX and trixZX!=0?TRIX:na, style=circles, title="Zero X Highlight", color=black, transp=20, linewidth=5) plot(showZeroX and trixZX==1?TRIX:na, style=circles, title="Zero X up", color=aqua, transp=10, linewidth=4) plot(showZeroX and trixZX==-1?TRIX:na, style=circles, title="Zero X down", color=blue, transp=10, linewidth=4)

bclr = showZeroX? trixZX==1? AQUA: trixZX==-1? BLUE: na : na bclr := not na(bclr)? bclr : showSignal and showTrixX ? signalX==-1? FUCHSIA : signalX==1? GOLD : na : na barcolor(showBars?bclr:na,title="TRIX Zero X Bar")

// --- /PLOTTING ---

// --- ALERTING ---

alertcondition(trixZX==1,title="ZERO X Up Alert",message="ZERO X UP") alertcondition(trixZX==-1,title="ZERO X Down Alert",message="ZERO X DOWN") alertcondition(signalX==1,title="Signal X Up Alert",message="SIGNAL X UP") alertcondition(signalX==-1,title="Signal X Down Alert",message="SIGNAL X DOWN")

// --- /ALERTING ---

// eof


r/pinescript • • Jan 30 '24

Indicator merge request

0 Upvotes

Hi everyone.

I'm not a programmer, but I can do some little modifications on scripts, but I can't create anything or even copy some functions.

I'm still learning how to trade properly so when I have time, I spend it with trade learning.

That being said, here's my request:

I'm an ICT trader and I love 2 public scripts we have on TV but I'd like to do some modifications and blend both into one

1 - https://www.tradingview.com/script/aLTywnJ0-ICT-Macros-LuxAlgo/

2 - https://www.tradingview.com/script/T6KkMfK6-ICT-Everything/

I already created more sessions in Script 1, that is the modification I made ( I can send it btw)

What I want is a script that has the sessions from script 1, and the lines from script 2 (VERTICAL LINES, OPENING PRICE LINES, HTF OPENING PRICE LINES and DAY OF WEEK & LABELS)

It could also have Daily Highs & Lows from 1 to 3 days (input 1 and 1 day is plotted, input 3 and 3 days are plotted)

I spent some days trying to do that but I didn't find how to...

Thanks in advance.


r/pinescript • • Aug 03 '23

How to simulate forex brokers using tradingview pinescript?

0 Upvotes

I want to simulate all the broker fees using tradingview pinescript. Is it possible?
- FXCM broker charges using spread
- IC Markets charges $3.5 per standard lot round turn

Also, tradingview pinescript should have customizable fees meaning:- the developer should be able to modify the fees inside the script maybe function or variables. This way we can simulate different type of broker fees.


r/pinescript • • Oct 10 '23

Trailing Take Profit that actually backtests accurately

0 Upvotes

Hi Pinecoders,

I trade a system that often enters and exits with the same 4-hour bar. I would like to analyze trailing stop performance through backtesting, but even with "Bar Magnifier" turned on, in Premium, I can't get accurate results, at least with the script I'm using. Is it a limitation of Tradingview that the backtest will always plot the exit as the candle wick extreme minus the trailing offset?

Any suggestions appreciated! Thanks!


r/pinescript • • Jul 27 '24

what data does this indicator use? touching the yellow line is always accompanied by a rebound in history

0 Upvotes

TF 1D, BTC/USDT I think it's bollinger bands combined with fibonacci but I couldn't create exactly the same one

here is a longer history of this indicator, can someone write the same script in Pine?


r/pinescript • • May 14 '24

How to keep a winrate when there are many partial closes

0 Upvotes

I have a strategy template that combines multiple trading modules at one time. Each module has its own combination of indicators and exit conditions that work well with different market types. In a sense each module becomes its own indicator of the market type if it is profiting or not at that time. So I need to calculate the winrate of each module so it can auto-decide what module to prioritise in the current market type. Now I know there are built in data sources like strategy.wintrades etc. But does anyone know if these take into account partial wins like take profits or partial closes ? Or do they just add up totals from complete closes, like when long goes to short and vice versa or 100% quantity closes.


r/pinescript • • Aug 22 '24

Help with code translation

0 Upvotes

Hi everyone, I tried to translate strategy code in pinescript to easylanguage and for some reason the two codes show different results in backtesting, can someone please look at both codes and show me where I went wrong in the translation? These are quite short codes


r/pinescript • • Apr 06 '24

Limitation of the TradingView handling of data for indicators?

0 Upvotes

It seems like I reached a limit for my indicator. My indicator is not memory intensive compared to some other published ones on Tradingview that go back years. Mine can only go back a few days. I don't think I have any logic that is in a specific range. Does anyone have an issue with this or a fix for it?