PINE LIBRARY

CNTLibrary

Aktualisiert
Library "CNTLibrary"
Custom Functions To Help Code In Pinescript V5

Coded By Christian Nataliano
First Coded In 10/06/2023
Last Edited In 22/06/2023

Huge Shout Out To © ZenAndTheArtOfTrading and his ZenLibrary V5, Some Of The Custom Functions Were Heavily Inspired By Matt's Work & His Pine Script Mastery Course
Another Shout Out To The TradingView's Team Library ta V5

//====================================================================================================================================================
// Custom Indicator Functions
//====================================================================================================================================================

GetKAMA(KAMA_lenght, Fast_KAMA, Slow_KAMA)
  Calculates An Adaptive Moving Average Based On Perry J Kaufman's Calculations
  Parameters:
    KAMA_lenght (int): Is The KAMA Lenght
    Fast_KAMA (int): Is The KAMA's Fastes Moving Average
    Slow_KAMA (int): Is The KAMA's Slowest Moving Average
  Returns: Float Of The KAMA's Current Calculations

GetMovingAverage(Source, Lenght, Type)
  Get Custom Moving Averages Values
  Parameters:
    Source (float): Of The Moving Average, Defval = close
    Lenght (simple int): Of The Moving Average, Defval = 50
    Type (string): Of The Moving Average, Defval = Exponential Moving Average
  Returns: The Moving Average Calculation Based On Its Given Source, Lenght & Calculation Type (Please Call Function On Global Scope)

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

Truncate(number, decimalPlaces)
  Truncates (cuts) excess decimal places © ZenAndTheArtOfTrading
  Parameters:
    number (float)
    decimalPlaces (simple float)
  Returns: The given number truncated to the given decimalPlaces

ToWhole(number)
  Converts pips into whole numbers © ZenAndTheArtOfTrading
  Parameters:
    number (float)
  Returns: The converted number

ToPips(number)
  Converts whole numbers back into pips © ZenAndTheArtOfTrading
  Parameters:
    number (float)
  Returns: The converted number

GetPctChange(value1, value2, lookback)
  Gets the percentage change between 2 float values over a given lookback period © ZenAndTheArtOfTrading
  Parameters:
    value1 (float)
    value2 (float)
    lookback (int)

BarsAboveMA(lookback, ma)
  Counts how many candles are above the MA © ZenAndTheArtOfTrading
  Parameters:
    lookback (int)
    ma (float)
  Returns: The bar count of how many recent bars are above the MA

BarsBelowMA(lookback, ma)
  Counts how many candles are below the MA © ZenAndTheArtOfTrading
  Parameters:
    lookback (int)
    ma (float)
  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 © ZenAndTheArtOfTrading
  Parameters:
    lookback (int)
    ma (float)
  Returns: The bar count of how many times price recently crossed the EMA

GetPullbackBarCount(lookback, direction)
  Counts how many green & red bars have printed recently (ie. pullback count) © ZenAndTheArtOfTrading
  Parameters:
    lookback (int)
    direction (int)
  Returns: The bar count of how many candles have retraced over the given lookback & direction

GetSwingHigh(Lookback, SwingType)
  Check If Price Has Made A Recent Swing High
  Parameters:
    Lookback (int): Is For The Swing High Lookback Period, Defval = 7
    SwingType (int): Is For The Swing High Type Of Identification, Defval = 1
  Returns: A Bool - True If Price Has Made A Recent Swing High

GetSwingLow(Lookback, SwingType)
  Check If Price Has Made A Recent Swing Low
  Parameters:
    Lookback (int): Is For The Swing Low Lookback Period, Defval = 7
    SwingType (int): Is For The Swing Low Type Of Identification, Defval = 1
  Returns: A Bool - True If Price Has Made A Recent Swing Low

//====================================================================================================================================================
// Custom Risk Management Functions
//====================================================================================================================================================

CalculateStopLossLevel(OrderType, Entry, StopLoss)
  Calculate StopLoss Level
  Parameters:
    OrderType (int): Is To Determine A Long / Short Position, Defval = 1
    Entry (float): Is The Entry Level Of The Order, Defval = na
    StopLoss (float): Is The Custom StopLoss Distance, Defval = 2x ATR Below Close
  Returns: Float - The StopLoss Level In Actual Price As A

CalculateStopLossDistance(OrderType, Entry, StopLoss)
  Calculate StopLoss Distance In Pips
  Parameters:
    OrderType (int): Is To Determine A Long / Short Position, Defval = 1
    Entry (float): Is The Entry Level Of The Order, NEED TO INPUT PARAM
    StopLoss (float): Level Based On Previous Calculation, NEED TO INPUT PARAM
  Returns: Float - The StopLoss Value In Pips

