TradingView
kurtsmock
2 juin 2022 19:24

[LIB] Array / Matrix Display 

E-mini S&P 500 FuturesCME

Description

Library "ArrayMatrixHUD"
Show Array or Matrix Elements In Table

For Arrays: Set the number of rows you want the data displayed in and it will generate a table, calculating the columns based on the size of the array being displayed.
For Matrix: It will automatically match the Rows and Columns to the values in the matrix.

Note: On the left, the table shows the index of the array/matrix value starting at 1. So, to call that value from inside the array, subtract 1 from the index value to the left. For matrices, keep in mind that the row and column are also starting at one when trying to call a value from the matrix. The numbering of the values on the left is for display purposes only.

viewArray(_arrayName, _pos, _txtSize, _tRows)
  Array Element Display (Supports float, int, string, and bool)
  Parameters:
    _arrayName: ID of Array to be Displayed
    _pos: Position for Table
    _txtSize: Size of Table Cell Text
    _tRows: Number of Rows to Display Data In (columns will be calculated accordingly)
  Returns: A Display of Array Values in a Table

viewMatrix(_matrixName, _pos, _txtSize)
  Matrix Element Display (Supports float, int, string, and bool)
  Parameters:
    _matrixName: ID of Matrix to be Displayed
    _pos: Position for Table
    _txtSize: Size of Table Cell Text
  Returns: A Display of Matrix Values in a Table

Notes de version

v2
Updates.
2 New Optional Parameters:
  • _fillCond (Optional) Conditional statement. Function displays array only when true. For instances where indices are na. Default = true, indicating array size is set at bar_index 0.
  • _offset (Optional) Use to view historical array states. Default = 0, displaying realtime bar.


Displays <float>, <int>, <string>, and <bool> arrays and matrices.

Notes de version

v3 This is a huge release. Complete game changer for me anyway. Now we have ezpz debugging.

This addition to the library adds debugging capability to anything your heart desires in your script.
There are two debug functions: debug() and debugs().
debug() is for Conditionals, variable outputs, variable updates. It converts the designated variable to a string and will display additional information defined by _msg argument.
This function does not need a variable name.
Example:
debug(0,0, _matrixName, variable, "Message")


debugs() is for scope testing. If you need to understand which scopes are triggering, this function will cause its scope location to show up in the panel when that scope is accessed. For this to work, you have to put the function inside of the scope you want to analyze.
This function does not need a variable name.
Example:
debugs(0,1, _matrixName, "Message")


Added:
debug(_col, _row, _name, _value, _lb, _ip)
  Debug Variables in Matrix
  Parameters:
    _col: (int) Assign Column
    _row: (int) Assign Row
    _name: (simple matrix) Matrix Name
    _value: (string) Assign variable as a string (str.tostring())
    _lb: (string) Constant label (optional)
    _ip: (int) (default 1) 1 for continuous updates. 2 for barstate.isnew updates. 3 for barstate.isconfirmed updates. -1 to only add once
  Returns: Returns Variable _value output and _msg formatted as {'_msg: variableOutput'} in designated column and row of debug panel

debugs(_col, _row, _name, _msg)
  Debug Scope in Matrix - Identify When Scope Is Accessed
  Parameters:
    _col: (int) Column Number
    _row: (int) Row Number
    _name: (simple matrix) Matrix Name
    _msg: (string) Message
  Returns: Message appears in debug panel using _col/_row as the identifier
Commentaires
A_Traders_Edge
Reason for the coins is in the comments. Sorry it is so few...its all I've ever had from receiving them from another user. Peace brother!!!
A_Traders_Edge
WOW. Thats intense! Great job. Now, its just.....trying to wrap my head around it.
kurtsmock
@chasinalts, Lets see if I can simplify it.
You have 2 things going on here. One: you can look inside of arrays/matrices. You add values to these things and you often hope they are being added correctly. This gives you a look inside of them.
For Arrays:
You can look inside float, int, string, and bool arrays with the same function. So its all the same as long as its one of those 4 array types.
To see inside an array with data you've added, you just add a function with no variable name in the script.
You add the import copy/paste to the top of the script:
import kurtsmock/ArrayMatrixHUD/3 as sa

Then on the last line of the script you add:
sa.viewArray(theNameOfTheArray, thePositionYouWantTheArrayIn, TheTxtSize, TheNumberOfRowsYouWantTheDataToDisplayOn, aConditionOnWhichYouAreSureThereIsDataInTheArray, Offset:IfyouWantToSeePriorInstancesOfTheArray)

