gnuplot draw finance and candlestick bars



set bars 3.0   // set bar width
set yrange [30:45] // set stock min and max to fit on screen
set xdata time
set timefmt "%Y%m%d"
plot "candle.dat" u 1:2:3:4:5 with candlesticks titile "Test"
plot "candle.dat" using 1:2:3:4:5 with financebar title "Test"
Finance bar


candle.dat should have 5 columns data
example data

4/8/1996 43.25 45 40 42
4/12/1996 42 43 39 40
4/16/1996 40 41 37.15 37.15
4/22/1996 39 39 37 39
4/23/1996 39 39 36 39



Candlesticks bar


Small C++ code : Read & Write file


// reading word by word
ifstream ifile(filename);
vector<string> words
copy(istream_iterator<string>(ifile),
         istream_iterator<string>(),
         back_inserter(words));
ifile.close();

//writing a vector  to file
ofstream outfile;
vector<string> lines;

outfile .open(filename,ofstream::out | ofstream::app);
copy(lines.begin(),
lines.end(),
ostream_iterator<string>(outfile,"\n"));
outfile.close();


Gnuplot draw graph using windows C++


Today I planned to draw some graph and i found a very good tool gnuplot. I used this tool without any kind of linking of library with my code, that's the best part of this tool. gnuplot have good stream operation functionality. you just need to open a pipe with gnuplot binary and run commands and draw required drawing.
=====Visit my store www.desikudi.in====

=====Visit my store www.desikudi.in====
you can get more details about this tool from gnuplot.




Header file.

class CGnuPlotter
{
FILE* m_fp;
public:
CGnuPlotter(void);
virtual ~CGnuPlotter(void);
bool runGnuPlot(const char* _gnuplot_path);
void closeGnuPlot();
void sendCmd2GnuPlot(const char* _cmd);
};

Implementation file


bool CGnuPlotter::runGnuPlot(const char* _gnuplot_path)
{
std::string gp(_gnuplot_path);
gp += " -persist";
m_fp=_popen(gp.c_str(),"w");
if(m_fp==NULL)
return false;
return true;
}
void CGnuPlotter::closeGnuPlot()
{
if(m_fp){
while(feof(m_fp)) Sleep(100);
_pclose(m_fp);
m_fp=NULL;
}
}
void CGnuPlotter::sendCmd2GnuPlot(const char* _cmd)
{
fprintf(m_fp,"%s\n",_cmd);
fflush(m_fp);  // you need to flush for force gnuplot to run the command.
}

Test Program
void testCGnuPlotter ()
{
CGnuPlotter cgp;
cgp.runGnuPlot("C:\\gp444win32\\gnuplot\\binary\\gnuplot.exe");
cgp.sendCmd2GnuPlot("set multiplot");
cgp.sendCmd2GnuPlot("plot sin(x) , 0.5  w l, -0.5  w l");
int i=0;
        // This is intentional stopped the program for have look of drawing.
std::cout<<"waiting for awake"<<std::endl;
while(i<100){std::cin>>i;}
cgp.closeGnuPlot();
}



Rajasthani Banagiri

Have a fun some time.
Everyday is not for only learning


Enjoy this..........................................................

Python Thread Pooling


import queue
import threading
import time
#TaskProcesser is my own module which is processing task, write your own module or function which provide job to thread.
import TaskProcesser

tasklist = [
"task1", 
"task2", 
"task3", 
"task4", 
"task5" 
]

taskqueue = queue.Queue()

class ThreadTask(threading.Thread):
def __init__(self, taskqueue):
threading.Thread.__init__(self)
self.taskqueue = taskqueue

def run(self):
while True:
start = time.time()
#get task from taskqueue
task = self.taskqueue.get()
#do processing of task
TaskProcesser.doTask(task)
#inform taskqueue about job has done
self.taskqueue.task_done()
print("Task compeleted in : " +str(time.time() - start) + " seconds")
def main():

#create thread pool and pass taskqueue
for i in range(2):
t = ThreadUrl(taskqueue)
t.setDaemon(True)
t.start()

#populate taskqueue with task   
for task in tasklist:
taskqueue.put(task)

#wait for queue, til task processing over 
taskqueue.join()

main()