PINE LIBRARY

JordanSwindenLibrary

已更新
Library "JordanSwindenLibrary"
TODO: add library description here

getDecimals()
  Calculates how many decimals are on the quote price of the current market
  Returns: The current decimal places on the market quote price

getPipSize(multiplier)
  Calculates the pip size of the current market
  Parameters:
    multiplier (int): The mintick point multiplier (1 by default, 10 for FX/Crypto/CFD but can be used to override when certain markets require)
  Returns: The pip size for the current market

truncate(number, decimalPlaces)
  Truncates (cuts) excess decimal places
  Parameters:
    number (float): The number to truncate
    decimalPlaces (simple float): (default=2) The number of decimal places to truncate to
  Returns: The given number truncated to the given decimalPlaces

toWhole(number)
  Converts pips into whole numbers
  Parameters:
    number (float): The pip number to convert into a whole number
  Returns: The converted number

toPips(number)
  Converts whole numbers back into pips
  Parameters:
    number (float): The whole number to convert into pips
  Returns: The converted number

getPctChange(value1, value2, lookback)
  Gets the percentage change between 2 float values over a given lookback period
  Parameters:
    value1 (float): The first value to reference
    value2 (float): The second value to reference
    lookback (int): The lookback period to analyze
  Returns: The percent change over the two values and lookback period

random(minRange, maxRange)
  Wichmann–Hill Pseudo-Random Number Generator
  Parameters:
    minRange (float): The smallest possible number (default: 0)
    maxRange (float): The largest possible number (default: 1)
  Returns: A random number between minRange and maxRange

bullFib(priceLow, priceHigh, fibRatio)
  Calculates a bullish fibonacci value
  Parameters:
    priceLow (float): The lowest price point
    priceHigh (float): The highest price point
    fibRatio (float): The fibonacci % ratio to calculate
  Returns: The fibonacci value of the given ratio between the two price points

bearFib(priceLow, priceHigh, fibRatio)
  Calculates a bearish fibonacci value
  Parameters:
    priceLow (float): The lowest price point
    priceHigh (float): The highest price point
    fibRatio (float): The fibonacci % ratio to calculate
  Returns: The fibonacci value of the given ratio between the two price points

