Fair value gap coding in pinescript?
I have tried to write code but unable to add more functions on it.
//#version=5
indicator('Fair Value Gap Akash Mehto', overlay=true)
boxLength = input.int(title='boxLength', defval=6, group='General', inline='General')
boxTransparency = input.int(title='boxTransparency', defval=85, group='General', inline='General')
bullishFvg = low[0] > high[2]
bearishFvg = high[0] < low[2]
if bullishFvg
box.new(left=bar_index - 2, top=low[0], right=bar_index + boxLength, bottom=high[2], bgcolor=color.new(color.rgb(28, 202, 121), boxTransparency), text="FVG", text_size = "tiny", text_halign = text.align_right, text_color = color.green, border_color=color.new(color.green, boxTransparency))
if bearishFvg
box.new(left=bar_index - 2, top=low[2], right=bar_index + boxLength, bottom=high[0], bgcolor=color.new(color.rgb(240, 46, 46), boxTransparency), text="FVG", text_size = "tiny", text_halign = text.align_right, text_color = color.red, border_color=color.new(color.green, boxTransparency))
I have this code
int[,] array = new int[,]{ {34, 21, 32, 41, 25},
{14 ,42, 43, 14, 31},
{54, 45, 52, 42, 23},
{33, 15, 51, 31, 35},
{21, 52, 33, 13, 23} };
for (int i = 0; i < array.GetLength(1); i++)
{
for (int j = 0; j < array.GetLength(0); j++)
{
Console.Write(array[i, j] + " ");
}
Console.WriteLine();
}
and i need to find a specific number ( the treasure ).
For each value the ten's digit represents the row number and the unit's digit represents the column number of the cell containing the next clue.
Starting in the upper left corner (at 1,1), i have to use the clues to guide me search of the array. (The first three clues are 11, 34, 42).
The treasure is a cell whose value is the same as its coordinates.
The program should output the cells it visits during its search.
I did the simply way:
Console.WriteLine("The next clue is: {0}", array[0, 0]);
Console.WriteLine("The next clue is: {0}", array[2, 3]);
Console.WriteLine("The next clue is: {0}", array[3, 2]);
Console.WriteLine("The next clue is: {0}", array[0, 4]);
and so on, but the problem is, that if I change the array to set another route the program will output the wrong way. So the solution needs to be dynamic and find the treasure regardless of the array content.
My problem is that i don't know how to do to find the ten's digit of the numbers and the unit's digit.
Can anyone please help me with this?
To illustrate my comment: code below and Fiddle
(I've added a HashSet<int> to track which cells have already been visited and avoid ending up with an infinite loop)
int[,] array = new int[,]
{
{34, 21, 32, 41, 25},
{14 ,42, 43, 14, 31},
{54, 45, 52, 42, 23},
{33, 15, 51, 31, 35},
{21, 52, 33, 13, 23}
};
int currentCoordinates = 11;
bool treasureFound = false;
var visitedCells = new HashSet<int>();
while (!treasureFound && !visitedCells.Contains(currentCoordinates))
{
int currentRowIndex = currentCoordinates / 10;
int currentColumnIndex = currentCoordinates % 10;
int nextCoordinates = array[currentRowIndex - 1, currentColumnIndex - 1];
if (nextCoordinates == currentCoordinates)
{
treasureFound = true;
}
else
{
visitedCells.Add(currentCoordinates);
currentCoordinates = nextCoordinates;
}
}
if (treasureFound)
{
Console.WriteLine($"Treasure found in cell {currentCoordinates}");
}
else
{
Console.WriteLine("No treasure");
}
I keep getting an error message when trying to use VennDiagram in R. Below is my posted code:
draw.quintuple.venn(area1 = 578, area2 = 519, area3 = 212, area4 = 402, area5 = 172, n12 = 366, n15 = 97, n13 =149, n14 = 284, n23 = 103, n24 = 202, n25 = 125, n35 = 31, n34= 12, n45 = 27, n123 = 80, n124 = 161, n125 = 84, n134 = 8, n135 = 25, n145 = 20, n234 = 5, n235 = 24, n245 = 21, n345 = 1, n1234 = 5, n1345 = 21, n1245 = 16, n1235 = 0, n2345 = 0, n12345 = 0, category = c("1", "2", "3", "4", "5"), lty = "blank", fill = c("skyblue", "pink1", "mediumorchid", "yellow", "orange"))
Error:
ERROR [2018-07-09 13:37:19] Impossible: a11 <- n23 - a21 - a22 - a24 -
a26 - a29 - a30 - a31 produces negative area Error in
draw.quintuple.venn(area1 = 578, area2 = 519, area3 = 212, area4 =
402, : Impossible: a11 <- n23 - a21 - a22 - a24 - a26 - a29 - a30
- a31 produces negative area
What am I doing wrong?
I double checked and made sure the values are all correct.
I do not think that this package is well documented. A look at the source code shows that the meaning of nxxxxx is not the obvious one. For instance n135 means "how many elements belong to at least groups 1, 3 and 5". When you want to draw the diagram, the package calculates how many of those n135 also belong to other groups (i. e., n1235, n1345 and n12345) and substracts them.
What seems to be happening here is that you interpret n135 as "how many elements only belong to sets 1, 3 and 5" (that would have also been my guess). If you want to use those numbers directly, you should write:
draw.quintuple.venn(area.vector = c(578, 519, 212, 402, 172, 31, 97, 284, 366, 125, 103, 149, 12, 202, 27, 1, 25, 20, 161, 84, 24, 80, 8, 5, 21, 0, 21, 16, 0, 5, 0), category = c("1", "2", "3", "4", "5"), lty = "blank", fill = c("skyblue", "pink1", "mediumorchid", "yellow", "orange"), direct.area = T)
The order of the numbers is taken directly from the source code, I have not seen it documented. Let us call a135 "how many elements only belong to sets 2, 3 and 5". With this in mind, the order would be:
a1, a2, a3, a4, a5, a35, a15, a14, a12, a25, a23, a13, a34, a24, a45, a345, a135, a145, a124, a125, a235, a123, a134, a234, a245, a2345, a1345, a1245, a1235, a1234, a12345
If you prefer to use the n135 notation, you would need to transform your data, so that n135 = a135 + a1235 + a1345 + a12345, and so forth. In your case, n135 = 25 + 0 + 21 + 0 = 36.
Although not part of the question, you can also use my nVennR package for a proportional representation. The order of the numbers is documented in the help and the vignette, and you can also enter raw sets rather than numbers:
library(nVennR)
myV <- createVennObj(nSets = 5, sNames = c('1', '2', '3', '4', '5'), sSizes = c(0, 172, 402, 27, 212, 31, 12, 1, 519, 125, 202, 21, 103, 24, 5, 0, 578, 97, 284, 20, 149, 25, 8, 21, 366, 84, 161, 16, 80, 0, 5, 0))
myV <- plotVenn(nVennObj = myV, setColors = c("skyblue", "pink1", "mediumorchid", "yellow", "orange"), borderWidth = 0)
And the result:
For gnuplot, I have a large list of (randomly generated) numbers which I want to use as indices in a sum. How do I do it?
Here is what I mean. Let's say the list of numbers is
list = [81, 37, 53, 22, 72, 74, 44, 46, 96, 27]
I have a function
f(x,n) = cos(n*x)
I now want to plot the function, on the interval (-pi,pi) which is the sum of the f(x,n) as n runs through the numbers in list.
If you can control how your list looks like, try the following:
num = 10
# Let the numbers be in a space separated string.
# We can access the individual numbers with the word(string, index) function.
list = "81 37 53 22 72 74 44 46 96 27"
f(x,n) = cos(n*x)
set terminal pngcairo
set output "sum_cos.png"
set xrange [-pi:pi]
set samples 1000
# Build the plot command as a macro.
plt_cmd = ""
do for [n=1:num] {
plt_cmd = sprintf("%s + f(x,%s)", plt_cmd, word(list,n))
}
# Check what we have done so far.
print plt_cmd
titlestring = "{/Symbol S} cos(n_i*x), i = 1 ...".num
# Finally plot the sum by evaluating the macro.
plot #plt_cmd title titlestring
This is the result:
I am trying to place textual information above particular points in the series, and have them be linked, meaning that if I scroll around the plot, the text is always in the same position relative to a particular point in the series. like so:
my lets say length of my int[] data is 15 and it contains values {22, 44, 55, 87, 33, 21, 23, 44, 33, 42, 54, 56, 66, 77, 99}
I need to place letter "H" over position 3, "Z" over position 8, and "T" over position 12. All annotations are near the top of the plot area. My code works fine displaying regular LineSeries but I cant figure out how to add the annotations.
public void SetWaveformData(int[] data)
{
PlotModel plotModel = new PlotModel();
List<DataPoint> dataSeries = new List<DataPoint>();
int i = 0;
foreach (int yValue in data)
{
dataSeries.Add(new DataPoint { X = i++, Y = yValue });
}
LineSeries ser = new LineSeries();
ser.Points.AddRange(dataSeries);
plotModel.Series.Add(ser);
}
You can create Text Annotations
var myTextAnnotation = new TextAnnotation();
myTextAnnotation.TextPosition = new DataPoint(3, 55);
myTextAnnotation.Text = "H";
and then add them to the plots models annotations.
OR
You can do some digging around and try to use the series labels, there's an example of how it's used here, called "Labels" under the "LineSeries" category:
http://resources.oxyplot.org/examplebrowser/
but on this example the labels are the Y value so you'll have to find a way to manipulate that.
Hope this helps!