CalculateTakeProfitLevel(OrderType, Entry, StopLossDistance, RiskReward)
  Calculate TakeProfit Level
  Parameters:
    OrderType (int): Is To Determine A Long / Short Position, Defval = 1
    Entry (float): Is The Entry Level Of The Order, Defval = na
    StopLossDistance (float)
    RiskReward (float)
  Returns: Float - The TakeProfit Level In Actual Price

CalculateTakeProfitDistance(OrderType, Entry, TakeProfit)
  Get TakeProfit Distance In Pips
  Parameters:
    OrderType (int): Is To Determine A Long / Short Position, Defval = 1
    Entry (float): Is The Entry Level Of The Order, NEED TO INPUT PARAM
    TakeProfit (float): Level Based On Previous Calculation, NEED TO INPUT PARAM
  Returns: Float - The TakeProfit Value In Pips

CalculateConversionCurrency(AccountCurrency, SymbolCurrency, BaseCurrency)
  Get The Conversion Currecny Between Current Account Currency & Current Pair's Quoted Currency (FOR FOREX ONLY)
  Parameters:
    AccountCurrency (simple string): Is For The Account Currency Used
    SymbolCurrency (simple string): Is For The Current Symbol Currency (Front Symbol)
    BaseCurrency (simple string): Is For The Current Symbol Base Currency (Back Symbol)
  Returns: Tuple Of A Bollean (Convert The Currency ?) And A String (Converted Currency)

CalculateConversionRate(ConvertCurrency, ConversionRate)
  Get The Conversion Rate Between Current Account Currency & Current Pair's Quoted Currency (FOR FOREX ONLY)
  Parameters:
    ConvertCurrency (bool): Is To Check If The Current Symbol Needs To Be Converted Or Not
    ConversionRate (float): Is The Quoted Price Of The Conversion Currency (Input The request.security Function Here)
  Returns: Float Price Of Conversion Rate (If In The Same Currency Than Return Value Will Be 1.0)

LotSize(LotSizeSimple, Balance, Risk, SLDistance, ConversionRate)
  Get Current Lot Size
  Parameters:
    LotSizeSimple (bool): Is To Toggle Lot Sizing Calculation (Simple Is Good Enough For Stocks & Crypto, Whilst Complex Is For Forex)
    Balance (float): Is For The Current Account Balance To Calculate The Lot Sizing Based Off
    Risk (float): Is For The Current Risk Per Trade To Calculate The Lot Sizing Based Off
    SLDistance (float): Is The Current Position StopLoss Distance From Its Entry Price
    ConversionRate (float): Is The Currency Conversion Rate (Used For Complex Lot Sizing Only)
  Returns: Float - Position Size In Units

ToLots(Units)
  Converts Units To Lots
  Parameters:
    Units (float): Is For How Many Units Need To Be Converted Into Lots (Minimun 1000 Units)
  Returns: Float - Position Size In Lots

ToUnits(Lots)
  Converts Lots To Units
  Parameters:
    Lots (float): Is For How Many Lots Need To Be Converted Into Units (Minimun 0.01 Units)
  Returns: Int - Position Size In Units

ToLotsInUnits(Units)
  Converts Units To Lots Than Back To Units
  Parameters:
    Units (float): Is For How Many Units Need To Be Converted Into Lots (Minimun 1000 Units)
  Returns: Float - Position Size In Lots That Were Rounded To Units

ATRTrail(OrderType, SourceType, ATRPeriod, ATRMultiplyer, SwingLookback)
  Calculate ATR Trailing Stop
  Parameters:
    OrderType (int): Is To Determine A Long / Short Position, Defval = 1
    SourceType (int): Is To Determine Where To Calculate The ATR Trailing From, Defval = close
    ATRPeriod (simple int): Is To Change Its ATR Period, Defval = 20
    ATRMultiplyer (float): Is To Change Its ATR Trailing Distance, Defval = 1
    SwingLookback (int): Is To Change Its Swing HiLo Lookback (Only From Source Type 5), Defval = 7
  Returns: Float - Number Of The Current ATR Trailing

DangerZone(WinRate, AvgRRR, Filter)
  Calculate Danger Zone Of A Given Strategy
  Parameters:
    WinRate (float): Is The Strategy WinRate
    AvgRRR (float): Is The Strategy Avg RRR
    Filter (float): Is The Minimum Profit It Needs To Be Out Of BE Zone, Defval = 3
  Returns: Int - Value, 1 If Out Of Danger Zone, 0 If BE, -1 If In Danger Zone

