Intra-Candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EsIstTurnt

//@version=5
indicator("Intra-Bars",overlay=true)
//Inputs
numbers           = input.bool(false,"Count Levels")
Sections          = input.int(6,"# of Lower Timeframe Candles",minval=2,maxval=6)
upCol             = input.color(#acfb00)
dnCol             = input.color(#ff0000)
candleTransparency=input.int(50)
textTransparency  =input.int(30)
tf=timeframe.multiplier/Sections<=1? timeframe.isseconds?na:
      timeframe.isminutes?str.tostring(math.round(timeframe.multiplier/Sections*60))+"S":
      timeframe.isintraday?str.tostring(math.round(timeframe.multiplier/Sections*60)):
      timeframe.isdaily?str.tostring(math.round(timeframe.multiplier/Sections*24))+"H" :
      timeframe.isweekly?str.tostring(math.round(timeframe.multiplier/Sections*7))+"D":
      str.tostring(math.round(timeframe.multiplier/Sections*4.3))+"W": timeframe.isseconds?str.tostring(math.round(timeframe.multiplier/Sections))+"S":
      timeframe.isminutes?str.tostring(math.round(timeframe.multiplier/Sections)):
      timeframe.isintraday?str.tostring(math.round(timeframe.multiplier/Sections)*60):
      timeframe.isdaily?str.tostring(math.round(timeframe.multiplier/Sections))+"D" :
      timeframe.isweekly?str.tostring(math.round(timeframe.multiplier/Sections))+"W":
      str.tostring(math.round(timeframe.multiplier/Sections))+"M" 
//Script
[IntraOpen,intraHigh,intraLow,intraClose] = request.security_lower_tf(         //                                     \✦ - Lower timeframe is selected according 
  syminfo.tickerid,                           //                                                                       \ to the current timeframe.multiplier value       
  tf, [open,high,low,close]         //                                                                         \     Candles" selected in settings.     
  )                                           //                                                                          \
Close_0 = if array.size(intraClose)>0//                                                                                          \
    array.get(intraClose,0)    //                                                                                           \
Close_1 = if array.size(intraClose)>1//                                                                                            \ 
    array.get(intraClose,1)    //                                                                                             \  
Close_2 = if array.size(intraClose)>2//                                         Get the closing price for each Intrabar----------    ✦ - Check if array size is large enough
    array.get(intraClose,2)    //                                                                                             / then get the closing value from each
Close_3 = if array.size(intraClose)>3//                                                                                            /      Intra-Bar from the array created
    array.get(intraClose,3)    //                                                                                           /   
Close_4 = if array.size(intraClose)>4//                                                                                          /             
    array.get(intraClose,4)    //                                                                                         /
Close_5 = if array.size(intraClose)>5//                                                                                          /
    array.get(intraClose,5)    //                                                                                         /
Close_6 = if array.size(intraClose)>6//                                                                                        /
    array.get(intraClose,6)    //                                                                                       /

//Do the same for high and low values 
High_0 = if array.size(intraHigh)>0//
    array.get(intraHigh,0)    //      
High_1 = if array.size(intraHigh)>1//
    array.get(intraHigh,1)    //      
High_2 = if array.size(intraHigh)>2//
    array.get(intraHigh,2)    //      
High_3 = if array.size(intraHigh)>3//
    array.get(intraHigh,3)    //      
High_4 = if array.size(intraHigh)>4//
    array.get(intraHigh,4)    //      
High_5 = if array.size(intraHigh)>5//
    array.get(intraHigh,5)    //      
High_6 = if array.size(intraHigh)>6//
    array.get(intraHigh,6)    //      

Low_0 = if array.size(intraLow)>0//
    array.get(intraLow,0)    //      
Low_1 = if array.size(intraLow)>1//
    array.get(intraLow,1)    //      
Low_2 = if array.size(intraLow)>2//
    array.get(intraLow,2)    //      
Low_3 = if array.size(intraLow)>3//
    array.get(intraLow,3)    //      
Low_4 = if array.size(intraLow)>4//
    array.get(intraLow,4)    //      
Low_5 = if array.size(intraLow)>5//
    array.get(intraLow,5)    //      
Low_6 = if array.size(intraLow)>6//
    array.get(intraLow,6)    //      

color(o,c,t)=> color.new(o<c?upCol:dnCol,t)//-Color Function

//                                                                               
plotchar(numbers?array.size(intraClose)>=0?Close_0:na:na,"Close #1",size=size.tiny,//   \
  char="1",location=location.absolute,color=color(open,Close_0,textTransparency))//    \                                                    
plotchar(numbers?array.size(intraClose)>=1?Close_1:na:na,"Close #2",size=size.tiny,//     \
  char="2",location=location.absolute,color=color(Close_0 ,Close_1,textTransparency))//      \    
plotchar(numbers?array.size(intraClose)>=2?Close_2:na:na,"Close #3",size=size.tiny,//       \
  char="3",location=location.absolute,color=color(Close_1 ,Close_2,textTransparency))//        \  
plotchar(numbers?array.size(intraClose)>=3?Close_3:na:na,"Close #4",size=size.tiny,//         - Check the input.bool "numbers" 
  char="4",location=location.absolute,color=color(Close_2 ,Close_3,textTransparency))//        / and if true mark each of the close 
plotchar(numbers?array.size(intraClose)>=4?Close_4:na:na,"Close #5",size=size.tiny,//       /   values with it's corresponding # 
  char="5",location=location.absolute,color=color(Close_3 ,Close_4,textTransparency))//      /
plotchar(numbers?array.size(intraClose)>=5?Close_5:na:na,"Close #6",size=size.tiny,//     /
  char="6",location=location.absolute,color=color(Close_4 ,Close_5,textTransparency))//    /    
plotchar(numbers?array.size(intraClose)>=6?Close_6:na:na,"Close #7",size=size.tiny,//   /
  char="7",location=location.absolute,color=color(Close_5 ,Close_6,textTransparency))//  /  



//Candle Plots for each lower time frame candle 
plotcandle(
  open,High_0,Low_0,Close_0,color=color(open,Close_0,candleTransparency)
  ,wickcolor=color(open ,Close_0,candleTransparency),
  bordercolor=color(open ,Close_0,candleTransparency/1.25)
  )

plotcandle(
  Close_0,High_1,Low_1,Close_1 ,color=color(Close_0 ,Close_1,candleTransparency)
  ,wickcolor=color(Close_0  ,Close_1,candleTransparency),
  bordercolor=color(Close_0  ,Close_1,candleTransparency/1.25)
  )

plotcandle(
  Close_1,High_2,Low_2,Close_2 ,color=color(Close_1 ,Close_2,candleTransparency)
  ,wickcolor=color(Close_1  ,Close_2,candleTransparency),
  bordercolor=color(Close_1  ,Close_2,candleTransparency/1.25)
  )

plotcandle(
  Close_2,High_3,Low_3,Close_3 ,color=color(Close_2 ,Close_3,candleTransparency)
  ,wickcolor=color(Close_2  ,Close_3,candleTransparency),
  bordercolor=color(Close_2  ,Close_3,candleTransparency/1.25)
  )

plotcandle(
  Close_3,High_4,Low_4,Close_4 ,color=color(Close_3 ,Close_4,candleTransparency)
  ,wickcolor=color(Close_3  ,Close_4,candleTransparency),
  bordercolor=color(Close_3  ,Close_4,candleTransparency/1.25)
  )

plotcandle(
  Close_4,High_5,Low_5,Close_5 ,color=color(Close_4 ,Close_5,candleTransparency)
  ,wickcolor=color(Close_4  ,Close_5,candleTransparency),
  bordercolor=color(Close_4  ,Close_5,candleTransparency/1.25)
  )

plotcandle(
  Close_5,High_6,Low_6,Close_6 ,color=color(Close_5 ,Close_6,candleTransparency)
  ,wickcolor=color(Close_5  ,Close_6,candleTransparency),
  bordercolor=color(Close_5  ,Close_6,candleTransparency/1.25)
  )


