Logger Library For Pinescript (Logging and Debugging)Library "LoggerLib"
This is a logging library for Pinescript. It is aimed to help developers testing and debugging scripts with a simple to use logger function.
Pinescript lacks a native logging implementation. This library would be helpful to mitigate this insufficiency.
This library uses table to print outputs into its view. It is simple, customizable and robust.
You can start using it's .log() method just like any other logging method in other languages.
//////////////////
USAGE
//////////////////
-- Recommended: Please Read The Documentation From Source Code Below. It Is Much More Readable There And Will Be Updated Along With Newer Versions. --
Importing the Library
---------------------
import paragjyoti2012/LoggerLib/ as Logger
.init() : Initializes the library and returns the logger pointer. (Later will be used as a function parameter)
.initTable: Initializes the Table View for the Logger and returns the table id. (Later will be used as a function parameter)
parameters:
logger: The logger pointer got from .init()
max_rows_count: Number of Rows to display in the Logger Table (default is 10)
offset: The offset value for the rows (Used for scrolling the view)
position: Position of the Table View
Values could be:
left
right
top-right
(default is left)
size: Font Size of content
Values could be:
small
normal
large
(default is small)
hide_date: Whether to hide the Date/Time column in the Logger (default is false)
returns: Table
example usage of .initTable()
import paragjyoti2012/LoggerLib/1 as Logger
var logger=Logger.init()
var logTable=Logger.initTable(logger, max_rows_count=20, offset=0, position="top-right")
-------------------
LOGGING
-------------------
.log() : Logging Method
params: (string message, |string| logger, table table_id, string type="message")
logger: pass the logger pointer from .init()
table_id: pass the table pointer from .initTable()
message: The message to log
type: Type of the log message
Values could be:
message
warning
error
info
success
(default is message)
returns: void
///////////////////////////////////////
Full Boilerplate For Using In Indicator
///////////////////////////////////////
P.S: Change the | (pipe) character into square brackets while using in script (or copy it from the source code instead)
offset=input.int(0,"Offset",minval=0)
size=input.string("small","Font Size",options=|"normal","small","large"|)
rows=input.int(15,"No Of Rows")
position=input.string("left","Position",options=|"left","right","top-right"|)
hide_date=input.bool(false,"Hide Time")
import paragjyoti2012/LoggerLib/1 as Logger
var logger=Logger.init()
var logTable=Logger.initTable(logger,rows,offset,position,size,hide_date)
rsi=ta.rsi(close,14)
|macd,signal,hist|=ta.macd(close,12,26,9)
if(ta.crossunder(close,34000))
Logger.log("Dropped Below 34000",logger,logTable,"warning")
if(ta.crossunder(close,35000))
Logger.log("Dropped Below 35000",logger,logTable)
if(ta.crossover(close,38000))
Logger.log("Crossed 38000",logger,logTable,"info")
if(ta.crossunder(rsi,20))
Logger.log("RSI Below 20",logger,logTable,"error")
if(ta.crossover(macd,signal))
Logger.log("Macd Crossed Over Signal",logger,logTable)
if(ta.crossover(rsi,80))
Logger.log("RSI Above 80",logger,logTable,"success")
////////////////////////////
// For Scrolling the Table View
////////////////////////////
There is a subtle way of achieving nice scrolling behaviour for the Table view. Open the input properties panel for the table/indicator. Focus on the input field for "Offset", once it's focused, you could use your mouse scroll wheel to increment/decrement the offset values; It will smoothly scroll the Logger Table Rows as well.
/////////////////////
For any assistance using this library or reporting issues, please write in the comment section below.
I will try my best to guide you and update the library. Thanks :)
/////////////////////
Datawindow
BEST Dollar Cost AverageHello traders
This is an upgraded version of my Dollar Cost Average (Data Window) script
1 - What is Dollar-Cost Averaging ( DCA )?
Dollar-Cost Averaging is a strategy that allows an investor to buy the same dollar amount of investment at regular intervals. The purchases occur regardless of the asset's price.
I hope you're hungry because that one is a biggie and gave me a few headaches. Happy that it's getting out of my way finally and I can offer it
🔸 This indicator will analyze for the defined date range, how a dollar-cost average ( DCA ) method would have performed (green panel) versus investing all the hard earnt money at the beginning (orange panel)
=> green versus orange
2- What's on the menu today?
My indicator works with all asset classes and with the daily/weekly/monthly inputs.
⚠️⚠️⚠️ However, results are only visible on the DAILY timeframe chart
As always, let's review quickly the different fields so that you'll understand how to use it (and I won't get spammed with questions in DM ^^)
🔸 Use current resolution: if checked will use the resolution of the chart
🔸 The timeframe used for DCA: different timeframe to be used if Use current resolution is unchecked
🔸 Amount invested in your local currency: The amount in Fiat money that will be invested at each period selected above
🔸 Starting Date
🔸 Ending Date
🔹 The script screenshot shows a DCA with 100 USD invested daily from 01.01.2017 to 01.28.2020
3- Bonus (DATA WINDOW)
🔸 Please check this screenshot to understand what you're supposed to see: Data window
And a quick video that I did months ago explaining how we can use this data window effectively
4 - Specifications used
I got the idea from this website dcabtc.com and the result shown by this website and my indicator are very interesting in general and for your own trading
The formula used for the DCA calculation is the one from the Investopedia website.
Best regards and best of luck
Dave
BEST IVFTHello traders
This is a Pine adaptation of this FXCM LUA indicator
Seems to be made mostly for tick data (< 1 min timeframe) and advanced scalpers
Always interesting to see that Pinescript is much easier than most of other trading programming languages out there :)
PS
You might like checking the data window panel from TradingView and mouseover your cursor on the chart. It will update the debug/historical data in real-time
imgur.com
Best,
Dave