0

i am newbie in this case, I use code from other and edit it When i setting alert in time frame 4h, the result is no sync with the list of trade , it may be same 5m time frame. i found it may be the Resolution input . i want alert same with the list of trade by time frame. how to do it? i set alert for BTC 4h, but alert can not show when list of trades and chart show the order
Look at Alert log, it not show same list of trade here is the code

//@version=5
// Original Author: @JayRogers
//Open Close Cross Strategy R5.1 revised by JustUncleL
//edit

strategy(title = "Open Close Cross Strategy R5.1 v5script", shorttitle = "OCC Strategy R5.1  v5script", overlay=true,initial_capital=100,default_qty_value=10,default_qty_type=strategy.percent_of_equity,commission_value=0.1,margin_long = 1./20*10, margin_short = 1./20*10,calc_on_order_fills=true,pyramiding=1)

// *** USE AT YOUR OWN RISK ***
// Change log my ver - ver1 - 
//1- Convert to V5 pine script
//2- Add Alert message  
//3- My default setting is best TP for 4h timeframe - BTC - backtest 1900 bar from Nov - 28 - 2022
// === INPUTS ===
useRes      = input(defval = true, title = "Use Alternate Resolution?")
intRes      = input(defval = 6,    title = "Multiplier for Alernate Resolution")
stratRes    = timeframe.ismonthly? str.tostring(str.tonumber(timeframe.period)*intRes,"###M") : timeframe.isweekly? str.tostring(str.tonumber(timeframe.period)*intRes,"###W") : timeframe.isdaily?  str.tostring(str.tonumber(timeframe.period)*intRes,"###D") : timeframe.isintraday ? str.tostring(str.tonumber(timeframe.period)*intRes,"####") : '60'
basisType   = input.string(defval = "TEMA", title = "MA Type: ", options = ["SMA", "EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMMA", "HullMA", "LSMA", "ALMA", "SSMA", "TMA"])
basisLen    = input(defval = 4, title = "MA Period")
offsetSigma = input(defval = 6, title = "Offset for LSMA / Sigma for ALMA")
offsetALMA  = input(defval = 0.85, title = "Offset for ALMA")
scolor      = input(false, title="Show coloured Bars to indicate Trend?")
delayOffset = input(defval = 0, title = "Delay Open/Close MA (Forces Non-Repainting)")
tradeType   = input.string("BOTH", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])

// === /INPUTS ===

// Constants colours that include fully non-transparent option.
green100 = #008000FF
lime100  = #00FF00FF
red100   = #FF0000FF
blue100  = #0000FFFF
aqua100  = #00FFFFFF
darkred100 = #8B0000FF
gray100 = #808080FF

// === BASE FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, offSig, offALMA) =>
    v1 = ta.sma(src, len)                                                  // Simple
    v2 = ta.ema(src, len)                                                  // Exponential
    v3 = 2 * v2 - ta.ema(v2, len)                                          // Double Exponential
    v4 = 3 * (v2 - ta.ema(v2, len)) + ta.ema(ta.ema(v2, len), len)               // Triple Exponential
    v5 = ta.wma(src, len)                                                  // Weighted
    v6 = ta.vwma(src, len)                                                 // Volume Weighted
    v7 = 0.0
    v7 := na(v7[1]) ? ta.sma(src, len) : (v7[1] * (len - 1) + src) / len    // Smoothed
    v8 = ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))   // Hull
    v9 = ta.linreg(src, len, offSig)                                       // Least Squares
    v10 = ta.alma(src, len, offALMA, offSig)                               // Arnaud Legoux
    v11 = ta.sma(v1,len)                                                   // Triangular (extreme smooth)
    // SuperSmoother filter
    // © 2013  John F. Ehlers
    a1 = math.exp(-1.414*3.14159 / len)
    b1 = 2*a1*math.cos(1.414*3.14159 / len)
    c2 = b1
    c3 = (-a1)*a1
    c1 = 1 - c2 - c3
    v12 = 0.0
    v12 := c1*(src + nz(src[1])) / 2 + c2*nz(v12[1]) + c3*nz(v12[2])
    type=="EMA"?v2 : type=="DEMA"?v3 : type=="TEMA"?v4 : type=="WMA"?v5 : type=="VWMA"?v6 : type=="SMMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : type=="ALMA"?v10 : type=="TMA"?v11: type=="SSMA"?v12: v1

