Pine script error "Syntax error at input 'symbol' - syntax-error

I am new to pinescript and I have an open source script for tradingview.
But I'm struggling with a syntax error and haven't found a solution yet.
I would appreciate if someone could help me with this problem.
Syntax error at input 'symbol'
//#version=4
study(title='Moving Average Cross', shorttitle='Moving Average Cross', overlay=true, precision=6, max_labels_count=500, max_lines_count=500)
f_ma(smoothing, [symbol=src]src[/symbol], length) =>
iff(smoothing == "RMA", rma([symbol=src]src[/symbol], length),
iff(smoothing == "SMA", [__tag__=simplemovingaverage]sma[/__tag__] ([symbol=src]src[/symbol], length)),
iff(smoothing == "EMA", [__tag__=ema]ema[/__tag__] ([symbol=src]src[/symbol], length), [symbol=src]src[/symbol]))

This is erroneous copypasta with html tags.
iff function is hard for newbies, try using Pine V5 and its switch function:
//#version=5
indicator("My script")
string i_maType = input.string("EMA", "MA type", options = ["EMA", "SMA", "RMA", "WMA"])
f_ma(smoothing, src, length) =>
float ma = switch smoothing
"EMA" => ta.rma(src, length)
"SMA" => ta.sma(src, length)
"RMA" => ta.ema(src, length)
// Default used when the three first cases do not match.
=> ta.wma(src, length)
ma
s = f_ma(i_maType, close, 20)
plot(s)
here is V5 manual.

Related

warning use of undefined constant.. this will throw an error in future version of php

This should be enough for someone to correct my issue - I'm very much a newbie at this.
It's a short bit of code to strip spaces from the ends of strings submitted in forms.
The warning message is saying "Use of undefined constant mystriptag - assumed 'mystriptag' (this will throw an error..."
How should I change this?
function mystriptag($item)
{
$item = strip_tags($item);
}
array_walk($_POST, mystriptag);
function t_area($str){
$order = array("\r\n", "\n", "\r");
$replace = ', ';
$newstr = str_replace($order, $replace, $str);
return $newstr;
}
You must use single quote in order for PHP to understand your parameter mystriptag.
So the correct line would be :
array_walk($_POST, 'mystriptag');

"Parsing error: Unexpected token )" with bot

I'm making a discord bot and I'm trying to make a timer that every second it edits the message to time + 1 second like a real clock (Like 0:00). I'm a noob at this. This is my script:
const Discord = require("discord.js");
exports.run = async(bot, message, args) => {
let timerMessage = await message.channel.send('0');
for (i = 0, 10000000000) {
setTimeout(function() {
timerMessage.edit(timerMessage + 1);
}, 1000);
}
}
module.exports.help = {
name: "timer"
}
I have an error and it says: "Parsing error: Unexpected token )"
I would really appreciate it if you would help me with my problem, Thanks!
(Btw I'm using it in Glitch on Google Chrome)
It says that there's an unexpected token ) because you wrote your loop like this:
for (i = 0, 10000000000) {...}
You forgot to add the third argument (usually i++). Also, if you want it to run 10000000000 times you should write a comparison:
for (let i = 0; i < 10000000000; i++) {...}
I see what you're trying to achieve, but I would do it in a simpler way, using setInterval() instead of setTimeout().
setInterval(() => {
timerMessage.edit(timerMessage + 1);
}, 1000);
You seem to be missing a right parenthesis after the setTimeout function. I am not entirely familiar with what you are doing, but I would try something like this :
const Discord = require("discord.js");
exports.run = async (bot, message, args) => {
let timerMessage = await message.channel.send('0');
for (i = 0, 10000000000) {
setTimeout(function()) {
timerMessage.edit(timerMessage + 1);
}, 1000);
}
}
module.exports.help = {
name: "timer";
}
Although this should (maybe) replace the missing parenthesis in your code, it seems to have many other issues. For example, your for loop does not make much sense. Normally a for loop would look something like this (to repeat a certain number of times in java) :
for (int i = 0; i < 10; i++) {
System.out.println(i);
} // will print numbers 0-9, repeat 10 times
The whole chunk of code with the setTimeout bit seems to be messed up... It would help to have a little more context on what you are trying to do / some commenting in your code.
If you are trying to get into coding, I'd recommend something much more basic or some tutorials. CodingTrain has great coding videos on youtube and you will learn a ton no matter what language you go with. Hope this helped...

Validation of dynamic text in testing

