sending Strategy data using Webhooks for Pinescript 4.0 - json

I am using Tradingview Pinescript 4.0.
This message was made with reference to :
https://stackoverflow.com/questions/66926863/combining-data-from-different-tradingview-4-0-indicators-for-the-purpose-of-crea
Basically, what I would like to do is use Tradingview 4.0 Pinescript Strategies with the Tradingview Webhook Alert system.
The closest I have seen that provides a hint a to how one can do this is found in this particular video (for a different product):
https://support.mudrex.com/hc/en-us/articles/360050211072-Automating-an-alert-from-a-Strategy-on-TradingView
It would use something like the "comment" below:
// strategy.entry(id=tostring(randomNumber), long=false,
comment="{"id" : " + tostring(randomNumber) + ", "action" :
"reverse_short_to_long"}")
I need to send JSON from the Strategy as part of the Web alert. According to the video, one would use something like:
{{ strategy.comment }}
Are there any solid examples as to how this could be done?

Tradingview sends the alert as JSON if the string is formatted as JSON. I suggest using the alert() function instead of alertcondition. It's then easy to construct a string in a JSON format however you want. Here's a nasty function I use to generate alerts.
customalert(_name, _symbol, _type, _asset_type, _action, _risk_value, _risk_percent, _sl, _tp1,_tp1_percent, _tp2, _tp2_percent, _message) =>
alert_array = array.new_string()
if _name != ''
array.push(alert_array, '"Name": "' + _name + '"')
if _symbol != ''
array.push(alert_array, '"Symbol": "' + _symbol + '"')
if _type != ''
array.push(alert_array, '"Type": "' + _type + '"')
if _asset_type != ''
array.push(alert_array, '"Asset Type": "' + _asset_type + '"')
if _action != ''
array.push(alert_array, '"Action": "' + _action + '"')
if _risk_value != 0
array.push(alert_array, '"Risk Value": "' + tostring(_risk_value) + '"')
if _risk_percent != 0
array.push(alert_array, '"Risk Percentage": "' + tostring(_risk_percent) + '"')
if _tp1 != 0
array.push(alert_array, '"Take Profit 1 Level": "' + tostring(_tp1) + '"')
if _tp1_percent != 0
array.push(alert_array, '"Take Profit 1 Percent": "' + tostring(_tp1_percent) + '"')
if _tp2 != 0
array.push(alert_array, '"Take Profit 2 Level": "' + tostring(_tp2) + '"')
if _tp2_percent != 0
array.push(alert_array, '"Take Profit 2 Percent": "' + tostring(_tp2_percent) + '"')
if _sl != 0
array.push(alert_array, '"Stop Loss Level": "' + tostring(_sl) + '"')
if _message != ''
array.push(alert_array, '"Message": "' + _message + '"')
alertstring = '{' + array.join(alert_array,', ') + '}'
alert(alertstring, alert.freq_once_per_bar_close)
You don't need to do anything complex though, the most important line is the alertstring = '{' + array.join(alert_array,', ') + '}'
You just need to make sure the string starts and ends with curly braces and is properly formatted JSON.
Could just as easily:
alert('{"Symbol": "' + syminfo.ticker + '", "Action": "Entry"}', alert.freq_once_per_bar_close)
You just need to be careful with your double and single quotes.
Also, this is explained if you go to set up an alert and click the option to learn more about alerts, at least the fact that formatting as JSON is what determines whether the alert is sent as text or JSON. As for the {{}}s, those are used to send a limited set of values for use with the alertcondition() function, and I don't really see an advantage to using them vs tostring() with alert().
Another thing to keep in mind is that this necessitates sending your data as strings, so you will need to make sure to convert back to ints and floats as necessary on the server side.

Related

Why is setting SQL variable is creating an error?

