Esempio n. 1
0
function run()
{
	BarPeriod = 240;	// 4 hour bars
	
// calculate the buy/sell signal
	vars Price = series(price());
	vars DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	vars HP = series(HighPass(Price,LowPeriod));
	vars Signal = series(Fisher(HP,500));
	var Threshold = 1.0;

// buy and sell
	Stop = 4*ATR(100);
	Trail = 4*ATR(100);
	if(crossUnder(Signal,-Threshold))
		enterLong(); 
	else if(crossOver(Signal,Threshold))
		enterShort();

// plot signals and thresholds
	plot("DominantPeriod",LowPeriod,NEW,BLUE);
	plot("Signal",Signal[0],NEW,RED);
	plot("Threshold1",Threshold,0,BLACK);
	plot("Threshold2",-Threshold,0,BLACK);
	PlotWidth = 600;
	PlotHeight1 = 300;
} 
Esempio n. 2
0
function run()
{
	vars Price = series(price());
	vars Trend = series(LowPass(Price,1000));
	
	Stop = 100*PIP;
	TakeProfit = 100*PIP;
	if(valley(Trend)) {
		//plotPriceProfile(50,0);
		enterLong();
	} else if(peak(Trend)) {
		//plotPriceProfile(50,PMINUS);
		enterShort();
	}

	PlotWidth = 1000;
	PlotHeight1 = 320;
	PlotScale = 4;
	
	//plotDay(Equity,PDIFF); 
	//plotWeek(Equity,PDIFF); 
	//plotMonth(Equity,PDIFF); 
	//plotYear(Equity,PDIFF); 
	plotTradeProfile(50);
}
Esempio n. 3
0
// brute force optimization
function run(){  
	set(PARAMETERS);
  int PeriodsEMA1[4] = { 5, 10, 15, 20 };
  int PeriodsEMA2[3] = { 100, 150, 200 };  LookBack = 250;
  int Index = optimize(1,1,4*3,1) - 1;  int PeriodEMA1 = PeriodsEMA1[Index%4];
  int PeriodEMA2 = PeriodsEMA2[Index/4];    vars Price = series(price(0));
  vars EMA1 = series(EMA(Price,PeriodEMA1));
  vars EMA2 = series(EMA(Price,PeriodEMA2));    
  if(crossOver(EMA1,EMA2))
    enterLong();  
  else if(crossUnder(EMA1,EMA2))    
   enterShort();
 }
Esempio n. 4
0
unsigned char get_byte(int id)
{
	double s1 = series (1, id);
	double s2 = series (4, id);
	double s3 = series (5, id);
	double s4 = series (6, id);
	double pid = 4. * s1 - 2. * s2 - s3 - s4;
	pid = pid - (int) pid + 1.;

	double y = fabs(pid);
	y = 16. * (y - floor (y));
	unsigned char first = y;
	return (first);
}
Esempio n. 5
0
void SeriesStyleDialog::UpdateSeriesStyle()
{
	void *x; UpdateData();
	if((x=Series->GainAcsess(WRITE))!=NULL)
	{
		SeriesProtector guard(x); TSeriesArray& series(guard);
		TChartSeries *graph=series[graph_num];

		ChartSeriesStyleParams style=graph->GetStyle();
		graph->Name=SeriesName;

		switch (LineStyleCombo.GetItemData(LineStyleCombo.GetCurSel()))
		{
		case STRAIGHT: style.LineStyleStyleParams::style=STRAIGHT; break;
		default: style.LineStyleStyleParams::style=NO_LINE; break;
		}

		switch (SymbolStyleCombo.GetItemData(SymbolStyleCombo.GetCurSel()))
		{
		case CIRCLE: style.SymbolStyleStyleParams::style=CIRCLE; break;
		case CROSS45: style.SymbolStyleStyleParams::style=CROSS45; break;
		case VERT_LINE: style.SymbolStyleStyleParams::style=VERT_LINE; break;
		default: style.SymbolStyleStyleParams::style=NO_SYMBOL; break;
		}

		switch (ErrBarsStyleCombo.GetItemData(ErrBarsStyleCombo.GetCurSel()))
		{
		case POINTvsERROR_BAR: style.ErrorBarStyleParams::style=POINTvsERROR_BAR; break;
		default: style.ErrorBarStyleParams::style=NO_BARS; break;
		}

		graph->SetStyle(style);
	}
	
}
Esempio n. 6
0
/**
 * Moves study and its series from one patient to another and returns the list of new indexes
 * @param const medDataIndex & indexStudy The data index of the study to be moved
 * @param const medDataIndex & toPatient The data index to move the study to.
 */