IsQuestionableTrades(TradeTP, TradeSL)
  Checks For Questionable Trades (Which Are Trades That Its TP & SL Level Got Hit At The Same Candle)
  Parameters:
    TradeTP (float): Is The Trade In Question Take Profit Level
    TradeSL (float): Is The Trade In Question Stop Loss Level
  Returns: Bool - True If The Last Trade Was A "Questionable Trade"

//====================================================================================================================================================
// Custom Strategy Functions
//====================================================================================================================================================

OpenLong(EntryID, LotSize, LimitPrice, StopPrice, Comment, CommentValue)
  Open A Long Order Based On The Given Params
  Parameters:
    EntryID (string): Is The Trade Entry ID, Defval = "Long"
    LotSize (float): Is The Lot Size Of The Trade, Defval = 1
    LimitPrice (float): Is The Limit Order Price To Set The Order At, Defval = Na / Market Order Execution
    StopPrice (float): Is The Stop Order Price To Set The Order At, Defval = Na / Market Order Execution
    Comment (string): Is The Order Comment, Defval = Long Entry Order
    CommentValue (string): Is For Custom Values In The Order Comment, Defval = Na
  Returns: Void

OpenShort(EntryID, LotSize, LimitPrice, StopPrice, Comment, CommentValue)
  Open A Short Order Based On The Given Params
  Parameters:
    EntryID (string): Is The Trade Entry ID, Defval = "Short"
    LotSize (float): Is The Lot Size Of The Trade, Defval = 1
    LimitPrice (float): Is The Limit Order Price To Set The Order At, Defval = Na / Market Order Execution
    StopPrice (float): Is The Stop Order Price To Set The Order At, Defval = Na / Market Order Execution
    Comment (string): Is The Order Comment, Defval = Short Entry Order
    CommentValue (string): Is For Custom Values In The Order Comment, Defval = Na
  Returns: Void

TP_SLExit(FromID, TPLevel, SLLevel, PercentageClose, Comment, CommentValue)
  Exits Based On Predetermined TP & SL Levels
  Parameters:
    FromID (string): Is The Trade ID That The TP & SL Levels Be Palced
    TPLevel (float): Is The Take Profit Level
    SLLevel (float): Is The StopLoss Level
    PercentageClose (float): Is The Amount To Close The Order At (In Percentage) Defval = 100
    Comment (string): Is The Order Comment, Defval = Exit Order
    CommentValue (string): Is For Custom Values In The Order Comment, Defval = Na
  Returns: Void

CloseLong(ExitID, PercentageClose, Comment, CommentValue, Instant)
  Exits A Long Order Based On A Specified Condition
  Parameters:
    ExitID (string): Is The Trade ID That Will Be Closed, Defval = "Long"
    PercentageClose (float): Is The Amount To Close The Order At (In Percentage) Defval = 100
    Comment (string): Is The Order Comment, Defval = Exit Order
    CommentValue (string): Is For Custom Values In The Order Comment, Defval = Na
    Instant (bool): Is For Exit Execution Type, Defval = false
  Returns: Void

CloseShort(ExitID, PercentageClose, Comment, CommentValue, Instant)
  Exits A Short Order Based On A Specified Condition
  Parameters:
    ExitID (string): Is The Trade ID That Will Be Closed, Defval = "Short"
    PercentageClose (float): Is The Amount To Close The Order At (In Percentage) Defval = 100
    Comment (string): Is The Order Comment, Defval = Exit Order
    CommentValue (string): Is For Custom Values In The Order Comment, Defval = Na
    Instant (bool): Is For Exit Execution Type, Defval = false
  Returns: Void

BrokerCheck(Broker)
  Checks Traded Broker With Current Loaded Chart Broker
  Parameters:
    Broker (string): Is The Current Broker That Is Traded
  Returns: Bool - True If Current Traded Broker Is Same As Loaded Chart Broker

