Library "ICTlibrary" Used to calculate various ICT related price levels and strategies. An ongoing project.
Hello Coders!
This library is meant for sourcing ICT related concepts. While some functions might generate more output than you require, you can specify "Lite Mode" as "true" in applicable functions to slim down necessary inputs.
isLastBar(userTF) Identifies the last bar on the chart before a timeframe change Parameters: userTF (simple int): the timeframe you wish to calculate the last bar for, must be converted to integer using 'timeframe.in_seconds()' Returns: bool true if bar on chart is last bar of higher TF, dalse if bar on chart is not last bar of higher TF
necessaryData(atrTF) returns necessaryData UDT for historical data access Parameters: atrTF (float): user-selected timeframe ATR value. Returns: logZ. log return Z score, used for calculating order blocks.
method gradBoxes(gradientBoxes, idColor, timeStart, bottom, top, rightCoordinate) creates neon like effect for box drawings Namespace types: array<box> Parameters: gradientBoxes (array<box>): an array.new<box>() to store the gradient boxes idColor (color) timeStart (int): left point of box bottom (float): bottom of box price point top (float): top of box price point rightCoordinate (int): right point of box Returns: void
checkIfTraded(tradeName) checks if recent trade is of specific name Parameters: tradeName (string) Returns: bool true if recent trade id matches target name, false otherwise
checkIfClosed(tradeName) checks if recent closed trade is of specific name Parameters: tradeName (string) Returns: bool true if recent closed trade id matches target name, false otherwise
IQZZ(atrMult, finalTF) custom ZZ to quickly determine market direction. Parameters: atrMult (float): an atr multiplier used to determine the required price move for a ZZ direction change finalTF (string): the timeframe used for the atr calcuation Returns: dir market direction. Up => 1, down => -1
method drawBos(id, startPoint, getKeyPointTime, getKeyPointPrice, col, showBOS, isUp) calculates and draws Break Of Structure Namespace types: array<labelLine> Parameters: id (array<labelLine>) startPoint (chart.point) getKeyPointTime (int): the actual time of startPoint, simplystartPoint.time getKeyPointPrice (float): the actual time of startPoint, simplystartPoint.price col (color): color of the BoS line / label showBOS (bool): whether to show label/line. This function still calculates internally for other ICT related concepts even if not drawn. isUp (bool): whether BoS happened during price increase or price decrease. Returns: void
method drawMSS(id, startPoint, getKeyPointTime, getKeyPointPrice, col, showMSS, isUp, upRejections, dnRejections, highArr, lowArr, timeArr, closeArr, openArr, atrTFarr, upRejectionsPrices, dnRejectionsPrices) calculates and draws Market Structure Shift. This data is also used to calculate Rejection Blocks. Namespace types: array<labelLine> Parameters: id (array<labelLine>) startPoint (chart.point) getKeyPointTime (int): the actual time of startPoint, simplystartPoint.time getKeyPointPrice (float): the actual time of startPoint, simplystartPoint.price col (color): color of the MSS line / label showMSS (bool): whether to show label/line. This function still calculates internally for other ICT related concepts even if not drawn. isUp (bool): whether MSS happened during price increase or price decrease. upRejections (array<rejectionBlocks>) dnRejections (array<rejectionBlocks>) highArr (array<float>): array containing historical highs, should be taken from the UDT "necessaryData" defined above lowArr (array<float>): array containing historical lows, should be taken from the UDT "necessaryData" defined above timeArr (array<int>): array containing historical times, should be taken from the UDT "necessaryData" defined above closeArr (array<float>): array containing historical closes, should be taken from the UDT "necessaryData" defined above openArr (array<float>): array containing historical opens, should be taken from the UDT "necessaryData" defined above atrTFarr (array<float>): array containing historical atr values (of user-selected TF), should be taken from the UDT "necessaryData" defined above upRejectionsPrices (array<float>): array containing up rejections prices. Is sorted and used to determine selective looping for invalidations. dnRejectionsPrices (array<float>): array containing down rejections prices. Is sorted and used to determine selective looping for invalidations. Returns: void
method getTime(id, compare, timeArr) gets time of inputted price (compare) in an array of data this is useful when the user-selected timeframe for ICT concepts is greater than the chart's timeframe Namespace types: array<float> Parameters: id (array<float>): the array of data to search through, to find which index has the same value as "compare" compare (float): the target data point to find in the array timeArr (array<int>): array of historical times Returns: the time that the data point in the array was recorded
method OB(id, highArr, signArr, lowArr, timeArr, sign) store bullish orderblock data Namespace types: array<orderBlock> Parameters: id (array<orderBlock>) highArr (array<float>): array of historical highs signArr (array<float>): array of historical price direction "math.sign(close - open)" lowArr (array<float>): array of historical lows timeArr (array<int>): array of historical times sign (int): orderblock direction, -1 => bullish, 1 => bearish Returns: void
OTEstrat(OTEstart, future, closeArr, highArr, lowArr, timeArr, longOTEPT, longOTESL, longOTElevel, shortOTEPT, shortOTESL, shortOTElevel, structureDirection, oteLongs, atrTF, oteShorts) executes the OTE strategy Parameters: OTEstart (chart.point) future (int): future time point for drawings closeArr (array<float>): array of historical closes highArr (array<float>): array of historical highs lowArr (array<float>): array of historical lows timeArr (array<int>): array of historical times longOTEPT (string): user-selected long OTE profit target, please create an input.string() for this using the example below longOTESL (int): user-selected long OTE stop loss, please create an input.string() for this using the example below longOTElevel (float): long entry price of selected retracement ratio for OTE shortOTEPT (string): user-selected short OTE profit target, please create an input.string() for this using the example below shortOTESL (int): user-selected short OTE stop loss, please create an input.string() for this using the example below shortOTElevel (float): short entry price of selected retracement ratio for OTE structureDirection (string): current market structure direction, this should be "Up" or "Down". This is used to cancel pending orders if market structure changes oteLongs (bool): input.bool() for whether OTE longs can be executed atrTF (float): atr of the user-seleceted TF oteShorts (bool): input.bool() for whether OTE shorts can be executed @exampleInputs oteLongs = input.bool(defval = false, title = "OTE Longs", group = "Optimal Trade Entry") longOTElevel = input.float(defval = 0.79, title = "Long Entry Retracement Level", options = [0.79, 0.705, 0.62], group = "Optimal Trade Entry") longOTEPT = input.string(defval = "-0.5", title = "Long TP", options = ["-0.5", "-1", "-2", "Swing High"], group = "Optimal Trade Entry") longOTESL = input.int(defval = 0, title = "How Many Ticks Below Swing Low For Stop Loss", group = "Optimal Trade Entry") oteShorts = input.bool(defval = false, title = "OTE Shorts", group = "Optimal Trade Entry") shortOTElevel = input.float(defval = 0.79, title = "Short Entry Retracement Level", options = [0.79, 0.705, 0.62], group = "Optimal Trade Entry") shortOTEPT = input.string(defval = "-0.5", title = "Short TP", options = ["-0.5", "-1", "-2", "Swing Low"], group = "Optimal Trade Entry") shortOTESL = input.int(defval = 0, title = "How Many Ticks Above Swing Low For Stop Loss", group = "Optimal Trade Entry") Returns: void (0)
displacement(logZ, atrTFreg, highArr, timeArr, lowArr, upDispShow, dnDispShow, masterCoords, labelLevels, dispUpcol, rightCoordinate, dispDncol, noBorders) calculates and draws dispacements Parameters: logZ (float): log return of current price, used to determine a "significant price move" for a displacement atrTFreg (float): atr of user-seleceted timeframe highArr (array<float>): array of historical highs timeArr (array<int>): array of historical times lowArr (array<float>): array of historical lows upDispShow (int): amount of historical upside displacements to show dnDispShow (int): amount of historical downside displacements to show masterCoords (map<string, float>): a <string, float> map to push the most recent displacement prices into, useful for having key levels in one data structure labelLevels (string): used to determine label placement for the displacement, can be inside box, outside box, or none, example below dispUpcol (color): upside displacement color rightCoordinate (int): future time for displacement drawing, best is "last_bar_time" dispDncol (color): downside displacement color noBorders (bool): input.bool() to remove box borders, example below @exampleInputs labelLevels = input.string(defval = "Inside" , title = "Box Label Placement", options = ["Inside", "Outside", "None"]) noBorders = input.bool(defval = false, title = "No Borders On Levels") Returns: void
method getStrongLow(id, startIndex, timeArr, lowArr, strongLowPoints) unshift strong low data to array<strongPoints> id Namespace types: array<strongPoints> Parameters: id (array<strongPoints>) startIndex (int): the starting index for the timeArr array of the UDT "necessaryData". this point should start from at least 1 pivot prior to find the low before an upside BoS timeArr (array<int>): array of historical times lowArr (array<float>): array of historical lows strongLowPoints (array<float>): array of strong low prices. Used to retrieve highest strong low price and see if need for removal of invalidated strong lows Returns: void
method getStrongHigh(id, startIndex, timeArr, highArr, strongHighPoints) unshift strong high data to array<strongPoints> id Namespace types: array<strongPoints> Parameters: id (array<strongPoints>) startIndex (int): the starting index for the timeArr array of the UDT "necessaryData". this point should start from at least 1 pivot prior to find the high before a downside BoS timeArr (array<int>): array of historical times highArr (array<float>): array of historical highs strongHighPoints (array<float>) Returns: void
equalLevels(highArr, lowArr, timeArr, rightCoordinate, equalHighsCol, equalLowsCol, liteMode) used to calculate recent equal highs or equal lows Parameters: highArr (array<float>): array of historical highs lowArr (array<float>): array of historical lows timeArr (array<int>): array of historical times rightCoordinate (int): a future time (right for boxes, x2 for lines) equalHighsCol (color): user-selected color for equal highs drawings equalLowsCol (color): user-selected color for equal lows drawings liteMode (bool): optional for a lite mode version of an ICT strategy. For more control over drawings leave as "True", "False" will apply neon effects Returns: void
quickTime(timeString) used to quickly determine if a user-inputted time range is currently active in NYT time Parameters: timeString (string): a time range Returns: true if session is active, false if session is inactive
macros(showMacros, noBorders) used to calculate and draw session macros Parameters: showMacros (bool): an input.bool() or simple bool to determine whether to activate the function noBorders (bool): an input.bool() to determine whether the box anchored to the session should have borders Returns: void
po3(tf, left, right, show) use to calculate HTF po3 candle tip only call this function on "barstate.islast" Parameters: tf (simple string) left (int): the left point of the candle, calculated as bar_index + left, right (int): :the right point of the candle, calculated as bar_index + right, show (bool): input.bool() whether to show the po3 candle or not Returns: void
silverBullet(silverBulletStratLong, silverBulletStratShort, future, userTF, H, L, H2, L2, noBorders, silverBulletLongTP, historicalPoints, historicalData, silverBulletLongSL, silverBulletShortTP, silverBulletShortSL) used to execute the Silver Bullet Strategy Parameters: silverBulletStratLong (simple bool) silverBulletStratShort (simple bool) future (int): a future time, used for drawings, example "last_bar_time" userTF (simple int) H (float): the high price of the user-selected TF L (float): the low price of the user-selected TF H2 (float): the high[2] price of the user-selected TF L2 (float): the low[2] price of the user-selected TF noBorders (bool): an input.bool() used to remove the borders from box drawings silverBulletLongTP (series silverBulletLevels) historicalPoints (array<chart.point>) historicalData (necessaryData) silverBulletLongSL (series silverBulletLevels) silverBulletShortTP (series silverBulletLevels) silverBulletShortSL (series silverBulletLevels) Returns: void
method invalidFVGcheck(FVGarr, upFVGpricesSorted, dnFVGpricesSorted) check if existing FVGs are still valid Namespace types: array<FVG> Parameters: FVGarr (array<FVG>) upFVGpricesSorted (array<float>): an array of bullish FVG prices, used to selective search through FVG array to remove invalidated levels dnFVGpricesSorted (array<float>): an array of bearish FVG prices, used to selective search through FVG array to remove invalidated levels Returns: void (0)
method drawFVG(counter, FVGshow, FVGname, FVGcol, data, masterCoords, labelLevels, borderTransp, liteMode, rightCoordinate) draws FVGs on last bar Namespace types: map<string, int> Parameters: counter (map<string, int>): a counter, as map<string, int>, keeping count of the number of FVGs drawn, makes sure that there aren't more FVGs drawn than int FVGshow FVGshow (int): the number of FVGs to show. There should be a bullish FVG show and bearish FVG show. This function "drawFVG" is used separately for bearish FVG and bullish FVG. FVGname (string): the name of the FVG, "FVG Up" or "FVG Down" FVGcol (color): desired FVG color data (FVG) masterCoords (map<string, float>): a map<string, float> containing the names and price points of key levels. Used to define price ranges. labelLevels (string): an input.string with options "Inside", "Outside", "Remove". Determines whether FVG labels should be inside box, outside, or na. borderTransp (int) liteMode (bool) rightCoordinate (int): the right coordinate of any drawings. Must be a time point. Returns: void
invalidBlockCheck(bullishOBbox, bearishOBbox, userTF) check if existing order blocks are still valid Parameters: bullishOBbox (array<orderBlock>): an array declared using the UDT orderBlock that contains bullish order block related data bearishOBbox (array<orderBlock>): an array declared using the UDT orderBlock that contains bearish order block related data userTF (simple int) Returns: void (0)
method lastBarRejections(id, rejectionColor, idShow, rejectionString, labelLevels, borderTransp, liteMode, rightCoordinate, masterCoords) draws rejectionBlocks on last bar Namespace types: array<rejectionBlocks> Parameters: id (array<rejectionBlocks>): the array<rejectionBlocks>, an array of rejection block data declared using the UDT rejection block rejectionColor (color): the desired color of the rejection box idShow (int) rejectionString (string): the desired name of the rejection blocks labelLevels (string): an input.string() to determine if labels for the block should be inside the box, outside, or none. borderTransp (int) liteMode (bool): an input.bool(). True = neon effect, false = no neon. rightCoordinate (int): atime for the right coordinate of the box masterCoords (map<string, float>): a map <string, float> that stores the price of key levels and assigns them a name, used to determine price ranges Returns: void
method OBdraw(id, OBshow, BBshow, OBcol, BBcol, bullishString, bearishString, isBullish, labelLevels, borderTransp, liteMode, rightCoordinate, masterCoords) draws orderblocks and breaker blocks for data stored in UDT array<orderBlock>() Namespace types: array<orderBlock> Parameters: id (array<orderBlock>): the array<orderBlock>, an array of order block data declared using the UDT orderblock OBshow (int): the number of order blocks to show BBshow (int): the number of breaker blocks to show OBcol (color): color of order blocks BBcol (color): color of breaker blocks bullishString (string): the title of bullish blocks, which is a regular bullish orderblock or a bearish orderblock that's converted to breakerblock bearishString (string): the title of bearish blocks, which is a regular bearish orderblock or a bullish orderblock that's converted to breakerblock isBullish (bool): whether the array<orderBlock> contains bullish orderblocks or bearish orderblocks. If bullish orderblocks, the array will naturally contain bearish BB, and if bearish OB, the array will naturally contain bullish BB labelLevels (string): an input.string() to determine if labels for the block should be inside the box, outside, or none. borderTransp (int) liteMode (bool): an input.bool(). True = neon effect, false = no neon. rightCoordinate (int): atime for the right coordinate of the box masterCoords (map<string, float>): a map <string, float> that stores the price of key levels and assigns them a name, used to determine price ranges Returns: void
FVG UDT for FVG calcualtions Fields: H (series float): high price of user-selected timeframe L (series float): low price of user-selected timeframe direction (series string): FVG direction => "Up" or "Down" T (series int): => time of bar on user-selected timeframe where FVG was created fvgLabel (series label): optional label for FVG fvgLineTop (series line): optional line for top of FVG fvgLineBot (series line): optional line for bottom of FVG fvgBox (series box): optional box for FVG
labelLine quickly pair a line and label together as UDT Fields: lin (series line): Line you wish to pair with label lab (series label): Label you wish to pair with line
orderBlock UDT for order block calculations Fields: orderBlockData (array<float>): array containing order block x and y points orderBlockBox (series box): optional order block box vioCount (series int): = 0 violation count of the order block. 0 = Order Block, 1 = Breaker Block traded (series bool) status (series string): = "OB" status == "OB" => Level is order block. status == "BB" => Level is breaker block. orderBlockLab (series label): options label for the order block / breaker block.
strongPoints UDT for strong highs and strong lows Fields: price (series float): price of the strong high or strong low timeAtprice (series int): time of the strong high or strong low strongPointLabel (series label): optional label for strong point strongPointLine (series line): optional line for strong point overlayLine (series line): optional lines for strong point to enhance visibility overlayLine2 (series line): optional lines for strong point to enhance visibility
displacement UDT for dispacements Fields: highPrice (series float): high price of displacement lowPrice (series float): low price of displacement timeAtPrice (series int): time of bar where displacement occurred displacementBox (series box): optional box to draw displacement displacementLab (series label): optional label for displacement
po3data UDT for po3 calculations Fields: dHigh (series float): higher timeframe high price dLow (series float): higher timeframe low price dOpen (series float): higher timeframe open price dClose (series float): higher timeframe close price po3box (series box): box to draw po3 candle body po3line (array<line>): line array to draw po3 wicks po3Labels (array<label>): label array to label price points of po3 candle
macros UDT for session macros Fields: sessions (array<bool>): Array of sessions, you can populate this array using the "quickTime" function located above "export macros". prices (matrix<float>): Matrix of session data -> open, high, low, close, time sessionTimes (array<string>): Array of session names. Pairs with array<bool> sessions. sessionLines (matrix<line>): Optional array for sesion drawings.
OTEtimes UDT for data storage and drawings associated with OTE strategy Fields: upTimes (array<int>): time of highest point before trade is taken dnTimes (array<int>): time of lowest point before trade is taken tpLineLong (series line): line to mark tp level long tpLabelLong (series label): label to mark tp level long slLineLong (series line): line to mark sl level long slLabelLong (series label): label to mark sl level long tpLineShort (series line): line to mark tp level short tpLabelShort (series label): label to mark tp level short slLineShort (series line): line to mark sl level short slLabelShort (series label): label to mark sl level short
sweeps UDT for data storage and drawings associated with liquidity sweeps Fields: upSweeps (matrix<float>): matrix containing liquidity sweep price points and time points for up sweeps dnSweeps (matrix<float>): matrix containing liquidity sweep price points and time points for down sweeps upSweepDrawings (array<box>): optional up sweep box array. Pair the size of this array with the rows or columns, dnSweepDrawings (array<box>): optional up sweep box array. Pair the size of this array with the rows or columns,
raidExitDrawings UDT for drawings associated with the Liquidity Raid Strategy Fields: tpLine (series line): tp line for the liquidity raid entry tpLabel (series label): tp label for the liquidity raid entry slLine (series line): sl line for the liquidity raid entry slLabel (series label): sl label for the liquidity raid entry
m2022 UDT for data storage and drawings associated with the Model 2022 Strategy Fields: mTime (series int): time of the FVG where entry limit order is placed mIndex (series int): array index of FVG where entry limit order is placed. This requires an array of FVG data, which is defined above. mEntryDistance (series float): the distance of the FVG to the 50% range. M2022 looks for the fvg closest to 50% mark of range. mEntry (series float): the entry price for the most eligible fvg fvgHigh (series float): the high point of the eligible fvg fvgLow (series float): the low point of the eligible fvg longFVGentryBox (series box): long FVG box, used to draw the eligible FVG shortFVGentryBox (series box): short FVG box, used to draw the eligible FVG line50P (series line): line used to mark 50% of the range line100P (series line): line used to mark 100% (top) of the range line0P (series line): line used to mark 0% (bottom) of the range label50P (series label): label used to mark 50% of the range label100P (series label): label used to mark 100% (top) of the range label0P (series label): label used to mark 0% (bottom) of the range sweepData (array<float>)
silverBullet UDT for data storage and drawings associated with the Silver Bullet Strategy Fields: session (series bool) sessionStr (series string): name of the session for silver bullet sessionBias (series string) sessionHigh (series float): = high high of session // use math.max(silverBullet.sessionHigh, high) sessionLow (series float): = low low of session // use math.min(silverBullet.sessionLow, low) sessionFVG (series float): if applicable, the FVG created during the session sessionFVGdraw (series box): if applicable, draw the FVG created during the session traded (series bool) tp (series float): tp of trade entered at the session FVG sl (series float): sl of trade entered at the session FVG sessionDraw (series box): optional draw session with box sessionDrawLabel (series label): optional label session with label
silverBulletDrawings UDT for trade exit drawings associated with the Silver Bullet Strategy Fields: tpLine (series line): tp line drawing for strategy tpLabel (series label): tp label drawing for strategy slLine (series line): sl line drawing for strategy slLabel (series label): sl label drawing for strategy
unicornModel UDT for data storage and drawings associated with the Unicorn Model Strategy Fields: hPoint (chart.point) hPoint2 (chart.point) hPoint3 (chart.point) breakerBlock (series box): used to draw the breaker block required for the Unicorn Model FVG (series box): used to draw the FVG required for the Unicorn model topBlock (series float): price of top of breaker block, can be used to detail trade entry botBlock (series float): price of bottom of breaker block, can be used to detail trade entry startBlock (series int): start time of the breaker block, used to set the "left = " param for the box includes (array<int>): used to store the time of the breaker block, or FVG, or the chart point sequence that setup the Unicorn Model. entry (series float): // eligible entry price, for longs"math.max(topBlock, FVG.get_top())", tpLine (series line): optional line to mark PT tpLabel (series label): optional label to mark PT slLine (series line): optional line to mark SL slLabel (series label): optional label to mark SL
rejectionBlocks UDT for data storage and drawings associated with rejection blocks Fields: rejectionPoint (chart.point) bodyPrice (series float): candle body price closest to the rejection point, for "Up" rejections => math.max(open, close), rejectionBox (series box): optional box drawing of the rejection block rejectionLabel (series label): optional label for the rejection block
equalLevelsDraw UDT for data storage and drawings associated with equal highs / equal lows Fields: connector (series line): single line placed at the first high or low, y = avgerage of distinguished equal highs/lows connectorLab (series label): optional label to be placed at the highs or lows levels (array<float>): array containing the equal highs or lows prices times (array<int>): array containing the equal highs or lows individual times startTime (series int): the time of the first high or low that forms a sequence of equal highs or lows radiate (array<label>): options label to "radiate" the label in connector lab. Can be used for anything
necessaryData UDT for data storage of historical price points. Fields: highArr (array<float>): array containing historical high points lowArr (array<float>): array containing historical low points timeArr (array<int>): array containing historical time points logArr (array<float>): array containing historical log returns signArr (array<float>): array containing historical price directions closeArr (array<float>): array containing historical close points binaryTimeArr (array<int>): array containing historical time points, uses "push" instead of "unshift" to allow for binary search binaryCloseArr (array<float>): array containing historical close points, uses "push" instead of "unshift" to allow the correct binaryOpenArr (array<float>): array containing historical optn points, uses "push" instead of "unshift" to allow the correct atrTFarr (array<float>): array containing historical user-selected TF atr points openArr (array<float>): array containing historical open points