How to offset an alert on pine editor (TradingView) - offset

I need some help to offset my alert by 1
I'm able to offset the arrow (plotted) but I can't figure out how to offset the actual alert so it comes on the next candle (so the cross is confirmed)
tavg = tos == 1 ? avg(a,avg) : avg(b,avg)
tavgi = tosi == 1 ? avg(ai,avgi) : avg(bi,avgi)
enterLong = crossover(tavgi, tavg)
enterShort = crossunder(tavgi, tavg)
alertcondition(enterLong, title='Long', message='long tradesymbol=EURUSD')
alertcondition(enterShort, title='Short', message='short tradesymbol=EURUSD')
How to add an offset=1 to enterLong and enterShort
I tried
enterLong = crossover(tavgi, tavg)
barcolor(color=enterLong ? blue : na, offset=1)
alertcondition(condition=enterLong,
message="long tradesymbol=EURUSD")
enterShort = crossunder(tavgi, tavg)
barcolor(color=enterShort ? orange : na, offset=1)
alertcondition(condition=enterShort,
message="short tradesymbol=EURUSD")
but it obviously only offset only the barcolor not the alert :(
Sorry I can't put the whole code but if you have an idea it would be highly appreciated thanks

This can be done via the history operator [], checking the condition on the previous bar:
alertcondition(enterLong[1], title='Long', message='long tradesymbol=EURUSD')
alertcondition(enterShort[1], title='Short', message='short tradesymbol=EURUSD')

Related

Historical Camarilla Levels

I've got a simple historical camarilla indicator that I'm mostly happy with, save for one detail. My horizontal lines are plotted from 9:30 until 9:30 the next day, except on the Friday to Monday transition. I don't really understand why this happens. So what I'd like is for the lines to start from 7:00 to 18:00 every day, in order to align with price action in the pre/post market. I'm not very good at pinescript, and I can't seem to find a solution. Is this even possible using 'plot', or should I be using 'line.new'? Any help would be greatly appreciated. The script I have is as follows;
//#version=5
indicator('Camarilla Levels', overlay=true)
// User inputs
showHistoricalCams = input(title='Show Historical Cam Pivots', defval=true)
//Camarilla Calculations
tR3 = close + (high - low) * 1.1 / 4.0
tS3 = close - (high - low) * 1.1 / 4.0
tR4 = close + (high - low) * 1.1 / 2.0
tS4 = close - (high - low) * 1.1 / 2.0
//Pivot Range
_tR4 = request.security(syminfo.tickerid, 'D', tR4)
_tR3 = request.security(syminfo.tickerid, 'D', tR3)
_tS3 = request.security(syminfo.tickerid, 'D', tS3)
_tS4 = request.security(syminfo.tickerid, 'D', tS4)
//Plot Historical Cam
plot(showHistoricalCam ? _tR3 : na, title=' R3', color=_tR3 != _tR3[1] ?
#eeeeee00 : #ff000080, style=plot.style_line, linewidth=1)
plot(showHistoricalCam ? _tR4 : na, title=' R4', color=_tR4 != _tR4[1] ?
#eeeeee00 : #ff000080, style=plot.style_line, linewidth=1)
plot(showHistoricalCam ? _tS3 : na, title=' S3', color=_tS3 != _tS3[1] ?
#eeeeee00 : #008000FF, style=plot.style_line, linewidth=1)
plot(showHistoricalCam ? _tS4 : na, title=' S4', color=_tS4 != _tS4[1] ?
#eeeeee00 : #008000FF, style=plot.style_line, linewidth=1)
**The lines are plotted this way to remove the 'connecting' lines
I've tried setting time parameters, but can't make the script work.

Pine script - using buy limit/sell limit is not firing at an exact price

I am trying to enter using a buy limit order at an exact price using pine script eg. 146.090 but even though the price has gone under and over it - it still does not execute.
I do not want to use close/high/low etc, just the exact price.
It would be greatly appreciated if somebody had a workaround for the issue.
Thx.
//#version=5
VERSION = "V1"
SCRIPT_NAME = "Test " + VERSION
InitCapital = 100000
InitPosition = 100.0
InitCommission = 0.025
InitPyramidMax = 1
CalcOnorderFills = false
ProcessOrdersOnClose = true
CalcOnEveryTick = true
CloseEntriesRule = "FIFO"
strategy(title=SCRIPT_NAME, shorttitle=SCRIPT_NAME, overlay=true, pyramiding=InitPyramidMax, initial_capital=InitCapital, default_qty_type=strategy.fixed, process_orders_on_close=ProcessOrdersOnClose, default_qty_value=InitPosition, commission_type=strategy.commission.percent, calc_on_order_fills=CalcOnorderFills, calc_on_every_tick=CalcOnEveryTick, precision=9, max_lines_count=500, max_labels_count=500, commission_value=InitCommission)
var float entry = 145.606
strategy.entry("Long", strategy.long, limit=entry)
Try to replace :
strategy.entry("Long", strategy.long, limit=entry)
By :
strategy.entry("Long", strategy.long, limit=entry, close=entry)

I would like to change candle colors using the offset function with a variable/conditional offset time

Version 5.0. iff_17 determines whether my conditions are met. It then sets the candlecolor and the offset time (pasttime) which is either -4 or 0. However, it seems that pasttime is not recognized as a numerical value (also using int pasttime = iff_17 == 2 ? -4 : 0) does not work Help would be greatly appreciated. Thanks
iff_17 = va1 == 1 and ((_hh or _lh) or (_hl or _ll)) ? 2 : 0
candleColor2 = iff_17 == 2 ? candleColor1 : candleColor
pasttime = iff_17 == 2 ? -4 : 0
barcolor(candleColor2, offset = pasttime)

Pine Script - Tradingview Draw a daily rectangle

I'm working on a TradingView script (Pine) and I would to develop a simply script that draw a rectangle from a start of current day to the end based on my current timeframe from Monday To Friday...
Example: First rectangle drawed from 24/03/2021 to 25/03/2021, Second Rectangle drawed from 25/03/2021 to 26/03/2021, etc...
Any solutions to achieve this result?
Thank's in advance
I think I have understood your request. The below should help assist you
//#version=4
study("Daily Box", overlay=true)
Bottom = input(title="Bottom", type=input.session, defval="0000-2359:1234567")
colourcheck = 1.0
boxheight = input(title="Box Height", type=input.float, defval=3)
DailyHigh = security(syminfo.tickerid, "D", high, lookahead=true)
DailyLow = security(syminfo.tickerid, "D", low, lookahead=true)
dayrange = DailyHigh - DailyLow
BottomLowBox = DailyLow + (dayrange * 0.01 * boxheight)
TopLowBox = DailyHigh - (dayrange * 0.01 * boxheight)
BarInSession(sess) => time(timeframe.period, sess) != 0
//ASIA
BottomL = plot(DailyLow and BarInSession(Bottom) ? DailyLow : na, title="Bottom High", style=plot.style_linebr, linewidth=3, color=na)
TopL = plot(DailyHigh and BarInSession(Bottom) ? DailyHigh : na, title="Bottom Low", style=plot.style_linebr, linewidth=3, color=na)
fill(BottomL, TopL, color=color.purple, title="Fill Box", transp=50)

Script for indicating order history - Tradeview Pine

I want to indicate historical trades in tradingview charts via a script based on information on time and price for entry and close.
My best idea is to search through "time" to find matches for entry and close, and then change the background color according to short or long position or draw a horizontal line. However, this seems not optimal. Any suggestions?
I'd implement that in the next way:
//#version=3
strategy("Background changing", overlay=true)
NONE = 0
LONG = 1000
SHORT = -1000
position = NONE
position := nz(position[1], NONE)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("LongEntryId", strategy.long)
position := LONG
if (close < high[1])
strategy.close("LongEntryId")
position := NONE
getColor(state) =>
state == LONG ? green :
state == SHORT ? red :
white
bgcolor(color=getColor(position))
Or you can put arrows to the chart:
//#version=3
study("My Script", overlay=true)
order = 0
if time >= timestamp(2018, 1, 10, 0, 0)
order := 1
if time == timestamp(2018, 1, 17, 0, 0)
order := -1
plotarrow(order)