OpenPC(LicenseID, OrderType, UseLimit, LimitPrice, SymbolPrefix, Symbol, SymbolSuffix, Risk, SL, TP, OrderComment, Spread)
  Compiles Given Parameters Into An Alert String Format To Open Trades Using Pine Connector
  Parameters:
    LicenseID (string): Is The Users PineConnector LicenseID
    OrderType (int): Is The Desired OrderType To Open
    UseLimit (bool): Is If We Want To Enter The Position At Exactly The Previous Closing Price
    LimitPrice (float): Is The Limit Price Of The Trade (Only For Pending Orders)
    SymbolPrefix (string): Is The Current Symbol Prefix (If Any)
    Symbol (string): Is The Traded Symbol
    SymbolSuffix (string): Is The Current Symbol Suffix (If Any)
    Risk (float): Is The Trade Risk Per Trade / Fixed Lot Sizing
    SL (float): Is The Trade SL In Price / In Pips
    TP (float): Is The Trade TP In Price / In Pips
    OrderComment (string): Is The Executed Trade Comment
    Spread (float): is The Maximum Spread For Execution
  Returns: String - Pine Connector Order Syntax Alert Message

ClosePC(LicenseID, OrderType, SymbolPrefix, Symbol, SymbolSuffix)
  Compiles Given Parameters Into An Alert String Format To Close Trades Using Pine Connector
  Parameters:
    LicenseID (string): Is The Users PineConnector LicenseID
    OrderType (int): Is The Desired OrderType To Close
    SymbolPrefix (string): Is The Current Symbol Prefix (If Any)
    Symbol (string): Is The Traded Symbol
    SymbolSuffix (string): Is The Current Symbol Suffix (If Any)
  Returns: String - Pine Connector Order Syntax Alert Message

//====================================================================================================================================================
// Custom Backtesting Calculation Functions
//====================================================================================================================================================

CalculatePNL(EntryPrice, ExitPrice, LotSize, ConversionRate)
  Calculates Trade PNL Based On Entry, Eixt & Lot Size
  Parameters:
    EntryPrice (float): Is The Trade Entry
    ExitPrice (float): Is The Trade Exit
    LotSize (float): Is The Trade Sizing
    ConversionRate (float): Is The Currency Conversion Rate (Used For Complex Lot Sizing Only)
  Returns: Float - The Current Trade PNL

UpdateBalance(PrevBalance, PNL)
  Updates The Previous Ginve Balance To The Next PNL
  Parameters:
    PrevBalance (float): Is The Previous Balance To Be Updated
    PNL (float): Is The Current Trade PNL To Be Added
  Returns: Float - The Current Updated PNL

CalculateSlpComm(PNL, MaxRate)
  Calculates Random Slippage & Commisions Fees Based On The Parameters
  Parameters:
    PNL (float): Is The Current Trade PNL
    MaxRate (float): Is The Upper Limit (In Percentage) Of The Randomized Fee
  Returns: Float - A Percentage Fee Of The Current Trade PNL

UpdateDD(MaxBalance, Balance)
  Calculates & Updates The DD Based On Its Given Parameters
  Parameters:
    MaxBalance (float): Is The Maximum Balance Ever Recorded
    Balance (float): Is The Current Account Balance
  Returns: Float - The Current Strategy DD

CalculateWR(TotalTrades, LongID, ShortID)
  Calculate The Total, Long & Short Trades Win Rate
  Parameters:
    TotalTrades (int): Are The Current Total Trades That The Strategy Has Taken
    LongID (string): Is The Order ID Of The Long Trades Of The Strategy
    ShortID (string): Is The Order ID Of The Short Trades Of The Strategy
  Returns: Tuple Of Long WR%, Short WR%, Total WR%, Total Winning Trades, Total Losing Trades, Total Long Trades & Total Short Trades

CalculateAvgRRR(WinTrades, LossTrades)
  Calculates The Overall Strategy Avg Risk Reward Ratio
  Parameters:
    WinTrades (int): Are The Strategy Winning Trades
    LossTrades (int): Are The Strategy Losing Trades
  Returns: Float - The Average RRR Values

CAGR(StartTime, StartPrice, EndTime, EndPrice)
  Calculates The CAGR Over The Given Time Period © TradingView
  Parameters:
    StartTime (int): Is The Starting Time Of The Calculation
    StartPrice (float): Is The Starting Price Of The Calculation
    EndTime (int): Is The Ending Time Of The Calculation
    EndPrice (float): Is The Ending Price Of The Calculation
  Returns: Float - The CAGR Values

//====================================================================================================================================================
// Custom Plot Functions
//====================================================================================================================================================

EditLabels(LabelID, X1, Y1, Text, Color, TextColor, EditCondition, DeleteCondition)
  Edit / Delete Labels
  Parameters:
    LabelID (label): Is The ID Of The Selected Label
    X1 (int): Is The X1 Coordinate IN BARINDEX Xloc
    Y1 (float): Is The Y1 Coordinate IN PRICE Yloc
    Text (string): Is The Text Than Wants To Be Written In The Label
    Color (color): Is The Color Value Change Of The Label Text
    TextColor (color)
    EditCondition (int): Is The Edit Condition of The Line (Setting Location / Color)
    DeleteCondition (bool): Is The Delete Condition Of The Line If Ture Deletes The Prev Itteration Of The Line
  Returns: Void