You do not have to use the last two arguments if you don't need them. But for _fillCond I often use bar_index > 100. Or some number that, by which I know the array has something in it.

If you ask for this display and your array is empty it will throw an error. Offset is basically to view prior array instances. It allows you to scroll backwards through the previous array states. I recommend that this is an input in your settings menu if you want it.

For Matrices:
Same as array, but.. on that bottom row your function is:
sa.viewMatrix(NameOfMatrix, PositionOfMatrix, TxtSize, FillCondition, Offset),

With Matrices you have rows and columns pre-defined so you don't need to tell it how many rows you want to see the data in.
Again, back to arrays, it could be 100 values. They'll stretch off the chart if you don't separate them in rows but Matrices have rows and columns so rows is inherently defined.

That said... then we go to the debugger.
Lets use the example that you have a true/false bool variable. You want to know when it fires off as true. First you create a matrix early in the script:
console = matrix.new<string>(rows, cols," ")
You are telling it how many rows you want and how many columns you want and you're prefilling them with blank strings.
Now you have your variables you want to see on the chart. After the variable has been declared and impacted by some logic you just call that variable using the function.
debug(0 TheColumn,0 TheRow, TheMatrixName Console, theVariableOutput, "THEMESSAGE")

There is the _ip argument, which you can use if you only want the value to update occasionally vs continuously. By default its 1 and if you don't declare it in the function it will be 1

Then down at the last line of the script again we're going to use
sa.viewMatrix(NameOfMatrix, PositionOfMatrix, TxtSize, FillCondition, Offset),

the name of the matrix is going to be whatever matrix you're assigning these debug functions to.

The script will map them to a row and column defined by the debug() function and display them on the screen
kurtsmock
@chasinalts, Last piece.. the debugs() function. Lets say there is an 'if' statement that you want to track when it triggers. It will say something like
if open>close changeMyVariableTo := newValue

What you'll do is add the debugs() function into this local scope and it will only fire when the if statement is true.
You assign it a row and column just like you do in the debug(), The only difference is that this becomes the scope identifier. So:
if open>close changeMyVariableTo := newValue debugs(0 theColumn, 0 theRow, theNameOfTheMatrix, "aMessageIfDesired")

You do not have to put a message in. If you do not it will just tell you the row and column number which you can match to the local scope the function is in.
It will show up in the table on bars that the 'if' statement is true. If the 'if statement' is not true, the cell on the table will be left blank.

At the end of the script you are using the viewMatrix() again just as in the previous example and you'll get a debug window to use with offset or replay.

You can see in the thumbnail you don't even have to have a variable you're defining, you can make headings too if you have as many conditions to test as I do in my backtesting engine
A_Traders_Edge
@kurtsmock, Kurt, I just had to come back and tell you this and I'm SO sorry it took so long to do so....it's about all the assistance you gave when I mentioned "Now I just need to wrap my head around it". You went above and beyond in your response and I not only wanted to thank you for that but also to tell you that this script is in my favorites section in my internet browser bc I've come back to it SOOOO many times now to get it to assist with SOOO MANY varieties of things spanning from assisting with errors with matrices/arrays when I couldn't figure out what the hell was going wrong, to simply needing to understand what the array looked like when learning arrays. It has honestly been the #1 script I have gone back to to use. I just wanted to tell you all that so that you didn't think that all your efforts in your response went under-appreciated and unused. QUITE the contrary. I only have these coins bc someone else gave them to me, so thats why its so few but I felt I needed to show my appreciation and again apologize for not thanking you previously. So #kurtsmock, from the bottom of my heart...I apologize to you for not being decent enough to express my appreciation before and to thank you for all of your efforts with this amazingly useful script and even more so your response to my first comment. Its has nearly singlehandedly assisted in opening the door to understanding arrays/matrices when I didn't even consider using them before bc I could not understand them due to lack of visualization. You're the man.
kurtsmock
@chasinalts, I'm blessed by the kind words. Thanks for stopping back and letting me know that it worked out so well for you.
allanster
Looks very useful, thank you for sharing!
slowcoconut
holy moly
that's so epic -- glad you found the time to do this while building that new room/table.. thanks Kurt
kurtsmock
@slowcoconut, Thanks man. There's always gotta some time for coding.
KioseffTrading
Awesome work Kurt!!
Plus