Following SQL statement is creating an error with message :
"Message: Fatal error encountered during command execution."
"Inner exception: Parameter '#LastUserID' must be defined."
If I directly use LAST_INSERT_ID() instead of LastUserID, it always returns zero (hence fails at second insert) when executed like this.
I don't see my syntax is different than in mySQL document.
Could some one help me ?
string Query = #"INSERT INTO login (" +
"LOGIN_EMAIL," +
"LOGIN_PASSWORD," +
"LOGIN_SALT," +
"LOGIN_LAST_LOGIN_DATE," +
// "LOGIN_LAST_LOGIN_LOCATION," +
"LOGIN_ACCOUNT_STATUS," +
"LOGIN_LOGIN_ATTEMPTS," +
"LOGIN_CREATED_DATE) " +
"VALUES (" +
"#Parameter2," +
"#Parameter3," +
"#Parameter4," +
"#Parameter5," +
// "#Parameter6," +
"#Parameter6," +
"#Parameter7," +
"#Parameter8); " +
"SET #LastUserID = LAST_INSERT_ID(); " +
"INSERT INTO user_role (" +
"USER_ROLE_USER_ID," +
"USER_ROLE_ROLE," +
"USER_ROLE_STATUS," +
"USER_ROLE_CREATED_DATE) " +
"SELECT " +
"#LastUserID," +
"#Parameter9," +
"#Parameter10," +
"#Parameter11 " +
"FROM dual WHERE NOT EXISTS (SELECT USER_ROLE_USER_ID FROM user_role " +
"WHERE USER_ROLE_USER_ID = #LastUserID AND USER_ROLE_ROLE = #Parameter9)";
MySqlCommand oCommand = new MySqlCommand(Query, oMySQLConnecion);
oCommand.Transaction = tr;
Create a procedure in which you first do your insert, cache the last inserted id, do the other insert and let it print out your parameters with a bool if your last insert worked or not. That way you can debug it properly.
In general you should avoid concatinating strings to generate sql-commands or you might get troubles with parameters containing unexpected characters or be hit by a injection.
Simple fix : Replace "$LastUserID" with "$'LastUserID'". The ephostophy makes the difference.

JSON parsing of finance.google.com result

I'm not getting how to parse finance.google.com results, i.e. I got
[
{
"id":"787381",
"t":"HDFC",
"e":"NSE",
"l":"1,424.00",
"l_fix":"1424.00",
"l_cur":"₹1,424.00",
"s":"0",
"ltt":"3:46PM GMT+5:30",
"lt":"Sep 23, 3:46PM GMT+5:30",
"lt_dts":"2016-09-23T15:46:54Z",
"c":"+10.75",
"c_fix":"10.75",
"cp":"0.76",
"cp_fix":"0.76",
"ccol":"chg",
"pcls_fix":"1413.25"
}
]
when I made call to this endpoint using httpopenConnection method, I didn't get anything returned because I couldn't find the JSON object name and i am going to use the result in my android app.
Assuming js is your tool of choice, and you since you don't say what you're trying to do with the array, just assign to a var named obj and you can access it - loop as required...
<!DOCTYPE HTML>
<html>
<body>
<h2>Manage a JSON Object in JavaScript</h2>
<p id="demo"></p>
<script>
var obj = [{"id":"787381","t":"HDFC","e":"NSE","l":"1,424.00","l_fix":"1424.00","l_cur":"₹1,424.00","s":"0","ltt":"3:46PM GMT+5:30","lt":"Sep 23, 3:46PM GMT+5:30","lt_dts":"2016-09-23T15:46:54Z","c":"+10.75","c_fix":"10.75","cp":"0.76","cp_fix":"0.76","ccol":"chg","pcls_fix":"1413.25"}];
document.getElementById("demo").innerHTML =
obj[0].id + "<br>" +
obj[0].t + "<br>" +
obj[0].e + "<br>" +
obj[0].l + "<br>" +
obj[0].l_fix + "<br>" +
obj[0].l_cur + "<br>" +
obj[0].s + "<br>" +
obj[0].ltt + "<br>" +
obj[0].lt + "<br>" +
obj[0].lt_dts + "<br>" +
obj[0].c + "<br>" +
obj[0].c_fix + "<br>" +
obj[0].cp + "<br>" +
obj[0].cp_fix + "<br>" +
obj[0].ccol + "<br>" +
obj[0].pcls_fix + "<br>";
</script>
</body>
</html>
Resulting output to browser is:
Accessing a JSON Object in JavaScript
787381
HDFC
NSE
1,424.00
1424.00
₹1,424.00
0
3:46PM GMT+5:30
Sep 23, 3:46PM GMT+5:30
2016-09-23T15:46:54Z
+10.75
10.75
0.76
0.76
chg
1413.25

Why CurrentApp::AppId take so long in Windows Phone 10?