EditLine(LineID, X1, Y1, X2, Y2, Color, EditCondition, DeleteCondition)
  Edit / Delete Lines
  Parameters:
    LineID (line): Is The ID Of The Selected Line
    X1 (int): Is The X1 Coordinate IN BARINDEX Xloc
    Y1 (float): Is The Y1 Coordinate IN PRICE Yloc
    X2 (int): Is The X2 Coordinate IN BARINDEX Xloc
    Y2 (float): Is The Y2 Coordinate IN PRICE Yloc
    Color (color): Is The Color Value Change Of The Line
    EditCondition (int): Is The Edit Condition of The Line (Setting Location / Color)
    DeleteCondition (bool): Is The Delete Condition Of The Line If Ture Deletes The Prev Itteration Of The Line
  Returns: Void

//====================================================================================================================================================
// Custom Display Functions (Using Tables)
//====================================================================================================================================================

FillTable(TableID, Column, Row, Title, Value, BgColor, TextColor, ToolTip)
  Filling The Selected Table With The Inputed Information
  Parameters:
    TableID (table): Is The Table ID That Wants To Be Edited
    Column (int): Is The Current Column Of The Table That Wants To Be Edited
    Row (int): Is The Current Row Of The Table That Wants To Be Edited
    Title (string): Is The String Title Of The Current Cell Table
    Value (string): Is The String Value Of The Current Cell Table
    BgColor (color): Is The Selected Color For The Current Table
    TextColor (color): Is The Selected Color For The Current Table
    ToolTip (string): Is The ToolTip Of The Current Cell In The Table
  Returns: Void

DisplayBTResults(TableID, BgColor, TextColor, StartingBalance, Balance, DollarReturn, TotalPips, MaxDD)
  Filling The Selected Table With The Inputed Information
  Parameters:
    TableID (table): Is The Table ID That Wants To Be Edited
    BgColor (color): Is The Selected Color For The Current Table
    TextColor (color): Is The Selected Color For The Current Table
    StartingBalance (float): Is The Account Starting Balance
    Balance (float)
    DollarReturn (float): Is The Account Dollar Reture
    TotalPips (float): Is The Total Pips Gained / loss
    MaxDD (float): Is The Maximum Drawdown Over The Backtesting Period
  Returns: Void

DisplayBTResultsV2(TableID, BgColor, TextColor, TotalWR, QTCount, LongWR, ShortWR, InitialCapital, CumProfit, CumFee, AvgRRR, MaxDD, CAGR, MeanDD)
  Filling The Selected Table With The Inputed Information
  Parameters:
    TableID (table): Is The Table ID That Wants To Be Edited
    BgColor (color): Is The Selected Color For The Current Table
    TextColor (color): Is The Selected Color For The Current Table
    TotalWR (float): Is The Strategy Total WR In %
    QTCount (int): Is The Strategy Questionable Trades Count
    LongWR (float): Is The Strategy Total WR In %
    ShortWR (float): Is The Strategy Total WR In %
    InitialCapital (float): Is The Strategy Initial Starting Capital
    CumProfit (float): Is The Strategy Ending Cumulative Profit
    CumFee (float): Is The Strategy Ending Cumulative Fee (Based On Randomized Fee Assumptions)
    AvgRRR (float): Is The Strategy Average Risk Reward Ratio
    MaxDD (float): Is The Strategy Maximum DrawDown In Its Backtesting Period
    CAGR (float): Is The Strategy Compounded Average GRowth In %
    MeanDD (float): Is The Strategy Mean / Average Drawdown In The Backtesting Period
  Returns: Void

//====================================================================================================================================================
// Custom Pattern Detection Functions
//====================================================================================================================================================

BullFib(priceLow, priceHigh, fibRatio)
  Calculates A Bullish Fibonacci Value (From Swing Low To High) © ZenAndTheArtOfTrading
  Parameters:
    priceLow (float)
    priceHigh (float)
    fibRatio (float)
  Returns: The Fibonacci Value Of The Given Ratio Between The Two Price Points

BearFib(priceLow, priceHigh, fibRatio)
  Calculates A Bearish Fibonacci Value (From Swing High To Low) © ZenAndTheArtOfTrading
  Parameters:
    priceLow (float)
    priceHigh (float)
    fibRatio (float)
  Returns: The Fibonacci Value Of The Given Ratio Between The Two Price Points