getMA(length, maType)
  Gets a Moving Average based on type (! MUST BE CALLED ON EVERY TICK TO BE ACCURATE, don't place in scopes)
  Parameters:
    length (simple int): The MA period
    maType (string): The type of MA
  Returns: A moving average with the given parameters

barsAboveMA(lookback, ma)
  Counts how many candles are above the MA
  Parameters:
    lookback (int): The lookback period to look back over
    ma (float): The moving average to check
  Returns: The bar count of how many recent bars are above the MA

barsBelowMA(lookback, ma)
  Counts how many candles are below the MA
  Parameters:
    lookback (int): The lookback period to look back over
    ma (float): The moving average to reference
  Returns: The bar count of how many recent bars are below the EMA

barsCrossedMA(lookback, ma)
  Counts how many times the EMA was crossed recently (based on closing prices)
  Parameters:
    lookback (int): The lookback period to look back over
    ma (float): The moving average to reference
  Returns: The bar count of how many times price recently crossed the EMA (based on closing prices)

getPullbackBarCount(lookback, direction)
  Counts how many green & red bars have printed recently (ie. pullback count)
  Parameters:
    lookback (int): The lookback period to look back over
    direction (int): The color of the bar to count (1 = Green, -1 = Red)
  Returns: The bar count of how many candles have retraced over the given lookback & direction

getBodySize()
  Gets the current candle's body size (in POINTS, divide by 10 to get pips)
  Returns: The current candle's body size in POINTS

getTopWickSize()
  Gets the current candle's top wick size (in POINTS, divide by 10 to get pips)
  Returns: The current candle's top wick size in POINTS

getBottomWickSize()
  Gets the current candle's bottom wick size (in POINTS, divide by 10 to get pips)
  Returns: The current candle's bottom wick size in POINTS

getBodyPercent()
  Gets the current candle's body size as a percentage of its entire size including its wicks
  Returns: The current candle's body size percentage

isHammer(fib, colorMatch)
  Checks if the current bar is a hammer candle based on the given parameters
  Parameters:
    fib (float): (default=0.382) The fib to base candle body on
    colorMatch (bool): (default=false) Does the candle need to be green? (true/false)
  Returns: A boolean - true if the current bar matches the requirements of a hammer candle

isStar(fib, colorMatch)
  Checks if the current bar is a shooting star candle based on the given parameters
  Parameters:
    fib (float): (default=0.382) The fib to base candle body on
    colorMatch (bool): (default=false) Does the candle need to be red? (true/false)
  Returns: A boolean - true if the current bar matches the requirements of a shooting star candle

isDoji(wickSize, bodySize)
  Checks if the current bar is a doji candle based on the given parameters
  Parameters:
    wickSize (float): (default=2) The maximum top wick size compared to the bottom (and vice versa)
    bodySize (float): (default=0.05) The maximum body size as a percentage compared to the entire candle size
  Returns: A boolean - true if the current bar matches the requirements of a doji candle

isBullishEC(allowance, rejectionWickSize, engulfWick)
  Checks if the current bar is a bullish engulfing candle
  Parameters:
    allowance (float): (default=0) How many POINTS to allow the open to be off by (useful for markets with micro gaps)
    rejectionWickSize (float): (default=disabled) The maximum rejection wick size compared to the body as a percentage
    engulfWick (bool): (default=false) Does the engulfing candle require the wick to be engulfed as well?
  Returns: A boolean - true if the current bar matches the requirements of a bullish engulfing candle

isBearishEC(allowance, rejectionWickSize, engulfWick)
  Checks if the current bar is a bearish engulfing candle
  Parameters:
    allowance (float): (default=0) How many POINTS to allow the open to be off by (useful for markets with micro gaps)
    rejectionWickSize (float): (default=disabled) The maximum rejection wick size compared to the body as a percentage
    engulfWick (bool): (default=false) Does the engulfing candle require the wick to be engulfed as well?
  Returns: A boolean - true if the current bar matches the requirements of a bearish engulfing candle

isInsideBar()
  Detects inside bars
  Returns: Returns true if the current bar is an inside bar

isOutsideBar()
  Detects outside bars
  Returns: Returns true if the current bar is an outside bar

barInSession(sess, useFilter)
  Determines if the current price bar falls inside the specified session
  Parameters:
    sess (simple string): The session to check
    useFilter (bool): (default=true) Whether or not to actually use this filter
  Returns: A boolean - true if the current bar falls within the given time session

barOutSession(sess, useFilter)
  Determines if the current price bar falls outside the specified session
  Parameters:
    sess (simple string): The session to check
    useFilter (bool): (default=true) Whether or not to actually use this filter
  Returns: A boolean - true if the current bar falls outside the given time session

dateFilter(startTime, endTime)
  Determines if this bar's time falls within date filter range
  Parameters:
    startTime (int): The UNIX date timestamp to begin searching from
    endTime (int): the UNIX date timestamp to stop searching from
  Returns: A boolean - true if the current bar falls within the given dates

dayFilter(monday, tuesday, wednesday, thursday, friday, saturday, sunday)
  Checks if the current bar's day is in the list of given days to analyze
  Parameters:
    monday (bool): Should the script analyze this day? (true/false)
    tuesday (bool): Should the script analyze this day? (true/false)
    wednesday (bool): Should the script analyze this day? (true/false)
    thursday (bool): Should the script analyze this day? (true/false)
    friday (bool): Should the script analyze this day? (true/false)
    saturday (bool): Should the script analyze this day? (true/false)
    sunday (bool): Should the script analyze this day? (true/false)
  Returns: A boolean - true if the current bar's day is one of the given days

atrFilter(atrValue, maxSize)
  Parameters:
    atrValue (float)
    maxSize (float)

tradeCount()
  Calculate total trade count
  Returns: Total closed trade count

isLong()
  Check if we're currently in a long trade
  Returns: True if our position size is positive

isShort()
  Check if we're currently in a short trade
  Returns: True if our position size is negative

isFlat()
  Check if we're currentlyflat
  Returns: True if our position size is zero

wonTrade()
  Check if this bar falls after a winning trade
  Returns: True if we just won a trade

lostTrade()
  Check if this bar falls after a losing trade
  Returns: True if we just lost a trade

maxDrawdownRealized()
  Gets the max drawdown based on closed trades (ie. realized P&L). The strategy tester displays max drawdown as open P&L (unrealized).
  Returns: The max drawdown based on closed trades (ie. realized P&L). The strategy tester displays max drawdown as open P&L (unrealized).

totalPipReturn()
  Gets the total amount of pips won/lost (as a whole number)
  Returns: Total amount of pips won/lost (as a whole number)

longWinCount()
  Count how many winning long trades we've had
  Returns: Long win count

shortWinCount()
  Count how many winning short trades we've had
  Returns: Short win count

longLossCount()
  Count how many losing long trades we've had
  Returns: Long loss count

shortLossCount()
  Count how many losing short trades we've had
  Returns: Short loss count

breakEvenCount(allowanceTicks)
  Count how many break-even trades we've had
  Parameters:
    allowanceTicks (float): Optional - how many ticks to allow between entry & exit price (default 0)
  Returns: Break-even count

longCount()
  Count how many long trades we've taken
  Returns: Long trade count

shortCount()
  Count how many short trades we've taken
  Returns: Short trade count

longWinPercent()
  Calculate win rate of long trades
  Returns: Long win rate (0-100)

shortWinPercent()
  Calculate win rate of short trades
  Returns: Short win rate (0-100)

breakEvenPercent(allowanceTicks)
  Calculate break even rate of all trades
  Parameters:
    allowanceTicks (float): Optional - how many ticks to allow between entry & exit price (default 0)
  Returns: Break-even win rate (0-100)

averageRR()
  Calculate average risk:reward
  Returns: Average winning trade divided by average losing trade

unitsToLots(units)
  (Forex) Convert the given unit count to lots (multiples of 100,000)
  Parameters:
    units (float): The units to convert into lots
  Returns: Units converted to nearest lot size (as float)

getFxPositionSize(balance, risk, stopLossPips, fxRate, lots)
  (Forex) Calculate fixed-fractional position size based on given parameters
  Parameters:
    balance (float): The account balance
    risk (float): The % risk (whole number)
    stopLossPips (float): Pip distance to base risk on
    fxRate (float): The conversion currency rate (more info below in library documentation)
    lots (bool): Whether or not to return the position size in lots rather than units (true by default)
  Returns: Units/lots to enter into "qty=" parameter of strategy entry function

EXAMPLE USAGE:

string conversionCurrencyPair = (strategy.account_currency == syminfo.currency ? syminfo.tickerid : strategy.account_currency + syminfo.currency)
float fx_rate = request.security(conversionCurrencyPair, timeframe.period, close[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]
if (longCondition)
strategy.entry("Long", strategy.long, qty=zen.getFxPositionSize(strategy.equity, 1, stopLossPipsWholeNumber, fx_rate, true))

skipTradeMonteCarlo(chance, debug)
  Checks to see if trade should be skipped to emulate rudimentary Monte Carlo simulation
  Parameters:
    chance (float): The chance to skip a trade (0-1 or 0-100, function will normalize to 0-1)
    debug (bool): Whether or not to display a label informing of the trade skip
  Returns: True if the trade is skipped, false if it's not skipped (idea being to include this function in entry condition validation checks)

fillCell(tableID, column, row, title, value, bgcolor, txtcolor, tooltip)
  This updates the given table's cell with the given values
  Parameters:
    tableID (table): The table ID to update
    column (int): The column to update
    row (int): The row to update
    title (string): The title of this cell
    value (string): The value of this cell
    bgcolor (color): The background color of this cell
    txtcolor (color): The text color of this cell
    tooltip (string)
  Returns: Nothing.
發行說明
v2
發行說明
v3

Added:
AVopenLong(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview long buy alert
  Parameters:
    exchange (string)
    symbol (string)
    accountAlias (string)
    SL (float)
    TP (float)
    quantity (int)
    orderType (string)
  Returns: Long buy alert suitable for Autoview

AVopenShort(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview short sell alert
  Parameters:
    exchange (string)
    symbol (string)
    accountAlias (string)
    SL (float)
    TP (float)
    quantity (int)
    orderType (string)
  Returns: Short sell alert suitable for Autoview
發行說明
v4
發行說明
v5

Updated:
AVopenLong(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview long buy alert
  Parameters:
    exchange (string): Autoview exchange
    symbol (string): Autoview symbol
    accountAlias (string): Autoview account accountAlias
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
    quantity (int): Autoview quantity
    orderType (string): Autoview order type
  Returns: Long buy alert suitable for Autoview

Removed:
AVopenShort(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview short sell alert
發行說明
v6

Removed:
AVopenLong(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview long buy alert
發行說明
v7

Added:
AVopenLong(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview long buy alert
  Parameters:
    exchange (string): Autoview exchange
    symbol (string): Autoview symbol
    accountAlias (string): Autoview account accountAlias
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
    quantity (int): Autoview quantity
    orderType (string): Autoview order type
  Returns: Long buy alert suitable for Autoview
發行說明
v8

Updated:
AVopenLong(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview long buy alert
  Parameters:
    exchange (string): Autoview exchange
    symbol (string): Autoview symbol
    accountAlias (string): Autoview account accountAlias
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
    quantity (float): Autoview quantity
    orderType (string): Autoview order type
  Returns: Long buy alert suitable for Autoview
發行說明
v9

Added:
AVopenShort(exchange, symbol, accountAlias, SL, TP, quantity, orderType)
  Autoview short sell alert
  Parameters:
    exchange (string): Autoview exchange
    symbol (string): Autoview symbol
    accountAlias (string): Autoview account accountAlias
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
    quantity (float): Autoview quantity
    orderType (string): Autoview order type
  Returns: Short sell alert suitable for Autoview

AVcloseLong(exchange, symbol, accountAlias, orderType)
  Autoview long close
  Parameters:
    exchange (string): Autoview exchange
    symbol (string): Autoview symbol
    accountAlias (string): Autoview account accountAlias
    orderType (string): Autoview order type
  Returns: Long close alert suitable for Autoview

AVcloseShort(exchange, symbol, accountAlias, orderType)
  Autoview short close
  Parameters:
    exchange (string): Autoview exchange
    symbol (string): Autoview symbol
    accountAlias (string): Autoview account accountAlias
    orderType (string): Autoview order type
  Returns: Short close alert suitable for Autoview

PCopenLong(LicenceID, symbol, risk, SL, TP, comment, key)
  Pine Connector long buy alert
  Parameters:
    LicenceID (string): Pine Connector licence ID
    symbol (string): Pine Connector symbol
    risk (string): Pine Connector risk
    SL (float): Pine Connector SL
    TP (float): Pine Connector TP
    comment (string): Pine Connector comment
    key (string): Pine Connector Secret Key
  Returns: Long buy alert suitable for Pine Connector

PCopenShort(LicenceID, symbol, risk, SL, TP, comment, key)
  Pine Connector short sell alert
  Parameters:
    LicenceID (string): Pine Connector licence ID
    symbol (string): Pine Connector symbol
    risk (string): Pine Connector risk
    SL (float): Pine Connector SL
    TP (float): Pine Connector TP
    comment (string): Pine Connector comment
    key (string): Pine Connector Secret Key
  Returns: Short sell alert suitable for Pine Connector

PCcloseLong(LicenceID, symbol, comment, key)
  Pine Connector long close
  Parameters:
    LicenceID (string): Pine Connector licence ID
    symbol (string): Pine Connector symbol
    comment (string): Pine Connector comment
    key (string): Pine Connector Secret Key
  Returns: Long close alert suitable for Pine Connector

PCcloseShort(LicenceID, symbol, comment, key)
  Pine Connector short close
  Parameters:
    LicenceID (string): Pine Connector licence ID
    symbol (string): Pine Connector symbol
    comment (string): Pine Connector comment
    key (string): Pine Connector Secret Key
  Returns: Short close alert suitable for Pine Connector
發行說明
v10

Updated:
AVopenLong(symbol, quantity, orderType, SL, TP)
  Autoview long buy alert
  Parameters:
    symbol (string): Autoview symbol
    quantity (float): Autoview quantity
    orderType (string): Autoview order type
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
  Returns: Long buy alert suitable for Autoview

AVopenShort(symbol, quantity, orderType, SL, TP)
  Autoview short sell alert
  Parameters:
    symbol (string): Autoview symbol
    quantity (float): Autoview quantity
    orderType (string): Autoview order type
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
  Returns: Short sell alert suitable for Autoview

AVcloseLong(symbol, orderType)
  Autoview long close
  Parameters:
    symbol (string): Autoview symbol
    orderType (string): Autoview order type
  Returns: Long close alert suitable for Autoview

AVcloseShort(symbol, orderType)
  Autoview short close
  Parameters:
    symbol (string): Autoview symbol
    orderType (string): Autoview order type
  Returns: Short close alert suitable for Autoview
發行說明
v11

Added:
AVnewsltplong(symbol, SL, TP)
  Autoview long update SL & TP
  Parameters:
    symbol (string): Autoview symbol
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
  Returns: Long SLTP update alert suitable for Autoview

AVnewsltpshort(symbol, SL, TP)
  Autoview short update SL & TP
  Parameters:
    symbol (string): Autoview symbol
    SL (float): Autoview stop loss
    TP (float): Autoview take profit
  Returns: Short SLTP update alert suitable for Autoview
發行說明
v12

Added:
AVcloseLongShort(symbol, orderType)
  Autoview long short close
  Parameters:
    symbol (string): Autoview symbol
    orderType (string): Autoview order type
  Returns: Long & short close alert suitable for Autoview

Updated:
getFxPositionSize(balance, risk, stopLossPips, fxRate, lots)
  (Forex) Calculate fixed-fractional position size based on given parameters
  Parameters:
    balance (float): The account balance
    risk (float): The % risk (whole number)
    stopLossPips (float): Pip distance to base risk on
    fxRate (float): The conversion currency rate (more info below in library documentation)
    lots (bool): Whether or not to return the position size in lots rather than units (true by default)
  Returns: Units/lots to enter into "qty=" parameter of strategy entry function

EXAMPLE USAGE:

string conversionCurrencyPair = (strategy.account_currency == syminfo.currency ? syminfo.tickerid : strategy.account_currency + syminfo.currency)
float fx_rate = request.security(conversionCurrencyPair, timeframe.period, close[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]
if (longCondition)
strategy.entry("Long", strategy.long, qty=jslib.getFxPositionSize(strategy.equity, 1, stopLossPipsWholeNumber, fx_rate, true))
debugging

Pine腳本庫

在真正的TradingView精神中,作者將這段Pine程式碼發佈為開源程式庫,以便我們社群的其他Pine程式設計師可以重複使用它。請向作者致敬!您可以私下使用這個函式庫,或在其他開源出版品中使用,但在出版物中再次使用這段程式碼將受到網站規則的約束。

免責聲明