I'm stuck and need some help please... I'm trying to create a indicator which draws a horizontal line from the Sunday Daily Open candle for the upcoming week. I found the code below as an example, which works for simple line, but the line is too short; it only continues for a day - I would want it to plot through to the following Sunday open (if this isn't possible it's also fine to just extend the line, and delete all previous lines.. or I was thinking a continuous step line could be best?)
The chart below shows how I want it to look, whether step line or individual lines for each week. But I wouldn't want them all to extend to the end of the chart, would be too messy.
study(title="Sunday Open", shorttitle="Sunday Open", overlay=true)
openPrice = security(tickerid, 'D', open)
isSunday() => dayofweek(time('D')) == sunday ? 1 : 0
plot(isSunday() and openPrice ? openPrice: na, title="Sunday Open", style=linebr, linewidth=2, color=orange)
That is because you are plotting only when it is Sunday with isSunday() inside your plot().
Instead, use a var to store the open price when it is Sunday, and update this variable the next Sunday.
//#version=5
indicator(title="Sunday Open", shorttitle="Sunday Open", overlay=true)
var float open_price = na
is_sunday = dayofweek == dayofweek.sunday
is_sunday_first_bar = not is_sunday[1] and is_sunday
open_price := is_sunday_first_bar ? open : open_price
plot(open_price, title="Sunday Open", style=plot.style_linebr, linewidth=2, color=color.orange)
Related
I'm trying to get the lowest low of a series of candles after a condition, but it always returns the last candle of the condition. I try with min(), lowest() and a for loop but it doesn't work. Also try using blackCandle[] and min(ThreeinARow)/lowest(ThreeinARow) and sometimes it returns the last candle and other times it gives me compilation error.
blackCandle = close < open
ThreeinARow = blackCandle[3] and blackCandle[2] and blackCandle[1]
SL = ThreeinARow ? min(low[1], low[2], low[3]) : na
//#version=4
study("Help (low after 3DownBar)", overlay=true, max_bars_back=100)
blackCandle = close < open
ThreeinARow = blackCandle[3] and blackCandle[2] and blackCandle[1]
bar_ind = barssince(ThreeinARow)
//SL = lowest(max(1, nz(bar_ind))) // the lowest low of a series of candles after the condition
SL = lowest(max(1, nz(bar_ind)+1)) // the lowest low of a series of candles since the condition
plot(SL, style=plot.style_cross, linewidth=3)
bgcolor(ThreeinARow ? color.silver : na)
See also the second solution which is in the commented line
It seems that I was misinterpreting it. Using min() does return the minimum of a series of candles. The detail is that I must enter the specific number of candles that I will use to calculate the minimum, which, for now, does not generate any problem for me. In the end, this is how I ended up writing it:
blackCandle = close < open
ThreeinARow = blackCandle[3] and blackCandle[2] and blackCandle[1]
Lowest_Low = if ThreeinARow
min(low[1], low[2], low[3])
plot(Lowest_Low, color=color.red)
I want 2 lines to be displayed automatically at a certain time. This worked fine with the code below, but Monday is generally not displayed. I am in the timezone Utc+1, Berlin. What have I done wrong?
("Line", overlay=true)
t1 = time(period, "2100-2105")
t2 = time(period, "0030-0035")
Open = na(t1) ? na : green
Close = na(t2) ? na : green
bgcolor(Open, title="Open")
bgcolor(Close, title="Close")
I have the start and end times of trips made by a bus, with the times in an Excel sheet. I want to make the graph as below :
I tried with Matlab nodes and graphs but did not got the exact figure, below is the Matlab code which I tried as an example:
A = [1 4]
B = [2 3]
weights = [5 5];
G = digraph(A,B,weights,4)
plot(G)
And the figure it generates:
I have got many more than 4 points in the Excel sheet, and I want them to all be displayed as in the first image.
Overview
You don't need any sort of complicated graph package for this, just use normal line plots! Here are methods in Excel and Matlab.
Excel
Give each bus stop a number, and list the bus stop number by the time it arrives/leaves there. I'll use stops number 0 and 1 for this example.
0 04:41
1 05:35
1 05:40
0 06:34
0 06:51
1 07:45
1 15:21
0 16:15
Then simply highlight the data and insert a "scatter with straight lines"
The rest is formatting. You can format the y-axis and tick "values in reverse order" to get the time increasing as in your desired plot. You can change the x-axis tick marks to just show integer stop numbers, get rid of the legend etc.
Final output:
Matlab
Here is the Matlab documentation for converting Excel formatted dates into Matlab datetime arrays: Convert Excel Date Number to Datetime.
Once you have the datetime objects, you can do this easily with the standard plot function.
% Set times up as a datetime array, could do this any number of ways
times = datetime(strcat({'1/1/2000 '}, {'04:41', '05:35', '05:40', '06:34', '06:51', '07:45', '15:21', '16:15'}, ':00'), 'format', 'dd/MM/yyyy HH:mm:ss');
% Set up the location of the bus at each of the above times
station = [0,1,1,0,0,1,1,0];
% Plot
plot(station, times) % Create plot
set(gca, 'xtick', [0,1]) % Limit to just ticks at the 2 stops
set(gca, 'ydir', 'reverse') % Reverse y axis to have earlier at top
set(gca,'XTickLabel',{'R', 'L'}) % Name the stops
Output:
I would like to know if anyone can help me to find the issue about this code in GrADS language.
I'd like to read many files and compute and store them, but when I perform that in GraDS, I have the same answer for all imput file.
Could anyone help me in this problem, please?
'reinit'
****Modify here******
var = v10
ano = 1980
while(ano <= 2013)
*Desire point
local = IAG
**lat = -22.3
**lon = 314.62
latInitialP = -34.58
lonInitialP = 305.43
*******************************************************
'sdfopen C:\Pesquisa_Michelle\dados_amandenha\V10m_'ano'.nc'
*Storing out
'set gxout print'
'set prnopts %10.2f 1 1'
in = 1
test = 1460
if ( math_fmod(ano,4) = 0 )
test = 1464
endif
while(in <= test)
'set t 'in
in2 = in + 3
say in
say in2
'define m = ave('var',t='in',t='in2')'
'set lat 'latInitialP''
'set lon 'lonInitialP''
'd m'
valor = sublin(result,2)
lixo = write('C:\Pesquisa_Michelle\dados_amandenha\'var'_'ano'.txt',valor)
in = in + 4
endwhile
lixo = close(''var'_'ano'.txt')
ano = ano + 1
endwhile
update
I don't get an error (message) about that. That works fine, the problem is the result files. All result files have the first result, like a file replication. When I perform that not using a loop, but changing each value for "ano" by myself, I got different result.
The problem is, in my point of view, the command:
'sdfopen C:\Pesquisa_Michelle\dados_amandenha\V10m_'ano'.nc'
This command aren't replace the files for each "ano".
The problem is that you are never closing your input datafile or resetting grads during your main loop. Consider this example where I open a file:
% grads -l
ga-> open data/semicircle-qv14_s.ctl
Scanning description file: data/semicircle-qv14_s.ctl
Data file data/semicircle-qv14_00%y4_s.dat is open as file 1
LON set to -79.5 79.5
LAT set to -79.5 79.5
LEV set to 0.05 0.05
Time values set: 0:7:3:0 0:7:3:0
E set to 1 1
Notice that it says open as file 1. Now I'll narrow down my selection to a single grid point and display the pressure:
ga-> set lat 0
LAT set to 0.125 0.125
ga-> set lon 0
LON set to 0.125 0.125
ga-> set lev 5
LEV set to 4.92368 4.92368
ga-> d prs
Result value = 55198.4
The pressure is 551 hPa. Looks good. Now lets open another data file without closing this one:
ga-> open data-fine/semicircle-qv14_s.ctl
Scanning description file: data-fine/semicircle-qv14_s.ctl
Data file data-fine/semicircle-qv14_00%y4_s.dat is open as file 2
Notice this says open as file 2. Lets display pressure from this file:
ga-> d prs
Result value = 55198.4
Wait, this is the same value? Yes, because we are still displaying from file 1, here prs is the same as writing prs.1. If we want pressure from the second file, we need to use prs.2:
ga-> d prs.2
Result value = -9.99e+08
Different result (and this on is missing because there is no data at this time step in the second file.
There are two ways to fix this.
Where you are incrementing ano in your loop, add the command close 1. This will close the input data file so when the next one is loaded the display commands will properly display its content.
At the top of your loop, before sdfopen add reinit, which will reset lots of things, including closing all open files. You set your output up in each loop iteration so this shouldn't be a problem for you.
I have problem with a chart in vb.net. The problem is that line and bar are not synced in the chart area. I've attached a picture to make it clear what I mean
Here is the code where I populate the chart. I´m getting the data from a database.
Dim theDate As Date
For i As Integer = Count - 1 To 0 Step -1
'Chart1.Series("serRxTime").Points.AddY(dv(i)(0) / 60)
theDate = dv(i)(1)
Chart1.Series("serTime").Points.AddXY(theDate.ToString("dd-MMM HH:MM", enUS), dv(i)(0) / 60)
Chart1.Series("serAdd").Points.AddY(dv(i)(2))
Next
Line and column series have the same XValues that's why their centres are aligned. You would need to generate different XValues for the two series. XValues that are offset by a small margin. Something like this:
Chart1.Series("serTime").XValues = {0.8, 1.8, 2.8, 3.8,,...,count - 0.2}
Chart1.Series("serAdd").XValues = {1, 2, 3, 4,..., count}
I used 0.2 difference, but this will be different in your case (especially since it seems you have date axis set?). This would push the line series to the left.
I created an example for you. On the first picture you can see the data for the columns. Their x values are 1,2,3,4,...,12 and their y values are marked with blue.
And this is the values for the XY chart. As you can see I moved the x values by 0.2 to the left.