GetBodySize()
  Gets The Current Candle Body Size IN POINTS © ZenAndTheArtOfTrading
  Returns: The Current Candle Body Size IN POINTS

GetTopWickSize()
  Gets The Current Candle Top Wick Size IN POINTS © ZenAndTheArtOfTrading
  Returns: The Current Candle Top Wick Size IN POINTS

GetBottomWickSize()
  Gets The Current Candle Bottom Wick Size IN POINTS © ZenAndTheArtOfTrading
  Returns: The Current Candle Bottom Wick Size IN POINTS

GetBodyPercent()
  Gets The Current Candle Body Size As A Percentage Of Its Entire Size Including Its Wicks © ZenAndTheArtOfTrading
  Returns: The Current Candle Body Size IN PERCENTAGE

GetTopWickPercent()
  Gets The Current Top Wick Size As A Percentage Of Its Entire Body Size
  Returns: Float - The Current Candle Top Wick Size IN PERCENTAGE

GetBottomWickPercent()
  Gets The Current Bottom Wick Size As A Percentage Of Its Entire Bodu Size
  Returns: Float - The Current Candle Bottom Size IN PERCENTAGE

BullishEC(Allowance, RejectionWickSize, EngulfWick, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Bullish Engulfing Candle
  Parameters:
    Allowance (int): To Give Flexibility Of Engulfing Pattern Detection In Markets That Have Micro Gaps, Defval = 0
    RejectionWickSize (float): To Filter Out long (Upper And Lower) Wick From The Bullsih Engulfing Pattern, Defval = na
    EngulfWick (bool): To Specify If We Want The Pattern To Also Engulf Its Upper & Lower Previous Wicks, Defval = false
    NearSwings (bool): To Specify If We Want The Pattern To Be Near A Recent Swing Low, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing Low, Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Bullish Engulfing Candle

BearishEC(Allowance, RejectionWickSize, EngulfWick, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Bearish Engulfing Candle
  Parameters:
    Allowance (int): To Give Flexibility Of Engulfing Pattern Detection In Markets That Have Micro Gaps, Defval = 0
    RejectionWickSize (float): To Filter Out long (Upper And Lower) Wick From The Bearish Engulfing Pattern, Defval = na
    EngulfWick (bool): To Specify If We Want The Pattern To Also Engulf Its Upper & Lower Previous Wicks, Defval = false
    NearSwings (bool): To Specify If We Want The Pattern To Be Near A Recent Swing High, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing High, Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Bearish Engulfing Candle

Hammer(Fib, ColorMatch, NearSwings, SwingLookBack, ATRFilterCheck, ATRPeriod)
  Checks If The Current Bar Is A Hammer Candle
  Parameters:
    Fib (float): To Specify Which Fibonacci Ratio To Use When Determining The Hammer Candle, Defval = 0.382 Ratio
    ColorMatch (bool): To Filter Only Bullish Closed Hammer Candle Pattern, Defval = false
    NearSwings (bool): To Specify If We Want The Doji To Be Near A Recent Swing Low, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing Low, Defval = 10
    ATRFilterCheck (float): To Filter Smaller Hammer Candles That Might Be Better Classified As A Doji Candle, Defval = 1
    ATRPeriod (simple int): To Change ATR Period Of The ATR Filter, Defval = 20
  Returns: Bool - True If The Current Bar Matches The Requirements of a Hammer Candle

Star(Fib, ColorMatch, NearSwings, SwingLookBack, ATRFilterCheck, ATRPeriod)
  Checks If The Current Bar Is A Hammer Candle
  Parameters:
    Fib (float): To Specify Which Fibonacci Ratio To Use When Determining The Hammer Candle, Defval = 0.382 Ratio
    ColorMatch (bool): To Filter Only Bullish Closed Hammer Candle Pattern, Defval = false
    NearSwings (bool): To Specify If We Want The Doji To Be Near A Recent Swing Low, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing Low, Defval = 10
    ATRFilterCheck (float): To Filter Smaller Hammer Candles That Might Be Better Classified As A Doji Candle, Defval = 1
    ATRPeriod (simple int): To Change ATR Period Of The ATR Filter, Defval = 20
  Returns: Bool - True If The Current Bar Matches The Requirements of a Hammer Candle

Doji(MaxWickSize, MaxBodySize, DojiType, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Doji Candle
  Parameters:
    MaxWickSize (float): To Specify The Maximum Lenght Of Its Upper & Lower Wick, Defval = 2
    MaxBodySize (float): To Specify The Maximum Lenght Of Its Candle Body IN PERCENT, Defval = 0.05
    DojiType (int)
    NearSwings (bool): To Specify If We Want The Doji To Be Near A Recent Swing High / Low (Only In Dragonlyf / Gravestone Mode), Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing High / Low (Only In Dragonlyf / Gravestone Mode), Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Doji Candle

BullishIB(Allowance, RejectionWickSize, EngulfWick, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Bullish Harami Candle
  Parameters:
    Allowance (int): To Give Flexibility Of Harami Pattern Detection In Markets That Have Micro Gaps, Defval = 0
    RejectionWickSize (float): To Filter Out long (Upper And Lower) Wick From The Bullsih Harami Pattern, Defval = na
    EngulfWick (bool): To Specify If We Want The Pattern To Also Engulf Its Upper & Lower Previous Wicks, Defval = false
    NearSwings (bool): To Specify If We Want The Pattern To Be Near A Recent Swing Low, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing Low, Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Bullish Harami Candle

BearishIB(Allowance, RejectionWickSize, EngulfWick, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Bullish Harami Candle
  Parameters:
    Allowance (int): To Give Flexibility Of Harami Pattern Detection In Markets That Have Micro Gaps, Defval = 0
    RejectionWickSize (float): To Filter Out long (Upper And Lower) Wick From The Bearish Harami Pattern, Defval = na
    EngulfWick (bool): To Specify If We Want The Pattern To Also Engulf Its Upper & Lower Previous Wicks, Defval = false
    NearSwings (bool): To Specify If We Want The Pattern To Be Near A Recent Swing High, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing High, Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Bearish Harami Candle

//====================================================================================================================================================
// Custom Time Functions
//====================================================================================================================================================

BarInSession(sess, useFilter)
  Determines if the current price bar falls inside the specified session © ZenAndTheArtOfTrading
  Parameters:
    sess (simple string)
    useFilter (bool)
  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 © ZenAndTheArtOfTrading
  Parameters:
    sess (simple string)
    useFilter (bool)
  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 © ZenAndTheArtOfTrading
  Parameters:
    startTime (int)
    endTime (int)
  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 © ZenAndTheArtOfTrading
  Parameters:
    monday (bool)
    tuesday (bool)
    wednesday (bool)
    thursday (bool)
    friday (bool)
    saturday (bool)
    sunday (bool)
  Returns: A boolean - true if the current bar's day is one of the given days

AUSSess()
  Checks If The Current Australian Forex Session In Running
  Returns: Bool - True If Currently The Australian Session Is Running

ASIASess()
  Checks If The Current Asian Forex Session In Running
  Returns: Bool - True If Currently The Asian Session Is Running

EURSess()
  Checks If The Current European Forex Session In Running
  Returns: Bool - True If Currently The European Session Is Running

USSess()
  Checks If The Current US Forex Session In Running
  Returns: Bool - True If Currently The US Session Is Running

UNIXToDate(Time, ConversionType, TimeZone)
  Converts UNIX Time To Datetime
  Parameters:
    Time (int): Is The UNIX Time Input
    ConversionType (int): Is The Datetime Output Format, Defval = DD-MM-YYYY
    TimeZone (string): Is To Convert The Outputed Datetime Into The Specified Time Zone, Defval = Exchange Time Zone
  Returns: String - String Of Datetime
Versionshinweise
v2

Added:
CanclePC(LicenseID, OrderType, SymbolPrefix, Symbol, SymbolSuffix)
  Compiles Given Parameters Into An Alert String Format To Cancel Trades Using Pine Connector
  Parameters:
    LicenseID (string): Is The Users PineConnector LicenseID
    OrderType (int): Is The Desired OrderType To Close
    SymbolPrefix (string): Is The Current Symbol Prefix (If Any)
    Symbol (string): Is The Traded Symbol
    SymbolSuffix (string): Is The Current Symbol Suffix (If Any)
  Returns: String - Pine Connector Order Syntax Alert Message
Versionshinweise
v3
*Fixed Typo
*Updated OpenPC Command To Include Limit Order & Stop Order Placement
*Updated ClosePC & CancelPC To Include Multi Symbol Capability

Added:
CancelPC(LicenseID, OrderType, SymbolPrefix, Symbol, SymbolSuffix, OrderComment)
  Compiles Given Parameters Into An Alert String Format To Cancel Trades Using Pine Connector
  Parameters:
    LicenseID (string): Is The Users PineConnector LicenseID
    OrderType (int): Is The Desired OrderType To Close
    SymbolPrefix (string): Is The Current Symbol Prefix (If Any)
    Symbol (string): Is The Traded Symbol
    SymbolSuffix (string): Is The Current Symbol Suffix (If Any)
    OrderComment (string): Is The Executed Trade Comment For Multi Strategy Implementation
  Returns: String - Pine Connector Order Syntax Alert Message

Updated:
OpenPC(LicenseID, OrderType, UseLimit, UseStop, Price, SymbolPrefix, Symbol, SymbolSuffix, Risk, SL, TP, OrderComment, Spread)
  Compiles Given Parameters Into An Alert String Format To Open Trades Using Pine Connector
  Parameters:
    LicenseID (string): Is The Users PineConnector LicenseID
    OrderType (int): Is The Desired OrderType To Open
    UseLimit (bool): Is If We Want To Enter Using A Limit Order
    UseStop (bool): Is If We Want To Enter Using A Stop Order
    Price (float): Is The Limit Price Of The Trade (Only For Pending Orders)
    SymbolPrefix (string): Is The Current Symbol Prefix (If Any)
    Symbol (string): Is The Traded Symbol
    SymbolSuffix (string): Is The Current Symbol Suffix (If Any)
    Risk (float): Is The Trade Risk Per Trade / Fixed Lot Sizing
    SL (float): Is The Trade SL In Price / In Pips
    TP (float): Is The Trade TP In Price / In Pips
    OrderComment (string): Is The Executed Trade Comment
    Spread (float): is The Maximum Spread For Execution
  Returns: String - Pine Connector Order Syntax Alert Message

ClosePC(LicenseID, OrderType, SymbolPrefix, Symbol, SymbolSuffix, OrderComment)
  Compiles Given Parameters Into An Alert String Format To Close Trades Using Pine Connector
  Parameters:
    LicenseID (string): Is The Users PineConnector LicenseID
    OrderType (int): Is The Desired OrderType To Close
    SymbolPrefix (string): Is The Current Symbol Prefix (If Any)
    Symbol (string): Is The Traded Symbol
    SymbolSuffix (string): Is The Current Symbol Suffix (If Any)
    OrderComment (string): Is The Executed Trade Comment For Multi Strategy Implementation
  Returns: String - Pine Connector Order Syntax Alert Message

Removed:
CanclePC(LicenseID, OrderType, SymbolPrefix, Symbol, SymbolSuffix)
  Compiles Given Parameters Into An Alert String Format To Cancel Trades Using Pine Connector
Versionshinweise
v4

Added:
New Inside Bar Logic In BullishIBV2 & BearishIBV2

BullishIBV2(RejectionWickSize, IncludeBody, ColorMatch, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Bullish Harami Candle
  Parameters:
    RejectionWickSize (float): To Filter Out long (Upper And Lower) Wick From The Bullsih Harami Pattern, Defval = na
    IncludeBody (bool): To Specify If We Want The Pattern To Also Be "Inside" Its Previous Body Candle And Not Just HiLo Range, Defval = false
    ColorMatch (bool): To Have A Bullish & Bearish Variaton Similar To Bullish Engulfing, Defval = false
    NearSwings (bool): To Specify If We Want The Pattern To Be Near A Recent Swing Low, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing Low, Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Bullish Harami Candle Version 2

BearishIBV2(RejectionWickSize, IncludeBody, ColorMatch, NearSwings, SwingLookBack)
  Checks If The Current Bar Is A Bearish Harami Candle
  Parameters:
    RejectionWickSize (float): To Filter Out long (Upper And Lower) Wick From The Bearish Harami Pattern, Defval = na
    IncludeBody (bool): To Specify If We Want The Pattern To Also Be "Inside" Its Previous Body Candle And Not Just HiLo Range, Defval = false
    ColorMatch (bool): To Have A Bullish & Bearish Variaton Similar To Bullish Engulfing, Defval = false
    NearSwings (bool): To Specify If We Want The Pattern To Be Near A Recent Swing High, Defval = true
    SwingLookBack (int): To Specify How Many Bars Back To Detect A Recent Swing High, Defval = 10
  Returns: Bool - True If The Current Bar Matches The Requirements of a Bearish Harami Candle Version 2
displaystatisticsstrategies

Pine Bibliothek

Ganz im Sinne von TradingView hat dieser Autor seinen/ihren Pine Code als Open-Source-Bibliothek veröffentlicht. Auf diese Weise können nun auch andere Pine-Programmierer aus unserer Community den Code verwenden. Vielen Dank an den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Veröffentlichungen verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert.

Haftungsausschluss