QList<medDataIndex> medDatabaseController::moveStudy( const medDataIndex& indexStudy, const medDataIndex& toPatient)
{
    QSqlQuery query(this->database());

    bool result = false;
    QList<medDataIndex> newIndexList;
    medDataIndex newIndex;

    if(indexStudy.isValidForStudy() && toPatient.isValidForPatient())
    {
        query.prepare("UPDATE study SET patient=:patientId WHERE id=:studyId");
        query.bindValue(":patientId", toPatient.patientId());
        query.bindValue(":studyId", indexStudy.studyId());

        result = EXEC_QUERY(query);

        if(result)
        {
            // we need to update patient id in study index
            newIndex = indexStudy;
            newIndex.setPatientId(toPatient.patientId());

            newIndexList << newIndex;
            
            // and update patient id in series indexes
            QList<medDataIndex> seriesIndexList = series(indexStudy);
            foreach(medDataIndex newSerieIndex, seriesIndexList)
            {
                newSerieIndex.setPatientId(toPatient.patientId());
                newIndexList << newSerieIndex;
            }
        }
long long
findmax (int depth, int level, int pos)
{
  int curr_width = depth;
  int curr_start = series (depth - 1, TRI);
  int current = retval(depth, pos);

  // reached the end of this search
  if (level == 1)
    return current;

  // top of the pyramid
  if (depth < 2)
    return tri[0];

  // far left edge
  if (pos == 1)
    return (findmax (depth - 1, level - 1, pos) + current);

  // far right edge
  if (pos == curr_width)
    return (findmax (depth - 1, level - 1, pos - 1) + current);

  // find the maximum value and return it
  current += maxlong (
		       // look left
		       findmax (depth - 1, level - 1, pos-1),
		       // look right
		       findmax (depth - 1, level - 1, pos));
  return current;
}
Esempio n. 8
0
int series(int a){
  if(a <= 0){
    return 0;
  }else{
    return a + series(a-1);
  }
}
Esempio n. 9
0
void SeriesValuesDialog::OnLvnKeydownList2(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLVKEYDOWN pLVKeyDow = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);
	int i,n; POSITION pos; CArray<int,const int&> arr; CString temp; CString T,T1;
	void *x; TChartSeries *graph;

	switch(pLVKeyDow->wVKey)
	{
	case VK_DELETE:		
		if((x=Series->GainAcsess(WRITE))!=NULL)
		{
			SeriesProtector guard(x); TSeriesArray& series(guard);
			graph=series[graph_num];
			n=graph->GetSize();
			pos=ListBox2.GetFirstSelectedItemPosition();				
			while(pos) arr.Add(ListBox2.GetNextSelectedItem(pos));
			graph->SetParentUpdateStatus(UPD_OFF);
			for(i=0;i<arr.GetSize();i++)
			{
				n=arr[i];
				graph->RemoveAt(n-i);
				ListBox2.DeleteItem(n-i);
			}
			graph->SetParentUpdateStatus(UPD_ON);
		}
		break;
	}
	*pResult = 0;
}
int main(int argc, char *argv[]) {
    int child = fork();
    if (child == 0) {
        ExtentTypeLibrary library;
        const ExtentType::Ptr type = library.registerTypePtr(type_string);

        DataSeriesSink sink("incomplete-ds-file.ds", Extent::compression_algs[Extent::compress_mode_lzf].compress_flag);
        ExtentSeries series(type);
        OutputModule output(sink, series, type, 4 * 1024);
        Int64Field number(series, "number");

        sink.writeExtentLibrary(library);
    
        for (uint64_t i = 0; i < 64 * 1024; i++) {
            output.newRecord();
            number.set(i);

            if (i == 50 * 1024) {
                output.flushExtent();
                sink.flushPending();
            }
            assert(i < 50 * 1024);
        }
    }

    int error = waitpid(child, NULL, 0);
    if (error != child) {
        return -1;
    }
    return 0;
}
Esempio n. 11
0
function tradeCounterTrend()
{
	TimeFrame = 4;
	vars Price = series(price());
	vars Filtered = series(BandPass(Price,optimize(30,25,35),0.5));
	vars Signal = series(Fisher(Filtered,500));
	var Threshold = optimize(1,0.5,1.5,0.1);
	
	Stop = optimize(4,2,10) * ATR(100);
	Trail = 4*ATR(100);
	
	if(crossUnder(Signal,-Threshold)) 
		enterLong(); 
	else if(crossOver(Signal,Threshold)) 
		enterShort();
}
Esempio n. 12
0
void TChart::DefaultBufferRender(BMPanvas* canvas)
{
	int i; void *x; //CString T; 
	BMPanvas &bmp=*canvas; 

	CalcOriginScale(); 	

	if(SeriesRenderIsChanged()==FALSE && SeriesIsChanged()==FALSE) return;
	LastSeriesRenderUpdateID=SeriesRender.GetModificationID();
	LastSeriesUpdateID=Series.GetModificationID();
	if((x=Series.GainAcsess(READ))!=0)
	{
		Timer1.Start(); 
		SeriesProtector Protector(x); TSeriesArray& series(Protector);
		Clear();	
		InfoOnCanvas.dt2=Timer1.StopStart();
		for(i=0;i<Elements.GetSize();i++) 
			Elements[i]->Draw(&bmp);									
		InfoOnCanvas.dt3=Timer1.StopStart();
		bmp.CopyTo(&sbuf,TOP_LEFT,Frame->DrawArea);
		for(i=0;i<series.GetSize();i++) series[i]->Draw(&sbuf);			
		sbuf.CopyTo(&bmp,Frame->DrawArea.TopLeft()); 
		
		
		InfoOnCanvas.dt4=Timer1.StopStart();
	}
	else
		ASSERT(0);

}
Esempio n. 13
0
BOOL TChart::Create(CWnd* pParentWnd,const RECT& rect)
{
	BOOL ret; void *x;
	CClientDC cdc(pParentWnd); 
	ret=CWnd::Create(0, Name, WS_CHILD | WS_BORDER, rect, pParentWnd, ID_CHART, 0);	

	font1.CreatePointFont(60,"MS Sans Serif");			
	font2.CreatePointFont(100,"Arial"); 

	if((x=Series.GainAcsess(WRITE))!=NULL)
	{
		SeriesProtector guard(x); TSeriesArray& series(guard);
		series.Parent=this;
		series.Parent=this;
		series.SetRender(SERIES_RENDER);
	}
	SetFont(&font1);
	menu1.LoadMenu(IDR_MENU2);
    OnPaintTimer.Start();	

	pThrd=AfxGetThread();	pWND=this;
	BckgBrush.CreateSolidBrush(RGB(140,140,140));
	InitBasicElements();
	OnSeriesUpdate(0,0);
	return ret;
}
Esempio n. 14
0
double GammaQ (double n, double x)
{                               /* --- regularized Gamma function Q */
  assert((n > 0) && (x >= 0));  /* check the function arguments */
  if (x <=  0) return 1;        /* treat x = 0 as a special case */
  if (x < n+1) return 1 -series(n, x) *exp(n *log(x) -x -logGamma(n));
  return cfrac(n, x) *exp(n *log(x) -x -logGamma(n));
}  /* GammaQ() */
Esempio n. 15
0
void STVariable::setColor(const QColor &newColor)
{
    if (color_ != newColor) {
        color_ = newColor;
        series()->setLinePen( QPen(color_) );
        emit colorChanged(color_);
    }
}
Esempio n. 16
0
BOOL SeriesStyleDialog::OnInitDialog()
{
	CDialog::OnInitDialog();

	int n;

	n=LineStyleCombo.AddString("No line"); LineStyleCombo.SetItemData(n,ChartSerieStyles::NO_LINE);
	n=LineStyleCombo.AddString("Straight");	LineStyleCombo.SetItemData(n,ChartSerieStyles::STRAIGHT);

	n=SymbolStyleCombo.AddString("No symbol");	SymbolStyleCombo.SetItemData(n,ChartSerieStyles::NO_SYMBOL);
	n=SymbolStyleCombo.AddString("Circle");	SymbolStyleCombo.SetItemData(n,ChartSerieStyles::CIRCLE);
	n=SymbolStyleCombo.AddString("Cross 45");	SymbolStyleCombo.SetItemData(n,ChartSerieStyles::CROSS45);
	n=SymbolStyleCombo.AddString("Vertical line");	SymbolStyleCombo.SetItemData(n,ChartSerieStyles::VERT_LINE);

	n=ErrBarsStyleCombo.AddString("No bars");	ErrBarsStyleCombo.SetItemData(n,ChartSerieStyles::NO_BARS);
	n=ErrBarsStyleCombo.AddString("Both bars");	ErrBarsStyleCombo.SetItemData(n,ChartSerieStyles::POINTvsERROR_BAR);

	void *x; int i;
	if((x=Series->GainAcsess(READ))!=NULL)
	{
		SeriesProtector guard(x); TSeriesArray& series(guard);
		TChartSeries *graph=series[graph_num];

		ChartSeriesStyleParams style=graph->GetStyle();
		SeriesName=graph->Name;
		for(i=0;i<LineStyleCombo.GetCount();i++)
		{
			if(LineStyleCombo.GetItemData(i)==style.LineStyleStyleParams::style) 
			{
				LineStyleCombo.SetCurSel(i); break;
			}
		}
		for(i=0;i<SymbolStyleCombo.GetCount();i++)
		{
			if(SymbolStyleCombo.GetItemData(i)==style.SymbolStyleStyleParams::style) 
			{
				SymbolStyleCombo.SetCurSel(i); break;
			}
		}
		for(i=0;i<ErrBarsStyleCombo.GetCount();i++)
		{
			if(ErrBarsStyleCombo.GetItemData(i)==style.ErrorBarStyleParams::style) 
			{
				ErrBarsStyleCombo.SetCurSel(i); break;
			}
		}

		LineColorBtn.FaceColor=graph->PColor;
		FillColorBtn.FaceColor=graph->BColor;

		if(graph->GetSeriesType()!=POINTvsERROR) 
			ErrBarsStyleCombo.EnableWindow(FALSE);
		UpdateData(0);
	}

	
	return TRUE;  
}
void
main ()
{
  int i, j, k=0;
  int start=0;
  int lev=0;

  for (i=0; i<(LEVELS+1); i++) {
    lev++;
    for (j=0; j<i; j++) {
      long double val;
      val = tri[start+j];
//      printf("%lld ", val);
      heat[start+j]   = val;
      k++;
    }
    start = k;
//    printf("\n");
  }
  
  k=0;
  start=0;
  lev=0;
  int pstart;

  for (i=LEVELS; i>1; i--) {
    start = series(i-1, TRI);
    pstart = series(i-2, TRI);
    for (j=i; j>0; j--) {
      long double val;
      int cpos = start+j-1;
      val = heat[cpos];
      //printf("***< %0.0Lf s %d j %d l %d > ", val, start, j, lev);
      printf("%0.0Lf ", val);
      if (heat[cpos-i+1]> heat[cpos-i+1+1])
        heat[cpos-i+1]   +=val;
      else
        heat[cpos-i+1+1] +=val;
    }
    printf("\n");
  }

 printf("Solution is %lld\n ", search(1,1));
  
}
Esempio n. 18
0
static ex atan_series(const ex &arg,
                      const relational &rel,
                      int order,
                      unsigned options)
{
	GINAC_ASSERT(is_a<symbol>(rel.lhs()));
	// method:
	// Taylor series where there is no pole or cut falls back to atan_deriv.
	// There are two branch cuts, one runnig from I up the imaginary axis and
	// one running from -I down the imaginary axis.  The points I and -I are
	// poles.
	// On the branch cuts and the poles series expand
	//     (log(1+I*x)-log(1-I*x))/(2*I)
	// instead.
	const ex arg_pt = arg.subs(rel, subs_options::no_pattern);
	if (!(I*arg_pt).info(info_flags::real))
		throw do_taylor();     // Re(x) != 0
	if ((I*arg_pt).info(info_flags::real) && abs(I*arg_pt)<_ex1)
		throw do_taylor();     // Re(x) == 0, but abs(x)<1
	// care for the poles, using the defining formula for atan()...
	if (arg_pt.is_equal(I) || arg_pt.is_equal(-I))
		return ((log(1+I*arg)-log(1-I*arg))/(2*I)).series(rel, order, options);
	if (!(options & series_options::suppress_branchcut)) {
		// method:
		// This is the branch cut: assemble the primitive series manually and
		// then add the corresponding complex step function.
		const symbol &s = ex_to<symbol>(rel.lhs());
		const ex &point = rel.rhs();
		const symbol foo;
		const ex replarg = series(atan(arg), s==foo, order).subs(foo==point, subs_options::no_pattern);
		ex Order0correction = replarg.op(0)+csgn(arg)*Pi*_ex_1_2;
		if ((I*arg_pt)<_ex0)
			Order0correction += log((I*arg_pt+_ex_1)/(I*arg_pt+_ex1))*I*_ex_1_2;
		else
			Order0correction += log((I*arg_pt+_ex1)/(I*arg_pt+_ex_1))*I*_ex1_2;
		epvector seq;
		if (order > 0) {
			seq.reserve(2);
			seq.push_back(expair(Order0correction, _ex0));
		}
		seq.push_back(expair(Order(_ex1), order));
		return series(replarg - pseries(rel, std::move(seq)), rel, order);
	}
	throw do_taylor();
}
Esempio n. 19
0
boost::optional<TimeSeries> SimFile::nodeDensity(int nr) const
{
  int index = m_nodeNr.indexOf(nr);
  if(index == -1) {
    return boost::optional<TimeSeries>();
  }
  TimeSeries series(m_seconds,m_D[index],"kg/m^3");
  return boost::optional<TimeSeries>(series);
}
Esempio n. 20
0
int main()
{
	int n;
	printf("Enter the length of Fibonacci Series: ");
	scanf("%d",&n);

	series(n,1,1);
	return 0;
}
int
retval(int level, int pos){
  int start;
  if (level>1)
     start = series (level-1, TRI);
  else 
     start = 0;
  return tri[start+pos];
}
Esempio n. 22
0
boost::optional<TimeSeries> SimFile::pathFlow1(int nr) const
{
  int index = m_pathNr.indexOf(nr);
  if(index == -1) {
    return boost::optional<TimeSeries>();
  }
  TimeSeries series(m_seconds,m_F1[index],"kg/s");
  return boost::optional<TimeSeries>(series);
}
Esempio n. 23
0
boost::optional<TimeSeries> SimFile::nodePressure(int nr) const
{
  int index = m_nodeNr.indexOf(nr);
  if(index == -1) {
    return boost::optional<TimeSeries>();
  }
  TimeSeries series(m_seconds,m_P[index],"Pa");
  return boost::optional<TimeSeries>(series);
}
Esempio n. 24
0
boost::optional<TimeSeries> SimFile::pathDeltaP(int nr) const
{
  int index = m_pathNr.indexOf(nr);
  if(index == -1) {
    return boost::optional<TimeSeries>();
  }
  TimeSeries series(m_seconds,m_dP[index],"Pa");
  return boost::optional<TimeSeries>(series);
}
void
setval(int level, int pos, int val){
  int start;
  pos -= 1;
  if (level>1) {
     start = series (level-1, TRI);
     tri[start+pos] = val;
  } else 
     tri[0] = val;
}
void
main ()
{
  int x, y;
  long close, result, solx, soly;
  for (x = 35; x < 50; x++)
    for (y = x; y < 80; y++)
      {
	result = series (y, 1) * series (x, 1);
	if (labs (result - TARGET) < labs (close - TARGET))
	  {
	    close = result;
	    solx = x;
	    soly = y;
	  }
      }
  printf ("Solution is %ld at %ld %ld %ld\n",
      solx * soly, solx, soly, close);
}
long double
retheat(int level, int pos){
  int start;
  pos -= 1;
  if (level>1) 
     start = series (level-1, TRI);
  else 
     return heat[0];
  return heat[start+pos];
}
Esempio n. 28
0
function tradeTrend()
{
	TimeFrame = 1;
	vars Price = series(price());
	vars Trend = series(LowPass(Price,optimize(500,300,700)));

	Stop = optimize(4,2,10) * ATR(100);
	Trail = 0;

	vars MMI_Raw = series(MMI(Price,300));
	vars MMI_Smooth = series(LowPass(MMI_Raw,500));
	
	if(falling(MMI_Smooth)) {
		if(valley(Trend))
			enterLong();
		else if(peak(Trend))
			enterShort();
	}
}
Esempio n. 29
0
function run() 
{
	BarPeriod	= 1440;
	//Detrend = 8; // does it also work with the inverse curve?
	asset("SPX500");
	
	vars Osc = series(StochEhlers(series(price()),20,10,10));
	
	if(crossOver(Osc,0.8)) 
		reverseShort(1);
	if(crossUnder(Osc,0.2))
		reverseLong(1);
	
	PlotWidth = 800;
	plot("StochEhlers",Osc[0],NEW,RED);
	plot("Threshold1",.2,0,BLACK);
	plot("Threshold2",.8,0,BLACK);
	set(PLOTNOW);
}
Esempio n. 30
0
/* This are the calculation threads.
 * they pick the next available position on the memsave array (so they know which 8 digits of pi
 * they should calculate) and increment the position counter for the others.
 * WHen calculated a set of digits they save it to the picked position in memory and go on
 * with the first step.
 * But they also look every calculation loop if the user has pressed "Stop/Close" (isRunning = false)
 * if so they terminate themself. */
UINT CCalculate::Calc_Threads(LPVOID pParam)
{
	//CSingleLock id_lock(&cs_id_lock);
	CSingleLock pos_lock(&cs_pos_lock);
	//int my_id;
	//id_lock.Lock();
	//if(id_lock.IsLocked())				//pick an number (id) and increment for other threads
	//{
	//	my_id = myThreadId;
	//	myThreadId++;
	//	id_lock.Unlock();
	//}
	int *my_id = reinterpret_cast<int*>(pParam);

	int save_pos = 0, id = 0;
	double pi, s1, s2, s3, s4;			//actual pi digit and the 4 series

	do
	{
		pos_lock.Lock();
		if(pos_lock.IsLocked())
		{
			save_pos = position;
			position++;
			pos_lock.Unlock();
		}
		id = save_pos * TRUSTED;
		s1 = series (1, id);
		s2 = series (4, id);
		s3 = series (5, id);
		s4 = series (6, id);
		pi = 4. * s1 - 2. * s2 - s3 - s4;
		pi = pi - (int) pi + 1.;
		ihex (pi, save_pos);

		if(!isRunning)					//user pressed stop, so stop operation NOW
			return 0;
	}while(((save_pos + num_cpu) * TRUSTED) < (pi_digits));

	isFinished[(*my_id)] = true;			//signalise to control_thread that you have finished

	return 0;
}