0

My question is identical to this question except that I'm using conditional coloring for candlesticks and the solution mentioned isn't working.

My data is like:

10/24/2018 23:45,168.25,168.65,168.2,168.4,0
10/24/2018 23:46,168.5,169,168.5,168.95,67577
10/24/2018 23:47,169.35,169.6,169.1,169.1,151630
10/24/2018 23:48,169.05,169.35,168.95,169.2,63418
.
.
10/26/2018 13:48,169.05,169.35,168.95,169.2,63418
10/26/2018 23:47,169.35,169.6,169.1,169.1,151630
10/26/2018 23:48,169.05,169.35,168.95,169.2,63418

Plotting a file like this in gnuplot using command:

plot ".../ISTFeed.csv" using (timecolumn(1, "%m/%d/%Y %H:%M:%S")) : 2 : 3 : 4 : 5 : ($5 < $2 ? rgb(255, 0, 0) : rgb(0, 255, 0)) linecolor rgb variable notitle with candlesticks

produces chart with gaps. I want gnuplot to omit the gaps and plot candlesticks continuously. Is there a way to achieve this?

hmmmmmm
  • 67
  • 3
  • if the only difference to the mentioned link is the conditional color, why do you use `(timecolumn(0, "%m/%d/%Y %H:%M:%S"))` instead of `0` as in the answer there? If you omit date/time gaps your x-axis will not be a date/time-axis anymore but something arbitrary (well, a sequence of datalines numbers). What do you want to have as x-axis tic labels, still the date like in the linked answer? – theozh Jun 15 '19 at 13:59
  • @theozh the `timecolumn()` syntax is because gnuplot (I think) deprecated the old format. Besides, it's also more flexible. I did, however, make a slight error in question - I meant it as `timecolumn(1, "%m/%d/%Y %H:%M:%S")`. And Yes, I do want the xtics to be datetime. – hmmmmmm Jun 15 '19 at 15:03

1 Answers1

1

Have a look at the below example with generated dummy data. Although the xtics in the plot look equidistant the values of the xtics are not equidistant at all. So if you want to readout a y-value between two xtics you don't have "any" idea what the actual x-value is. You just know it must be somewhere inbetween the neighbouring xtics. A bit strange... but if you are fine with this precision...

Code:

### remove gaps in timedata
# requires gnuplot >=5.2, because of use of datablocks
reset session

# generate some dummy data
t = strptime("%m/%d/%Y %H:%M", "10/24/2018 23:45")
close = 168.25
set print $Data
print "#      date time,    open,     low,    high,   close"
do for [i=1:100] {
    open = close + (rand(0)*2)-1
    low_tmp = open - rand(0)
    high_tmp = open + rand(0)
    close = open + (rand(0)*2)-1
    low = open<low_tmp ? open : close<low_tmp ? close : low_tmp
    high = open>high_tmp ? open : close>high_tmp ? close : high_tmp
    dt = 3600*rand(0)*48
    t = t + dt
    print sprintf("%s,%8 .2f,%8 .2f,%8 .2f,%8 .2f",strftime("%m/%d/%Y %H:%M",t),open,low,high,close)
}
set print
print $Data

N = 10
Offset = 5
everyNthRow(N) = (int($0)%N==Offset ? word(strcol(1),1) : NaN)
set datafile separator ","
set xtics rotate by 45 right
set style fill solid 1.0
plot $Data u 0:2:3:4:5:($5<$2 ? 0xff0000 : 0x00ff00):xtic(everyNthRow(N)) w candlesticks lc rgb var not

### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72