Commit 9fe57c95 authored by denis's avatar denis

further work on ichimoku evaluation

parent 1b2204ed
......@@ -5,6 +5,7 @@ INCLUDES = -I/usr/include/mysql
LIBS = -L/usr/lib/mysql -lmysqlclient -lm
CFLAGS = -lm -Wall -O2 -L/usr/lib/mysql/ -lmysqlclient -pedantic -Wextra
all:ichinscratchy
ichinscratchy: $(OBJPATH)
......
......@@ -6,7 +6,7 @@
enum trend_type{
uptrend,
downtrend,
neutral,
sideways,
};
typedef enum trend_type trend_type;
......@@ -18,14 +18,15 @@ enum longshort{
typedef enum longshort signal_type;
enum strength_type{
none,
weak,
neutral,
strong,
};
typedef enum strength_type strength_type;
struct signal
{
bstring name;
bstring date;
signal_type type;
strength_type strength;
......
......@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdbool.h>
#include "bstrlib.h"
#include "datatypes.h"
......@@ -179,6 +180,10 @@ int ichimoku_evaluate_signals(bstring symbol)
indicator *tenkan, *kijun, *chikou, *senkouA, *senkouB;
trend_type kumo_trend, chikou_trend;
signal Tenkan_Kijun_cross, Kijun_Sen_cross;
signal Kumo_breakout, Senkou_Span_cross, Chikou_Span_Cross;
unsigned int days_to_analyze=0;
// we want the full parms.ICHI_DAYS_TO_ANALYZE days, so we
......@@ -228,48 +233,46 @@ int ichimoku_evaluate_signals(bstring symbol)
hh_short, hh_mid, hh_long, ll_short, ll_mid, ll_long,\
tenkan, kijun, chikou, senkouA, senkouB);
printf("\nindicator days: %i\ndays_to_analze: %i\nIchi_days_to_a: %i\nintervall: %i", chikou->days, days_to_analyze, parms.ICHI_DAYS_TO_ANALYZE, days_to_analyze-parms.ICHI_PERIOD_MID);
// Initialize Signals with name and description
Tenkan_Kijun_cross.name = bfromcstr("Tenkan/Kijun Cross");
Tenkan_Kijun_cross.description = bfromcstr("Tenkan-Sen (Turning line) crossed Kijun-Sen (Standard line)");
Kijun_Sen_cross.name = bfromcstr("Kijun Cross");
Kijun_Sen_cross.description = bfromcstr("Close quote crossed the Kijun- Sen (Standard line)");
Chikou_Span_Cross.name = bfromcstr("Chikou Cross");
Chikou_Span_Cross.name = bfromcstr("Chikou Span (Lagging line) crossed close quote");
Kumo_breakout.name = bfromcstr("Kumo breakout");
Kumo_breakout.description = bfromcstr("Close quote left or crossed Kumo (Cloud)");
Senkou_Span_cross.name = bfromcstr("Senkou Cross");
Senkou_Span_cross.description = bfromcstr("Senkou Span A crossed Senkou Span B");
for (daynr=parms.ICHI_PERIOD_MID; daynr< days_to_analyze; daynr++)
{
// check if current close is above, under or in kumo
kumo_trend = ichimoku_get_kumo_trend(close->quotes[daynr], senkouA->quotes[daynr-parms.ICHI_PERIOD_MID], senkouB->quotes[daynr-parms.ICHI_PERIOD_MID]);
// check if chikou is above or under close
// check if chikou is above or under close, but check only for dates where chikou is available
if (daynr < parms.ICHI_DAYS_TO_ANALYZE)
{
chikou_trend = ichimoku_get_chikou_trend(close->quotes[daynr], chikou->quotes[daynr-parms.ICHI_PERIOD_MID+1]);
// if(current_trend == uptrend)
// {
// printf("\n%s: c:%0.1f sA: %0.1f sB:%0.1f Hoch", bdata(close->dates[daynr]), close->quotes[daynr], senkouA->quotes[daynr-parms.ICHI_PERIOD_MID], senkouB->quotes[daynr-parms.ICHI_PERIOD_MID] );
// }
// else if (current_trend == downtrend)
// {
// printf("\n%s: c:%0.1f sA: %0.1f sB:%0.1f Runter", bdata(close->dates[daynr]), close->quotes[daynr], senkouA->quotes[daynr-parms.ICHI_PERIOD_MID], senkouB->quotes[daynr-parms.ICHI_PERIOD_MID]);
// }
// else if (current_trend == neutral)
// {
// printf("\n%s: c:%0.1f sA: %0.1f sB:%0.1f nischt", bdata(close->dates[daynr]), close->quotes[daynr], senkouA->quotes[daynr-parms.ICHI_PERIOD_MID], senkouB->quotes[daynr-parms.ICHI_PERIOD_MID]);
// }
if(chikou_trend == uptrend)
{
printf("\n%s: c:%0.1f ch: %0.1f Hoch", bdata(close->dates[daynr]), close->quotes[daynr], chikou->quotes[daynr-parms.ICHI_PERIOD_MID+1]);
}
else if (chikou_trend == downtrend)
{
printf("\n%s: c:%0.1f ch: %0.1f runter", bdata(close->dates[daynr]), close->quotes[daynr], chikou->quotes[daynr-parms.ICHI_PERIOD_MID+1]);
}
else if (chikou_trend == neutral)
{
printf("\n%s: c:%0.1f ch: %0.1f neutral", bdata(close->dates[daynr]), close->quotes[daynr], chikou->quotes[daynr-parms.ICHI_PERIOD_MID+1]);
}
}
// debugging printouts
// printf("\n%s: c:%0.1f sA: %0.1f sB:%0.1f Hoch", bdata(close->dates[daynr]), close->quotes[daynr], senkouA->quotes[daynr-parms.ICHI_PERIOD_MID], senkouB->quotes[daynr-parms.ICHI_PERIOD_MID] );
// printf("\n%s: c:%0.1f ch: %0.1f", bdata(close->dates[daynr]), close->quotes[daynr], chikou->quotes[daynr-parms.ICHI_PERIOD_MID+1]);
}
// print_indicator_table2(symbol, close);
// printf("\n=========\n==================");
// print_indicator_table2(symbol, chikou);
// for (daynr = 0; daynr < parms.ICHI_DAYS_TO_ANALYZE; daynr++)
// {
// if(tenkan_kijun_golden_X(daynr, tenkan->quotes, kijun->quotes))
// printf("\n%s GoldenX \t\t %f %f", bdata(kijun->dates[daynr]), tenkan->quotes[daynr], kijun->quotes[daynr]);
// else if(tenkan_kijun_death_X(daynr, tenkan->quotes, kijun->quotes))
// printf("\n%s deathX \t\t %f %f", bdata(kijun->dates[daynr]), tenkan->quotes[daynr], kijun->quotes[daynr]);
// else
// printf("\n%s menno \t\t %f %f", bdata(kijun->dates[daynr]), tenkan->quotes[daynr], kijun->quotes[daynr]);
// }
print_indicator_table2(symbol, kijun);
return 0;
......@@ -382,8 +385,8 @@ int ichimoku_create_plotfile(bstring symbol)
fprintf(fp, "plot \"%s\" using 0:9:10:xticlabels(everyNth(0, 1, 5)) with filledcurves above %s lt 2 title 'Kumo steigend', \\", bdata(datafile), bdata(fill_kumo_up));
fprintf(fp, "\n\t\"%s\" using 0:9:10:xticlabels(everyNth(0, 1, 5)) with filledcurves below %s lt 4 title 'Kumo fallend', \\", bdata(datafile), bdata(fill_kumo_down));
fprintf(fp, "\n\t\"%s\" using 0:6 with lines lt 3 lw 2,\\",bdata(datafile));
fprintf(fp, "\n\t\"%s\" using 0:7 with lines lt 7 lw 2,\\", bdata(datafile));
fprintf(fp, "\n\t\"%s\" using 0:6 with lines lt 7 lw 2,\\",bdata(datafile));
fprintf(fp, "\n\t\"%s\" using 0:7 with lines lt 3 lw 2,\\", bdata(datafile));
fprintf(fp, "\n\t\"%s\" using 0:8 with lines lt 2 lw 1,\\", bdata(datafile));
fprintf(fp, "\n\t\"%s\" using 0:2:3:4:5:($5 < $2 ? -1 : 1):xticlabels(everyNth(0, 1, 5)) notitle with candles palette\n", bdata(datafile));
......@@ -438,4 +441,67 @@ trend_type ichimoku_get_chikou_trend(float quote_close, float quote_chikou)
return current_trend;
}
bool tenkan_kijun_golden_X(unsigned int daynr, float *tenkan_close, float *kijun_close)
{
unsigned int i;
// in general: bullish signal if tenkan crosses kijun from below to above
// check if tenkan today is above kijun
if(tenkan_close[daynr] > kijun_close[daynr])
{
// now check, if yesterdays tenkan was also above kijun
if(tenkan_close[daynr-1] > kijun_close[daynr-1])
return false; // yeah it was, so definitely no golden cross
else
{
// much more interesting, yesterday we were below or equal kijun
// so loop backwards until we find a tenkan not equal to kijun
for (i = daynr; i-- > 0 ; )
{
if(tenkan_close[i] > kijun_close[i])
return false; // tenkan was above kijun, then eqal then above again
else if(tenkan_close[i] < kijun_close[i])
return true; // tenkan was below kijun, then above (and maybe a couple of days equal)
// next i will be evaluated only if tenkan was equal so far
}
}
return false;
}
else
return false; //no, tenkan is below or equal kijun
}
bool tenkan_kijun_death_X(unsigned int daynr, float *tenkan_close, float *kijun_close)
{
unsigned int i;
//printf("\ndX daynr: %i tenkan: %f kijun: %f",daynr, tenkan_close[daynr], kijun_close[daynr]);
// in general: bearish signal if tenkan crosses kijun from above to below
// check if tenkan today is below kijun
if(tenkan_close[daynr] < kijun_close[daynr])
{
// now check, if yesterdays tenkan was also below kijun
if(tenkan_close[daynr-1] < kijun_close[daynr-1])
return false; // yeah it was, so definitely no death cross
else
{
// much more interesting, yesterday we were above or equal kijun
// so loop backwards until we find a tenkan not equal to kijun
for (i = daynr; i-- > 0 ; )
{
// if(tenkan_close[i] < kijun_close[i])
// return false; // tenkan was below kijun, then eqal then below again
// else if(tenkan_close[i] > kijun_close[i])
// return true; // tenkan was above kijun, then below (and maybe a couple of days equal)
// // next i will be evaluated only if tenkan was equal so far
}
}
return false;
}
else
return false; //no, tenkan is above or equal kijun
}
// end of file
......@@ -19,12 +19,17 @@
#ifndef ICHIMOKU_H
#define ICHIMOKU_H
#include <stdbool.h>
int ichimoku_update_indicators(bstring symbol);
int ichimoku_evaluate_signals(bstring symbol);
int ichimoku_create_plotfile(bstring symbol);
trend_type ichimoku_get_kumo_trend(float quote_close, float quote_senkA, float quote_senkB);
trend_type ichimoku_get_chikou_trend(float quote_close, float quote_chikou);
bool tenkan_kijun_golden_X(unsigned int daynr, float *tenkan_close, float *kijun_close);
bool tenkan_kijun_death_X(unsigned int daynr, float *tenkan_close, float *kijun_close);
#endif // ICHIMOKU_H
//end of file
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment