TF-altProjekte/Indukatoren/Sun/Sun-V2.mq5
super.admin 84cd1a7ab0 convert
2025-05-30 16:31:33 +02:00

248 lines
24 KiB
MQL5

//+------------------------------------------------------------------+
//| Sun-V2.mq5 |
//| Thorsten Fischer Copyright 2019-2020 |
//| https://mql5.tfsystem.de |
//+------------------------------------------------------------------+
#property copyright "Thorsten Fischer Copyright 2019-2020"
#property link "https://mql5.tfsystem.de"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 2
//--- Eingabe Variablen
input color i_ColorLong=clrBlue; // Farbe Long
input color i_ColorShort=clrRed; // Farbe Short
input int i_DrawBegin=0; // Zeichnen Anfang
input string i_ArrowName="Kreis"; // Namen der Periode 0
input int i_PeriodenZahl=12; // Perioden Zahl 0
input ushort i_ArrowCode=159; // Zeichen Arrow Code 0
input int i_ArrowWidth=5; // Zeichen Arrow Width 0
input int i_ArrowShift=6; // Zeichen Arrow Shift 0
//--- Periode 0
int i_Arrow_Periode=i_PeriodenZahl;
//--- Buffer
double i_Arrow_Buffer_High[];
double i_Arrow_Buffer_Low[];
double i_Arrow_Buffer_Flag[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,i_Arrow_Buffer_High,INDICATOR_DATA);
SetIndexBuffer(1,i_Arrow_Buffer_Low,INDICATOR_DATA);
SetIndexBuffer(2,i_Arrow_Buffer_Flag,INDICATOR_DATA);
ArraySetAsSeries(i_Arrow_Buffer_High,true);
ArraySetAsSeries(i_Arrow_Buffer_Low,true);
ArraySetAsSeries(i_Arrow_Buffer_Flag,true);
//---
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW);
PlotIndexSetInteger(0,PLOT_ARROW,i_ArrowCode);
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,i_ArrowShift*-1);
//PlotIndexSetInteger(0,PLOT_SHIFT,0);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,i_DrawBegin);
//PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
//PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,i_ColorLong);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,i_ColorShort);
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,i_ArrowWidth);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetString(0,PLOT_LABEL,i_ArrowName+" High");
//---
PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW);
PlotIndexSetInteger(1,PLOT_ARROW,i_ArrowCode);
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,i_ArrowShift);
//PlotIndexSetInteger(1,PLOT_SHIFT,0);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,i_DrawBegin);
//PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,3);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,i_ColorLong);
//PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,i_ColorShort);
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,i_ArrowWidth);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetString(1,PLOT_LABEL,i_ArrowName+" Low");
//---
PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetString(2,PLOT_LABEL,"Flag Periode");
//---
IndicatorSetString(INDICATOR_SHORTNAME,"TF Sun");
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- Variablen
int suche=rates_total-prev_calculated;
ArraySetAsSeries(open,true);
ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
ArraySetAsSeries(close,true);
//--- Testeinstellungen
i_Arrow_Periode=2;
//---
if(rates_total-prev_calculated==1)
{
suche=1;
}
//---
if(prev_calculated==0)
{
suche--;
//Print("Anfang = "+(string)suche);
//Print(__FUNCTION__+" / rates_total = "+(string)rates_total+" / prev_calculated = "+(string)prev_calculated+" / high = "+(string)high[suche]+" / low = "+(string)low[suche]+" / close = "+(string)close[suche]);
}
//---
for(suche; suche>=0 && !IsStopped(); suche--)
{
//---
if(i_Arrow_Periode<1)return(false);
//--- Variablen
//int rates_total=ArraySize(i_Arrow_Buffer_High);
int f_position_ihighest=0;
int f_position_ilowest=0;
int f_position_high=0;
int f_position_low=0;
//--- Vorhergehende Kontrolle
if(rates_total-suche>1)
{
if(i_Arrow_Buffer_Flag[suche+1]<-2)
{
f_position_high=Periode_Punkt_Suchen(i_Arrow_Buffer_Flag,-1,suche+1);
f_position_low=Periode_Punkt_Suchen(i_Arrow_Buffer_Flag,-2,suche+1);
//Print("Beide Signale gleichzeitig high = "+(string)f_position_high+" / low = "+(string)f_position_low);
if(f_position_high<f_position_low)
{
//Print("High und Low gleich if V1 nächste Kerze");
i_Arrow_Buffer_High[suche+1]=0;
i_Arrow_Buffer_Flag[suche+1]+=1;
}
else
{
//Print("High und Low gleich if V2 nächste Kerze");
i_Arrow_Buffer_Low[suche+1]=0;
i_Arrow_Buffer_Flag[suche+1]+=2;
}
}
}
//---
f_position_high=Periode_Punkt_Suchen(i_Arrow_Buffer_Flag,-1,suche);
f_position_low=Periode_Punkt_Suchen(i_Arrow_Buffer_Flag,-2,suche);
f_position_ihighest=iHighest(NULL,0,MODE_HIGH,i_Arrow_Periode,suche);
f_position_ilowest=iLowest(NULL,0,MODE_LOW,i_Arrow_Periode,suche);
//---
//Print("nach Pos./ rates_total = "+(string)rates_total+" / suche = "+(string)suche+" / i_Arrow_Buffer_High = "+(string)i_Arrow_Buffer_High[suche]+" / i_Arrow_Buffer_Low = "+(string)i_Arrow_Buffer_Low[suche]+" / f_close = "+(string)f_close[suche]);
//Print(" / f_position_ihighest = "+(string)f_position_ihighest+" / f_position_ilowest = "+(string)f_position_ilowest);//+" / f_position_high_delete = "+(string)f_position_high_delete+" / f_position_low_delete = "+(string)f_position_low_delete);
//Print(" / f_position_high = "+(string)f_position_high+" / f_position_low = "+(string)f_position_low);//+" / f_position_high2 = "+(string)f_position_high2+" / f_position_low2 = "+(string)f_position_low2);
//}
//--- V1
if(suche==f_position_ilowest && suche==f_position_ihighest)
{
//Print("High und Low gleich vor if aktuelle Kerze");
if(i_Arrow_Buffer_High[f_position_high]>i_Arrow_Buffer_High[suche])
{
//Print("High und Low gleich if V1 aktuelle Kerze");
f_position_ihighest=0;
}
if(i_Arrow_Buffer_Low[f_position_low]<i_Arrow_Buffer_Low[suche])
{
//Print("High und Low gleich if V2 aktuelle Kerze");
f_position_ilowest=0;
}
}
//Print("nach V1 / rates_total = "+(string)rates_total+" / suche = "+(string)suche+" / i_Arrow_Buffer_High = "+(string)i_Arrow_Buffer_High[suche]+" / i_Arrow_Buffer_Low = "+(string)i_Arrow_Buffer_Low[suche]+" / f_close = "+(string)f_close[suche]);
//Print(" / f_position_ihighest = "+(string)f_position_ihighest+" / f_position_ilowest = "+(string)f_position_ilowest);//+" / f_position_high_delete = "+(string)f_position_high_delete+" / f_position_low_delete = "+(string)f_position_low_delete);
//Print(" / f_position_high = "+(string)f_position_high+" / f_position_low = "+(string)f_position_low);//+" / f_position_high2 = "+(string)f_position_high2+" / f_position_low2 = "+(string)f_position_low2);
//---
if(suche==f_position_ihighest)
{
//Print("Sonderfall high vor");
if(i_Arrow_Buffer_High[f_position_high]<=i_Arrow_Buffer_High[suche])
{
//Print("Sonderfall high 1");
if(f_position_high<f_position_low)
{
//Print("Sonderfall high 1.1");
i_Arrow_Buffer_High[f_position_high]=0;
i_Arrow_Buffer_Flag[f_position_high]=f_position_high;
}
i_Arrow_Buffer_High[suche]=i_Arrow_Buffer_High[suche];
i_Arrow_Buffer_Flag[suche]-=1;
}
else if(f_position_high>f_position_low)
{
//Print("Sonderfall high 2");
i_Arrow_Buffer_High[suche]=i_Arrow_Buffer_High[suche];
i_Arrow_Buffer_Flag[suche]-=1;
}
}
//---
if(suche==f_position_ilowest)// && i_Arrow_Buffer_Low[f_position_low]>i_Arrow_Buffer_Low[suche])
{
//Print("Sonderfall low vor");
//if(!(f_position_low-suche>=i_Arrow_Periode) && !(i_Arrow_Buffer_Low[suche]>i_Arrow_Buffer_Low[f_position_low]))
if(i_Arrow_Buffer_Low[f_position_low]>=i_Arrow_Buffer_Low[suche])
{
//Print("Sonderfall low 1");
if(f_position_low<f_position_high)
{
//Print("Sonderfall low 1.1");
i_Arrow_Buffer_Low[f_position_low]=0;
i_Arrow_Buffer_Flag[f_position_low]=f_position_low;
}
i_Arrow_Buffer_Low[suche]=i_Arrow_Buffer_Low[suche];
i_Arrow_Buffer_Flag[suche]-=2;
}
else if(f_position_high<f_position_low)
{
//Print("Sonderfall low 2");
i_Arrow_Buffer_Low[suche]=i_Arrow_Buffer_Low[suche];
i_Arrow_Buffer_Flag[suche]-=2;
}
}
//---
if(i_Arrow_Buffer_Flag[suche]>=0)
{
i_Arrow_Buffer_Flag[suche]=suche;
}
}
//ChartRedraw();
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Periode_Punkt_Suchen(const double &f_array[],const int f_suche=0,const int f_position=0)
{
//---
int rates_total=ArraySize(f_array);
int i=f_position;
//---
for(i; i<rates_total; i++)
{
if(f_array[i]==f_suche) break;
}
//---
return((i==rates_total)?i-1:i);
}
//+------------------------------------------------------------------+