// security wrapper for repeat calls
reso(exp, use, res) => use ? request.security(syminfo.tickerid, res, exp, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : exp

// === /BASE FUNCTIONS ===

// === SERIES SETUP ===
closeSeries     = variant(basisType, close[delayOffset], basisLen, offsetSigma, offsetALMA)
openSeries      = variant(basisType, open[delayOffset], basisLen, offsetSigma, offsetALMA)

// GetWinRate() returns the strategy's win rate (percentage
// of profitable trades). Set 'includeEvens' to 'true' to
// treat break-even trades as profitable setups too.
GetWinRate(includeEvens = false) =>
    winTradeCount = strategy.wintrades + 
         (includeEvens ? strategy.eventrades : 0)
    (winTradeCount / strategy.closedtrades) * 100
barTimeFormatted = str.format_time(time, 'dd-MM-yyyy HH:mm', "UTC+7")
// === /SERIES ===

// === /COMMENT ===
//Set find Price numbar SL Long / Short
InlowestClose = input(20,"Enter number bar Stop Loss Long",group = "Find Price numbar Long / Short Setting for Alert")
InhightClose = input(20,"Enter number bar Stop Loss Short",group = "Find Price numbar Long / Short Setting for Alert")
lowestClose = ta.lowest(low, InlowestClose)
hightClose = ta.highest(high, InhightClose)
//TP/SL target Long / Short
LTP1 = input(1.01,"TP1 Long - 1.01 is 1% from Enrty",group = "Take Profit Long / Short from Entry for Alert")
LTP2 = input(1.03,"TP2 Long - 1.03 is 3% from Entry",group = "Take Profit Long / Short from Entry for Alert")

STP1 = input(1.01,"TP1 Short - 1.01 is 1% from Enrty",group = "Take Profit Long / Short from Entry for Alert")
STP2 = input(1.03,"TP2 Short - 1.03 is 3% from Entry",group = "Take Profit Long / Short from Entry for Alert")

Longtakeprofit1 = open * LTP1
Longtakeprofit2 = open * LTP2
Shorttakeprofit1 = open-((open * STP1)-open)
Shorttakeprofit2 = open-((open * STP2)-open)

// Comment Long/ short
//CoEntryLo = "buy - Entry: " + str.tostring(close)+ "\n" + "TP1: " + str.tostring(Longtakeprofit1,"#.##") + " SL: " + str.tostring(lowestClose,"#.##") +" Winrate " + str.tostring(GetWinRate(),"00.0")+"%"+  " Time " + str.tostring(barTimeFormatted)
//CoEntrySh = "sell - Entry: " + str.tostring(close)+ "\n" + "TP1: " + str.tostring(Shorttakeprofit1,"#.##")+ " SL: " + str.tostring(hightClose,"#.##") +" Winrate " + str.tostring(GetWinRate(),"00.0")+"%"+  " Time " + str.tostring(barTimeFormatted)


// === PLOTTING ===

// Get Alternate resolution Series if selected.
closeSeriesAlt = reso(closeSeries, useRes, stratRes)
openSeriesAlt = reso(openSeries, useRes, stratRes)
//
trendColour = (closeSeriesAlt > openSeriesAlt) ? color.rgb(0,255,85,80) : color.rgb(229,10,10, 75)
bcolour     = (closeSeries > openSeriesAlt) ? lime100 : red100
barcolor(scolor?bcolour:na, title = "Bar Colours")
closeP=plot(closeSeriesAlt, title = "Close Series", color = trendColour, linewidth=2, style = plot.style_line)
openP=plot(openSeriesAlt, title = "Open Series", color = trendColour, linewidth = 2, style = plot.style_line)
fill(closeP,openP,color=trendColour,transp=80)

// === /PLOTTING ===

// === ALERT conditions
xlong       = ta.crossover(closeSeriesAlt, openSeriesAlt)
xshort      = ta.crossunder(closeSeriesAlt, openSeriesAlt)
longCond    = xlong   // alternative: longCond[1]? false : (xlong or xlong[1]) and close>closeSeriesAlt and close>=open
shortCond   = xshort  // alternative: shortCond[1]? false : (xshort or xshort[1]) and close<closeSeriesAlt and close<=open
// === /ALERT conditions.
// === /ALERT message ===
Lalert_msg = "Long "+" Winrate " + str.tostring(GetWinRate(),"00.00")+ "%" + " Current Price "+ str.tostring(close)+ "\n" + "Bars from prev signal:" + str.tostring(ta.barssince(xlong[1]))     + "\n"  + " Take Profit 1:"   + str.tostring(Longtakeprofit1,"#.##")   + "\n"+  " Take Profit 2:"  + str.tostring(Longtakeprofit2,"#.##")   + "\n"   +  " Stop Loss:"     + str.tostring(lowestClose)  + "\n"   +  " Time " + str.tostring(barTimeFormatted)  
Salert_msg = "Short " + " Winrate " + str.tostring(GetWinRate(),"00.00")+ "%" + " Current Price "+ str.tostring(close)  + "\n"   + "Bars from prev signal:" + str.tostring(ta.barssince(xshort[1])) + "\n"  + " Take Profit 1:"   + str.tostring(Shorttakeprofit1,"#.##")  + "\n"   +  " Take Profit 2:"   + str.tostring(Shorttakeprofit2,"#.##") + "\n"   +    "Stop Loss:"  + str.tostring(hightClose) + "\n"    +  " Time " + str.tostring(barTimeFormatted)

// === STRATEGY ===
// stop loss
slPoints    = input.int(0, "Initial Stop Loss Points (zero to disable)", minval = 0 , step = 1,group = "Stop Loss Calulate Strategy")
tpPoints    = input.int(0, "Initial Target Profit Points (zero for disable)", minval = 0,step = 1,group = "Stop Loss Calulate Strategy")
// Include bar limiting algorithm
ebar            = input.int(defval = 1900, title="Number of Bars for Back Testing", minval=0, step = 1,group = "Bars Backtest")
dummy           = input(false,        title="- SET to ZERO for Daily or Longer Timeframes",group = "Bars Backtest" )
//
// Calculate how many mars since last bar
tdays       = (timenow-time)/60000.0  // number of minutes since last bar
tperiod =timeframe.period
tdays       := timeframe.ismonthly? tdays/1440.0/5.0/4.3/str.tonumber(tperiod) : timeframe.isweekly? tdays/1440.0/5.0/str.tonumber(tperiod) : timeframe.isdaily? tdays/1440.0/str.tonumber(tperiod) : tdays/str.tonumber(tperiod) // number of bars since last bar
//
//set up exit parameters
TP = tpPoints>0?tpPoints:na
SL = slPoints>0?slPoints:na

// Make sure we are within the bar range, Set up entries and exit conditions
if ((ebar==0 or tdays<=ebar) and tradeType!="NONE")
    strategy.entry("long", strategy.long, when=longCond==true and tradeType!="SHORT", alert_message = Lalert_msg)
    strategy.entry("short", strategy.short, when=shortCond==true and tradeType!="LONG", alert_message = Salert_msg)
    strategy.close("long", when = shortCond==true and tradeType=="LONG")
    strategy.close("short", when = longCond==true and tradeType=="SHORT")
    strategy.exit("XL", from_entry = "long", profit = TP, loss = SL,comment_profit = "ELong TP ✅",comment_loss = "ELong SL ❌")
    strategy.exit("XS", from_entry = "short", profit = TP, loss = SL,comment_profit = "EShort TP ✅",comment_loss = "EShort SL ❌")

// === /STRATEGY ===
// eof

the alert will show same list of trades by time frame

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 03 '22 at 12:13
  • I upload a image, you can focus on alert log, i set alert for BTC 4h, but alert can not show when list of trades and chart show the order [img]https://i.ibb.co/zSS20v4/Alert.jpg[/img] – Long token Dec 03 '22 at 13:25

0 Answers0