Study forloop Star Diamond
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hapharmonic

//@version=5

//'Study forloop' pinescript Program to print star Diamond

//------Output------
//      *          |
//     * *         |
//    * * *        |
//   * * * *       |
//  * * * * *      |
// * * * * * *     |
//  * * * * *      |
//   * * * *       |
//    * * *        |
//     * *         |
//      *          |
//------------------


indicator("Study forloop Star Diamond",overlay=true)

rows = input.int(15,'Enter number of rows:',maxval=35)  //The number of rows displayed
i_tablePosition = input.string(title="Position", defval=position.middle_center, group="Table", options=[position.top_left, position.top_center, position.top_right, position.middle_left, position.middle_center, position.middle_right, position.bottom_left, position.bottom_center, position.bottom_right])

in_ = array.new_string(1)


//define a function to print star shape
star_pattern4(n) =>

    textin  = ""
    for i = 0 to n-1                 //Use outer for loop for rows
    
        for k=0 to i
            textin := textin+'*  '  //Store each star in the variable "textin"
        textin := textin+'\n'        //At the end of the forloop, start a new line. End of line after each row
    
    
    ////////Assemble the footer//////////
    for i = 0 to n
        for k=0 to n-i
            textin := textin+'*  ' 
        textin := textin+'\n'    
    ////////////////////////////////////
    
    array.set(in_,0,textin) 
    
star_pattern4(rows)


////==show label format==
// l1 = label.new(bar_index+5,close,text=array.get(in_,0),color=color.new(color.red,100),textcolor=color.white)
// label.delete(l1[1])

//Show data within an array.

for i = 0 to 1
    var table tdSetupTable = table.new(i_tablePosition, 1, 2, border_width=0)
    if i == 0
        table.cell(tdSetupTable, 0, 0, array.get(in_,0), text_color = color.white,text_valign=text.align_center)
    else
        T = "'Study forloop' pinescript Program to print star Diamond"
        table.cell(tdSetupTable, 0, 1, T, text_color = color.yellow,text_valign=text.align_center,text_size=size.large)


    
