如果当前交易时段正在盘整,我如何为下一交易时段开始之前的亚洲交易时段的高点和低点绘制一条线?
How do I plot a line for the the high and low of the Asia session up to the start of the next session, if the current session is consolidating?
为了对此进行研究,我一直在查看各种在线参考资料和教程。我是 Pine 的新手,但有 Python 背景。
我想做的是在 TradingView 上绘制亚洲时段的高点和低点,以便它跨越到下一个时段的开始,如果在亚洲时段内进行盘整的话。
我已经成功地做到了这一点,几乎(见下文)。
查看下面的代码:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlfieJ04
//@version=4
study("Asia Consolidation and Breakout Indicator", shorttitle="ACBI", overlay=true)
//-------------------------------------------------------------------------------------------------------------
// Inputs
timeframe = input(title="Session", type=input.session, defval="1700-0300:12345") // Asia session Monday to Friday
bgColor = input(title="Disable background?", type=input.bool, defval=false)
lookbackLeft = input(title="Lookback Left", type=input.integer, defval=20)
lookbackRight = input(title="Lookback Right", type=input.integer, defval=5)
percentage = input(title="Consolidation Threshold", type=input.float, defval=2.0)
asia = input(title="Show Asia Session?", type=input.bool, defval=true)
extendType = input(false, title="Extend Lines?") ? extend.right : extend.none
showPrice = input(true, title="Show Prices?")
//-------------------------------------------------------------------------------------------------------------
// Variables
asiaColor = color.blue
threshold = 1 - (percentage / 100)
maxClose = highest(high, lookbackLeft)[1]
minClose = lowest(low, lookbackLeft)[1]
float asiaMaxHigh = na
float asiaMinLow = na
bool consolidating = na
bool breakout = na
bool breakdown = na
float asiaHigh = na
float asiaLow = na
//-------------------------------------------------------------------------------------------------------------
// Determine if we are in a session
asiaSession = not na(time(timeframe.period, timeframe))
newSession = asiaSession and not asiaSession[1]
//-------------------------------------------------------------------------------------------------------------
// Define consolidating and breakout/breakdown
if asiaSession
consolidating := minClose > (maxClose * threshold) ? true : false
if not asiaSession
breakout := not consolidating and close > maxClose ? true : false
breakdown := not consolidating and close < minClose ? true : false
//-------------------------------------------------------------------------------------------------------------
// Plot Asia Session to screen
bgcolor(asiaSession and asia and not bgColor ? asiaColor : na, transp=90)
barcolor(consolidating ? color.purple : na)
//-------------------------------------------------------------------------------------------------------------
asiaMaxHigh := asiaSession ? maxClose[1] : asiaMaxHigh[1]
asiaMinLow := asiaSession ? minClose[1] : asiaMinLow[1]
plot(asiaMaxHigh, color=color.green, style=plot.style_circles, title='Asia High')
plot(asiaMinLow, color=color.red, style=plot.style_circles, title='Asia Low')
这应该绘制出您要查找的内容。
它在亚洲时段跟踪 high
和 low
,并且仅在亚洲时段不再活跃时才开始绘图。
//@version=4
study("Asia Session", overlay=true)
var hourSessionStart = input(22, "Asia session start hour (GMT)", minval=0, maxval=23)
var hourSessionStop = input(08, "Asia session end hour (GMT)", minval=0, maxval=23)
var float hi = na
var float lo = na
var float plotHi = na
var float plotLo = na
var int currentHourGMT = na
var bool inSession = na
var bool enteringSession = na
var bool exitingSession = na
currentHourGMT := hour(time, "GMT")
inSession := (currentHourGMT >= hourSessionStart or currentHourGMT < hourSessionStop)
enteringSession := inSession and not inSession[1]
exitingSession := not inSession and inSession[1]
if enteringSession
plotLo := na
plotHi := na
if inSession
lo := min(low, nz(lo, 1.0e23))
hi := max(high, nz(hi))
if exitingSession
plotLo := lo
plotHi := hi
lo := na
hi := na
bgcolor(inSession ? color.blue : na)
plot(plotLo, "Asia session Low", color.red, style=plot.style_linebr)
plot(plotHi, "Asia session High", color.green, style=plot.style_linebr)
为了对此进行研究,我一直在查看各种在线参考资料和教程。我是 Pine 的新手,但有 Python 背景。
我想做的是在 TradingView 上绘制亚洲时段的高点和低点,以便它跨越到下一个时段的开始,如果在亚洲时段内进行盘整的话。
我已经成功地做到了这一点,几乎(见下文)。
查看下面的代码:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlfieJ04
//@version=4
study("Asia Consolidation and Breakout Indicator", shorttitle="ACBI", overlay=true)
//-------------------------------------------------------------------------------------------------------------
// Inputs
timeframe = input(title="Session", type=input.session, defval="1700-0300:12345") // Asia session Monday to Friday
bgColor = input(title="Disable background?", type=input.bool, defval=false)
lookbackLeft = input(title="Lookback Left", type=input.integer, defval=20)
lookbackRight = input(title="Lookback Right", type=input.integer, defval=5)
percentage = input(title="Consolidation Threshold", type=input.float, defval=2.0)
asia = input(title="Show Asia Session?", type=input.bool, defval=true)
extendType = input(false, title="Extend Lines?") ? extend.right : extend.none
showPrice = input(true, title="Show Prices?")
//-------------------------------------------------------------------------------------------------------------
// Variables
asiaColor = color.blue
threshold = 1 - (percentage / 100)
maxClose = highest(high, lookbackLeft)[1]
minClose = lowest(low, lookbackLeft)[1]
float asiaMaxHigh = na
float asiaMinLow = na
bool consolidating = na
bool breakout = na
bool breakdown = na
float asiaHigh = na
float asiaLow = na
//-------------------------------------------------------------------------------------------------------------
// Determine if we are in a session
asiaSession = not na(time(timeframe.period, timeframe))
newSession = asiaSession and not asiaSession[1]
//-------------------------------------------------------------------------------------------------------------
// Define consolidating and breakout/breakdown
if asiaSession
consolidating := minClose > (maxClose * threshold) ? true : false
if not asiaSession
breakout := not consolidating and close > maxClose ? true : false
breakdown := not consolidating and close < minClose ? true : false
//-------------------------------------------------------------------------------------------------------------
// Plot Asia Session to screen
bgcolor(asiaSession and asia and not bgColor ? asiaColor : na, transp=90)
barcolor(consolidating ? color.purple : na)
//-------------------------------------------------------------------------------------------------------------
asiaMaxHigh := asiaSession ? maxClose[1] : asiaMaxHigh[1]
asiaMinLow := asiaSession ? minClose[1] : asiaMinLow[1]
plot(asiaMaxHigh, color=color.green, style=plot.style_circles, title='Asia High')
plot(asiaMinLow, color=color.red, style=plot.style_circles, title='Asia Low')
这应该绘制出您要查找的内容。
它在亚洲时段跟踪 high
和 low
,并且仅在亚洲时段不再活跃时才开始绘图。
//@version=4
study("Asia Session", overlay=true)
var hourSessionStart = input(22, "Asia session start hour (GMT)", minval=0, maxval=23)
var hourSessionStop = input(08, "Asia session end hour (GMT)", minval=0, maxval=23)
var float hi = na
var float lo = na
var float plotHi = na
var float plotLo = na
var int currentHourGMT = na
var bool inSession = na
var bool enteringSession = na
var bool exitingSession = na
currentHourGMT := hour(time, "GMT")
inSession := (currentHourGMT >= hourSessionStart or currentHourGMT < hourSessionStop)
enteringSession := inSession and not inSession[1]
exitingSession := not inSession and inSession[1]
if enteringSession
plotLo := na
plotHi := na
if inSession
lo := min(low, nz(lo, 1.0e23))
hi := max(high, nz(hi))
if exitingSession
plotLo := lo
plotHi := hi
lo := na
hi := na
bgcolor(inSession ? color.blue : na)
plot(plotLo, "Asia session Low", color.red, style=plot.style_linebr)
plot(plotHi, "Asia session High", color.green, style=plot.style_linebr)