Hi:
This is what is I am trying to achieve. I would like to run the program for
6 minutes, within the six minutes I would like to toggle for 2 minutes data
operation and for 1 minute trade operation, so there will be 2 cycle of data
operation and 2 cycle of trade operation.
I am setting and getting the ptime outside the main program, but what is
happening is that the getPtime of the template class is always return the +2
minutes of the current time, that is why diff is never reducing less than 2
minutes, why is that happening, the setter have been instantiated only once.
I would really appreciate if someone can help me out.
[code]
// boost_example.cpp : Defines the entry point for the console application.
//
#include "boost/date_time/posix_time/posix_time.hpp"
#include <iostream>
#include
#include
#include "windows.h"
using namespace std;
template <typename ptime_type>
class timeManagement
{
private:
ptime_type tradingTime;
public:
timeManagement(){};
void setPtime (const ptime_type& _val){tradingTime = _val; }
ptime_type const& getPtime() {return (tradingTime);}
~timeManagement(){};
};
int main()
{
bool btradingIndicator = false;
std::ostringstream msg;
using namespace boost::posix_time;
const ptime start = second_clock::local_time();
time_duration td = minutes(6);
time_duration tdDataCollection = minutes(2);
time_duration tdTrading = minutes(1);
bool bTradingIndicator = false;
const ptime end = start + td;
const ptime tTimeWindow = start + tdDataCollection;
int i = 0;
int switchTime = 0;
timeManagement <ptime> tradingWindow;
tradingWindow.setPtime(tTimeWindow);
//std::cout << tradingWindow.getPtime() << std::endl;
while(second_clock::local_time() <= end){
ptime currentTime = second_clock::local_time();
time_duration diff = tradingWindow.getPtime() - currentTime;
if(diff.total_seconds() >= 0 && !bTradingIndicator){
std::cout << "Data.) " << currentTime << "|" << tradingWindow.getPtime() <<
"|" << diff << std::endl;
}else{
const ptime tTimeWindow1 = currentTime + tdTrading;
tradingWindow.setPtime(tTimeWindow1);
bTradingIndicator = true;
}
if(diff.total_seconds() >= 0 && bTradingIndicator){
std::cout << "Trade.) " << diff << std::endl;
}else{
const ptime tTimeWindow2 = currentTime + tdDataCollection;
tradingWindow.setPtime(tTimeWindow2);
bTradingIndicator = false;
}
}
std::cout << "Start Time: " << start << std::endl;
std::cout << "End Time: " << end << std::endl;
std::cout << "Time Now: "<< end << std::endl;
return 0;
}
[/code]
Regards,
Arup
*"I don't need to know everything, I just need to KNOW where to find it,
when I need it"*. -*Albert Einstein *