I am trying to validate a pin code in my application. I am using Katalon and I have not been able to find an answer.
The pin code that I need to validate is the same length but different each time I run the test and looks like this on my page: PIN Code: 4938475948.
How can I account for the number changing each time I run the test?
I have tried the following regular expressions:
assertEquals(
"PIN Code: [^a-z ]*([.0-9])*\\d",
selenium.getText("//*[#id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span")
);
Note: This was coded in Selenium and converted to Katalon.
In Katalon, use a combination of WebUI.getText() and WebUI.verifyMatch() to do the same thing.
E.g.
TestObject object = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[#id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span')
def actualText = WebUI.getText(object)
def expectedText = '4938475948'
WebUI.verifyMatch(actualText, expectedText, true)
Use also toInteger() or toString() groovy methods to convert types, if needed.
Editing upper example but to get this working
TestObject object = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[#id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span')
def actualText = WebUI.getText(object)
def expectedText = '4938475948'
WebUI.verifyMatch(actualText, expectedText, true)
This can be done as variable but in Your case I recommend using some java
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(9000000000) + 1000000000;
// this will also cover the bad PIN (above limit)
I'd tweak your regex just a little since your pin code is the same length each time: you could limit the number of digits that the regex looks for and make sure the following character is white space (i.e. not a digit, or another stray character). Lastly, use the "true" flag to let the WebUI.verifyMatch() know it should expect a regular expression from the second string (the regex must be the second parameter).
def regexExpectedText = "PIN Code: ([0-9]){10}\\s"
TestObject pinCodeTO = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[#id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span')
def actualText = WebUI.getText(pinCodeTO)
WebUI.verifyMatch(actualText, expectedText, true)
Hope that helps!

VBA to return RGB color of text

I have been able to return the RGB colour of text in a word document where the color has been picked using custom colours, but not when the standard colours are used. I initially used the below code:
Function GetRGBTest(Colour As Long) As String
GetRGBTest = "rgb(" & (Colour Mod 256) & "," & ((Colour \ 256) Mod 256) & "," & ((Colour \ 256 \ 256) Mod 256) & ")"
End Function
Sub TestColour()
MsgBox GetRGBTest(Selection.Font.Color)
End Sub
When using a standard colour, selection.font.color returns a negative value and the RGB value is incorrect.
I have tried editing it to have the following (Where Dict is a list of colorindex and respective rgb vals):
Function GetRGBTest(Colour As Long, colInd As Integer) As String
If Colour > 0 Then
GetRGBTest = "rgb(" & (Colour Mod 256) & "," & ((Colour \ 256) Mod 256) & "," & ((Colour \ 256 \ 256) Mod 256) & ")"
Else
colInd = LTrim(Str(colInd))
GetRGBTest = Dict.Item(colInd)
End If
End Function
Sub TestColour()
MsgBox GetRGBTest(Selection.Font.Color, Selection.Font.ColorIndex)
End Sub
Although I think that the ColorIndex returns a value that doesnt relate to the standard colours.
Does anyone have an idea how to transform these values into RGB vals?
I haven't been able to quickly Google up a reference, but if I recall correctly there are three possible data formats that Word will return a font colour in.
RGB Format
If the high byte is &H00 then the remaining three bytes represent red, green, and blue. This is the format you are familiar with and already handling.
Automatic Colour
If the value is &HFF000000 also known as -16777216 then the colour is set to automatic, and is usually black. Otherwise it assumes the default colour for the document.
Mysterious third negative format
If the high nibble of the high byte is &HD, that is to say if the first digit of the hexidecimal representation of the number is D, then it uses the Word colour scheme format.
For example, you might get &D500FFFF
The second nibble, &H5 in our example, matches up to a value in the enumeration WdThemeColorIndex. If you create a translation table translating from this enumeration to the MsoThemeColorSchemeIndex enumeration, you can then look up the basic colours in the document's ActiveDocument.DocumentTheme.ThemeColorScheme collection. Why are there are two enumerations with different index numbers for the same thing you ask? Good question! Moving on...
This is not the end of the story however! There are those last three remaining bytes to worry about! The next one, the low byte of the high word, I think it's easy. I believe it's always &H00. If you run into a different value for that byte... well, best of luck to you.
The last two bytes represent percentages that darken or lighten the value (respectively). Where &FF or 255 means no change and &h00 means 100%. The same as in the colour picker where you see things like "Accent 2, Lighter 60%". That by the way would be &HD500FF66, 5 being the index for Accent 2, &H66 being 60% in the lighter byte.
So here is a function that does not account for the lighter and darker values:
Public Function GetBasicRGB(color As Long) As String
Dim colorIndexLookup
Dim colorIndex As Integer
Dim finalColor As Long
colorIndexLookup = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 2, 1, 4, 3)
colorIndex = colorIndexLookup( _
((color And &HF000000) / &H1000000) _
+ LBound(colorIndexLookup))
finalColor = ActiveDocument.DocumentTheme.ThemeColorScheme(colorIndex)
GetBasicRGB = "rgb(" & (finalColor And &HFF) & "," & _
(finalColor / &H100 And &HFF) & "," & _
((finalColor And &HFF0000) / &H10000) & ")"
End Function
To account for the lighter and darker I believe you have to convert the RGB value to an HSL value then modify the L component by the % lighter or darker. Finally convert back to RGB. But I don't care to figure that out right now.
Thanks to AndASM for this awesome description of this particular problem. I've been writing a Perl program that was reading a word document using the Win32::OLE library. My goal was to output the document in a different format and found myself deeply troubled when I came across these indexed values. After being guided in the right direction, I ended up building a hash look up in Perl for these indexes. I stripped the hex string of everything else that seemed useless (like the &H00 byte) and constructed a search string that returned RGB values when fed through this hash map:
my %indexedColors = (
"ff0000" => [0,0,0],
"dcffff" => [255,255,255],
"dcf2ff" => [242,242,242],
"dcd9ff" => [217,217,217],
"dcbfff" => [191,191,191],
"dca6ff" => [166,166,166],
"dc80ff" => [128,128,128],
"ddffff" => [0,0,0],
"ddff80" => [127,127,127],
"ddffa6" => [89,89,89],
"ddffbf" => [64,64,64],
"ddffd9" => [38,38,38],
"ddfff2" => [13,13,13],
"deffff" => [238,236,225],
"dee6ff" => [221,217,195],
"debfff" => [196,188,150],
"de80ff" => [148,138,84],
"de40ff" => [74,68,42],
"de1aff" => [29,27,17],
"dfffff" => [31,73,125],
"dfff33" => [198,217,241],
"dfff66" => [141,179,226],
"dfff99" => [84,141,212],
"dfbfff" => [23,54,93],
"df80ff" => [15,36,62],
"d4ffff" => [79,129,189],
"d4ff33" => [219,229,241],
"d4ff66" => [184,204,228],
"d4ff99" => [149,179,215],
"d4bfff" => [54,95,145],
"d480ff" => [36,64,97],
"d5ffff" => [192,80,77],
"d5ff33" => [242,219,219],
"d5ff66" => [229,184,183],
"d5ff99" => [217,149,148],
"d5bfff" => [148,54,52],
"d580ff" => [99,36,35],
"d6ffff" => [155,187,89],
"d6ff33" => [221,217,195],
"d6ff66" => [214,227,188],
"d6ff99" => [194,214,155],
"d6bfff" => [118,146,60],
"d680ff" => [79,98,40],
"d7ffff" => [128,100,162],
"d7ff33" => [229,223,236],
"d7ff66" => [204,192,217],
"d7ff99" => [178,161,199],
"d7bfff" => [95,73,122],
"d780ff" => [64,49,82],
"d8ffff" => [75,172,198],
"d8ff33" => [218,238,243],
"d8ff66" => [182,221,232],
"d8ff99" => [146,205,220],
"d8bfff" => [49,132,155],
"d880ff" => [33,88,104],
"d9ffff" => [247,150,70],
"d9ff33" => [253,233,217],
"d9ff66" => [251,212,180],
"d9ff99" => [250,191,143],
"d9bfff" => [227,108,10],
"d980ff" => [152,72,6],
);
Hopefully no poor soul ever has to delve into the depths of Microsoft's backwards compatibility but just in case.

Error while inserting image in table using Prawn

I am working with Prawn to generate a pdf, I have to insert an image in a cell of a table.
My code is like this:
image = "path to file"
subject = [["FORMATIVE I "," SUMATIVE ","GRAPH"],
[formative_1,sumative, {:image => image}]
]
table subject
But, I get an error which says:
prawn/table/cell.rb:127:in `make': Content type not recognized: nil (ArgumentError)
How can I resolve this? Any help is greatly appreciated.
Cheers!
In the current version of Prawn 0.12.0 it is not possible to embed images in a Prawn::Table, but this feature seems to be under way, see here. At the moment you have to write your own table, something like
data = [[{:image => "red.png"},{:text => "Red"}],
[{:image => "blue.png"},{:text => "Blue"}]]
data.each_with_index do |row,i|
row.each_with_index do |cell,j|
bounding_box [x_pos,y_pos], :width => cell_width, :height => cell_height do
image(cell[:image], ...) if cell[:image].present?
text_box(cell[:text], ...) if cell[:text].present?
end
x_pos = (x_pos + cell_width)
end
y_pos = (y_pos - cell_height)
end
Prawn in version 0.12.0 doesn't give the possibility to insert image in a cell. Look at this for further information. It works on the next version 1.0.0.rc1. Just change your version. You can also use the tricky way, but I advise you not to do so.
The manual is available here.
The commit and explanation for that feature from the author. Here