ich habe einen kleinen Indikator in MQL5 geschrieben mit dem man einen eigenen Index erstellen kann. Die Aktien mit deren Gewichtung einfach eintragen (entsprechend der SymbolBestimmungen des Brokers . hier am Beispiel Admiral Markets). Ich habe auch ein Beispiel für einen Aktiensplit bei Google eingetragen.....
Ihr könnt die Aktien natürlich erweitern.
Code:
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_level1 14
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_label1 "EIGENER-INDEX"
//--- input params
//---- buffers
double DPCBuffer[];
double A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,CC,OA,OB,OC,OD,OE,OF,OG,OH,OI,OJ,OK,OL,OM,ON,OO,OP,OQ,OR,OS,OT,OU,OV,OW,OAa;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME,"EIGENER-INDEX");
//---- index buffer
SetIndexBuffer(0,DPCBuffer,INDICATOR_DATA);
ArraySetAsSeries(DPCBuffer,true);
// PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,100);
return(INIT_SUCCEEDED);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Calculation |
//+------------------------------------------------------------------+
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[])
{
datetime tm=StringToTime("2014.03.25 00:00:00");
Comment(tm);
//--- check for bars count
if(rates_total<1440/Period())
return(0); //exit with zero result
//--- prevent total recalculation
int i=rates_total-1;
if(prev_calculated>0)
i=rates_total-prev_calculated -1;
//--- current value should be recalculated
if(i<0)
i=0;
//---
while(i>=0)
{
datetime date=iTime(NULL,0,i);
int Hour=TimeHourMQL4(date);
int Minute=TimeMinuteMQL4(date);
// Print("i = ",i," Hour = ",Hour," Minute = ",Minute);
OAa=iOpen("#ATVI",0,i) *4.37;
OA=iOpen("#ADS",0,i)*1.69;
OB=iOpen("#ADBE",0,i)*0.85;
if(date>=tm)OC=iOpen("#GOOG",0,i)*0.18;
if(date<tm)OC=iOpen("#GOOG",0,i)*0.18*0.5;
OD=iOpen("#AMZN",0,i)*0.13;
OE=iOpen("#AAPL",0,i)*3.32;
DPCBuffer[i]=OA+OB+OC+OAa+OD+OE;
i--;
}
//----
return(rates_total);
}
//+------------------ Functions -----------------------------------------------+
int TimeHourMQL4(datetime date)
{
MqlDateTime tm;
TimeToStruct(date,tm);
return(tm.hour);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int TimeMinuteMQL4(datetime date)
{
MqlDateTime tm;
TimeToStruct(date,tm);
return(tm.min);
}
//+------------------------------------------------------------------+