I have a windows 8 universal project and have a function to get APP ID,
The following function works well in Windows Phone 8.1
Platform::Guid appId = Windows::ApplicationModel::Store::CurrentApp::AppId;
however, it spent around 40s in Windows Phone 10.
From MSDN, only the Metadata is different,
May I know is it caused by the metadata? And how to solve it?
To instead of using AppID, you might use the following code,
Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
Windows::ApplicationModel::PackageId^ packageId = package->Id;
Windows::ApplicationModel::PackageVersion version = packageId->Version;
Platform::String^ output =
"Name: \"" + packageId->Name + "\"\n" +
"Version: " + version.Major.ToString() + "."
+ version.Minor.ToString() + "."
+ version.Revision.ToString() + "."
+ version.Build.ToString() + "\n" +
"Architecture: " + packageId->Architecture.ToString() + "\n" +
"ResourceId: \"" + packageId->ResourceId + "\"\n" +
"Publisher: \"" + packageId->Publisher + "\"\n" +
"PublisherId: \"" + packageId->PublisherId + "\"\n" +
"FullName: \"" + packageId->FullName + "\"\n" +
"FamilyName: \"" + packageId->FamilyName + "\"\n" +
"IsFramework: " + package->IsFramework.ToString();
Sample output from device
Output:
Name: "f3e02737-ddfa-47a0-a837-37ee53459898"
Version: 1.0.0.0
Architecture: Arm
ResourceId: ""
Publisher: "CN=heefan"
PublisherId: "gsbawe9kfjm1p"
FullName: "f3e02737-ddfa-47a0-a837-37ee53459898_1.0.0.0_arm__gsbawe9kfjm1p"
FamilyName: "f3e02737-ddfa-47a0-a837-37ee53459898_gsbawe9kfjm1p"
IsFramework: false
I also have no idea why AppID take long time to compute.

SSRS expression to get first character from string

I am having a field with string values as "First Middle Last" and i want to show the initial characters from this string as "FML"
how can i do it in terms of ssrs expression ?
Assuming the field MyString always has 3 words the following will find the first character of the First, Second and Last words. This admittedly doesn't handle instances where there are more or less than 3 words, but hopefully should get you started if you require more finesse.
=Left(Fields!MyString.Value, 1) + " " +
Left(Mid(Fields!MyString.Value, InStr(Fields!MyString.Value, " ") + 1), 1) + " " +
Left(Mid(Fields!MyString.Value, InStrRev(Fields!MyString.Value, " ") + 1), 1)
Edit
To cope with the possiblity of only two words (as suggested in the commetns below) a check for the index of the spaces could be used to ensure that they are not the same, and thus 3 words exist. This would make the code as follows
=Left(Fields!MyString.Value, 1) + " " +
Left(Mid(Fields!MyString.Value, InStr(Fields!MyString.Value, " ") + 1), 1) +
iif(InStrRev(Fields!MyString.Value, " ") > InStr(Fields!MyString.Value, " "),
" " + Left(Mid(Fields!MyString.Value, InStrRev(Fields!MyString.Value, " ") + 1), 1),
"")

SSIS expression to convert string to date

Using SQL Server 2008, Visual Studio 2008.
Trying to convert the data from a string column into a derived Date column.
The string can be in two formats, either : "dd/mm/yy" (where century 20 can be assumed), or "dd/mm/yyyy" . e.g. "02/05/12", "23/12/02", "13/08/2012".
So I tried an expression like this for a Derived column :
DateReceived == "" ? NULL(DT_DATE) : (DT_DATE)((LEN(RTRIM(DT_DATE)) == 10 ? SUBSTRING(DateReceived,7,4) : ("20" + SUBSTRING(DateReceived,7,2))) + "-" + SUBSTRING(DateReceived,4,2) + "-" + SUBSTRING(DateReceived,1,2))
but Visual Studio gives error :
"The expression was not valid, or there is an out-of-memory error".
It accepts a simpler expression like :
DateReceived == "" ? NULL(DT_DATE) : (DT_DATE)("20" + SUBSTRING(DateReceived,7,2) + "-" + SUBSTRING(DateReceived,4,2) + "-" + SUBSTRING(DateReceived,1,2))
but this expression will only work for "dd/mm/yy" format.
What am I doing wrong ? Thanks.
Never mind, the error was due to a typo. (Was calling RTRIM on the column type, not column name).
The following works :
DateReceived == "" ? NULL(DT_DATE) : (DT_DATE)((LEN(RTRIM(DateReceived)) == 10 ? SUBSTRING(DateReceived,7,4) : ("20" + SUBSTRING(DateReceived,7,2))) + "-" + SUBSTRING(DateReceived,4,2) + "-" + SUBSTRING(DateReceived,1,2))