Hallo zusammen,
ich versuche grade den Mayer Multiple Indikator nachzubauen. Als Linienindikator habe ich das geschafft, allerdings hänge ich grade bei der zweiten Version. In diesem Indikator soll der Wert als Säule dargestellt werden, welche Ihre Farbe wechselt wenn ein bestimmter Wert unter- bzw. überschritten wird.
Wenn ich den Indikator anwende bekomme ich entweder Säulen in nur einer Farbe, oder gar keine Säulen ausgedruckt. Habt ihr mir evtl einen Tipp, woran es liegen kann?
Hallo!
- Bitte benutze die Code-Taste aus der Editierzeile (</>) bzw. Alt+s um Code zu veröffentlichen.
- Für unterschiedliche Farben ein und desselben Indikatorpuffers muss man für jede Farbe einen eigenen Puffer verwenden!
- Oder man verwendet einzelne Objekte, was alles ziemlich verlangsamt!!!
Wenn ich den Indikator anwende bekomme ich entweder Säulen in nur einer Farbe, oder gar keine Säulen ausgedruckt. Habt ihr mir evtl einen Tipp, woran es liegen kann?
Wenn du ein färbiges Histogramm möchtest must du
#property indicator_type1 DRAW_LINE als #property indicator_type1 DRAW_COLOR_HISTOGRAM definieren
Du brachst dann noch eine andere Definition für die Farben.
Such dir irgend ein Beispiel wo DRAW_COLOR_LINE oder DRAW_COLOR_HISTOGRAM verwendet wird.
Un schau dir das verhalten dieses Indis im Tester an. Im EA ist Bar[0] mit Vorsicht zu verwenden.
Da jede neue Bar gleiche Werte für O,H,L,C hat beginnt der ForceIndex bei einer neuen Bar IMMER bei 0.
Ist trotzdem ein interessanter (und einfacher) Indi.Damit meine Indikatorkenntnisse nicht einrosten habe ich mich an dem Force_Index probiert.
Das Ergebnis: Wahlweise Linien, Farblinien, Histogram, Farbhistogramm. Alle Indikator-Eigenschaften sind dynamisch erstellt, damit einstellbar.
//+------------------------------------------------------------------+ //| Force_Index_V2.mq5 | //| Copyright © 2018 Ing. Otto Pauser | //| https://www.mql5.com/de/users/kronenchakra | //+------------------------------------------------------------------+ #property copyright "Copyright © 2019, Ing. Otto Pauser" #property link "https://www.mql5.com/de/users/kronenchakra" #property version "2.00" //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 1 //+------------------------------------------------------------------+ enum ENUM_INDI_TYPE // subset of drawtypes { DRAW_LI, // DRAW_LINE DRAW_CL, // DRAW_COLOR_LINE DRAW_HI, // DRAW_HISTOGRAM DRAW_CH // DRAW_COLOR_HISTOGRAM }; //+------------------------------------------------------------------+ input int InpMAPeriod = 13; // MA period input ENUM_MA_METHOD InpMAMethod = MODE_SMA; // MA method input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price input ENUM_APPLIED_VOLUME InpAppliedVolume = VOLUME_TICK; // Volumes input ENUM_INDI_TYPE inpFIType = DRAW_CH; // Drawtype input int inpLineWidth = 1; // Linewidth input int inpHistWidth = 2; // Histogramwidth input color inpColor =clrDodgerBlue; // Color input color inpColorUP = clrLime; // Color UP input color inpColorDN = clrRed; // Color DN //+------------------------------------------------------------------+ int MAHandle; double MABuffer[]; double FIBuffer[]; double FIColors[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { // indicator buffers mapping SetIndexBuffer(0,FIBuffer,INDICATOR_DATA); SetIndexBuffer(1,FIColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,MABuffer,INDICATOR_CALCULATIONS); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod); // sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth); switch(inpFIType) { case DRAW_LI : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth); PlotIndexSetInteger(0,PLOT_LINE_COLOR,inpColor); break; case DRAW_CL : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_LINE); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpColorUP); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpColorDN); break; case DRAW_HI : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_HISTOGRAM); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpHistWidth); PlotIndexSetInteger(0,PLOT_LINE_COLOR,inpColor); break; case DRAW_CH : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_HISTOGRAM); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpHistWidth); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpColorUP); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpColorDN); break; } IndicatorSetString(INDICATOR_SHORTNAME,"Force("+string(InpMAPeriod)+")"); // name for DataWindow and indicator subwindow label MAHandle=iMA(NULL,0,InpMAPeriod,0,InpMAMethod,InpAppliedPrice); // get MA handle if(MAHandle==INVALID_HANDLE) // check MA handle { Alert("*ERROR* creating iMA handle"); return(INIT_FAILED); } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Force Index | //+------------------------------------------------------------------+ 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[]) { int i,start,to_copy; if(rates_total<InpMAPeriod) // check for rates total return(0); // try again next tick if(BarsCalculated(MAHandle)<rates_total) // check for MA ready return(0); // try again next tick // calculate amount of data needed to_copy=(prev_calculated==0)?rates_total:rates_total-prev_calculated+1; if(CopyBuffer(MAHandle,0,0,to_copy,MABuffer)!=to_copy) // get ma buffer return(0); // preliminary calculations start=(prev_calculated<InpMAPeriod)?InpMAPeriod:prev_calculated-1; if(InpAppliedVolume==VOLUME_TICK) // the main loop of calculations { for(i=start; i<rates_total && !IsStopped(); i++) { FIBuffer[i]=tick_volume[i]*(MABuffer[i]-MABuffer[i-1]); FIColors[i]=(FIBuffer[i]>0)?0:1; } } else { for(i=start; i<rates_total && !IsStopped(); i++) { FIBuffer[i]=volume[i]*(MABuffer[i]-MABuffer[i-1]); FIColors[i]=(FIBuffer[i]>0)?0:1; } } return(rates_total); }
Viel Erfolg damit.
//+------------------------------------------------------------------+ //| MayerMultipleHist.mq5 | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 1 //+------------------------------------------------------------------+ enum ENUM_INDI_TYPE // subset of drawtypes { DRAW_LI, // DRAW_LINE DRAW_CL, // DRAW_COLOR_LINE DRAW_HI, // DRAW_HISTOGRAM DRAW_CH // DRAW_COLOR_HISTOGRAM }; //+------------------------------------------------------------------+ input int InpMAPeriod = 200; // MA period input ENUM_MA_METHOD InpMAMethod = MODE_SMA; // MA method input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price input ENUM_APPLIED_VOLUME InpAppliedVolume = VOLUME_TICK; // Volumes input ENUM_INDI_TYPE inpFIType = DRAW_CH; // Drawtype input int inpLineWidth = 1; // Linewidth input int inpHistWidth = 2; // Histogramwidth input color inpColor =clrDodgerBlue; // Color input color inpColorUP = clrLime; // Color UP input color inpColorDN = clrRed; // Color DN input color inpColorOD = clrGray; input double UpperThreshold = 2.4; input double LowerThreshold = 1; //+------------------------------------------------------------------+ int MAHandle; double MABuffer[]; double FIBuffer[]; double FIColors[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { // indicator buffers mapping SetIndexBuffer(0,FIBuffer,INDICATOR_DATA); SetIndexBuffer(1,FIColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,MABuffer,INDICATOR_CALCULATIONS); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod); // sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth); switch(inpFIType) { case DRAW_LI : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth); PlotIndexSetInteger(0,PLOT_LINE_COLOR,inpColor); break; case DRAW_CL : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_LINE); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpColorUP); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpColorDN); PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,inpColorOD); break; case DRAW_HI : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_HISTOGRAM); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpHistWidth); PlotIndexSetInteger(0,PLOT_LINE_COLOR,inpColor); break; case DRAW_CH : PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_HISTOGRAM); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpHistWidth); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpColorUP); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpColorDN); PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,inpColorOD); break; } IndicatorSetString(INDICATOR_SHORTNAME,"Mayer Multiple Hist("+string(InpMAPeriod)+")"); // name for DataWindow and indicator subwindow label MAHandle=iMA(NULL,0,InpMAPeriod,0,InpMAMethod,InpAppliedPrice); // get MA handle if(MAHandle==INVALID_HANDLE) // check MA handle { Alert("*ERROR* creating iMA handle"); return(INIT_FAILED); } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Force Index | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { int i,start,to_copy; if(rates_total<InpMAPeriod) // check for rates total return(0); // try again next tick if(BarsCalculated(MAHandle)<rates_total) // check for MA ready return(0); // try again next tick // calculate amount of data needed to_copy=(prev_calculated==0)?rates_total:rates_total-prev_calculated+1; if(CopyBuffer(MAHandle,0,0,to_copy,MABuffer)!=to_copy) // get ma buffer return(0); // preliminary calculations start=(prev_calculated<InpMAPeriod)?InpMAPeriod:prev_calculated-1; if(InpAppliedVolume==VOLUME_TICK) // the main loop of calculations { for(i=start; i<rates_total && !IsStopped(); i++) { FIBuffer[i]=price[i]/MABuffer[i]; if(FIBuffer[i]>UpperThreshold){ FIColors[i]=0; }else if(FIBuffer[i]<LowerThreshold){ FIColors[i]=1; }else{ FIColors[i]=2; } } } else { for(i=start; i<rates_total && !IsStopped(); i++) { FIBuffer[i]=price[i]/MABuffer[i]; if(FIBuffer[i]>UpperThreshold){ FIColors[i]=0; }else if(FIBuffer[i]<LowerThreshold){ FIColors[i]=1; }else{ FIColors[i]=2; } } } return(rates_total); }
Danke für die Tipps. Mit der genialen Vorlage hats geklappt.
Ciao,
h4rry
Danke für die Tipps. Mit der genialen Vorlage hats geklappt.
Ciao,
h4rry

- Freie Handelsapplikationen
- Über 8.000 Signale zum Kopieren
- Wirtschaftsnachrichten für die Lage an den Finanzmärkte
Sie stimmen der Website-Richtlinie und den Nutzungsbedingungen zu.
Hallo zusammen,
ich versuche grade den Mayer Multiple Indikator nachzubauen. Als Linienindikator habe ich das geschafft, allerdings hänge ich grade bei der zweiten Version. In diesem Indikator soll der Wert als Säule dargestellt werden, welche Ihre Farbe wechselt wenn ein bestimmter Wert unter- bzw. überschritten wird.
Wenn ich den Indikator anwende bekomme ich entweder Säulen in nur einer Farbe, oder gar keine Säulen ausgedruckt. Habt ihr mir evtl einen Tipp, woran es liegen kann?
//+------------------------------------------------------------------+
//| Force_Index.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Red,Green,Yellow
//--- input parameters
input int InpForcePeriod=200; // Period
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // MA method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
input ENUM_APPLIED_VOLUME InpAppliedVolume=VOLUME_TICK; // Volumes
input double UpperThreshold=2.4;
input double LowerThreshold=1;
//--- indicator buffers
double ExtForceBuffer[];
double ExtMABuffer[];
double buffer_color_line[];
//--- MA handle
int ExtMAHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtForceBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
//Assign the color indexes array with indicator's buffer
SetIndexBuffer(2,buffer_color_line,INDICATOR_COLOR_INDEX);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpForcePeriod);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"Mayer Multiple Hist("+string(InpForcePeriod)+")");
//--- get MA handle
ExtMAHandle=iMA(NULL,0,InpForcePeriod,0,InpMAMethod,InpAppliedPrice);
//Specify the number of color indexes, used in the graphic plot
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3);
//Specify colors for each index
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Red); //Zeroth index -> Blue
PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Yellow); //First index -> Orange
PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,Green); //First index -> Orange
//return(0);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Force Index |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
int i,limit;
//--- check for rates total
if(rates_total<InpForcePeriod)
return(0);
//---
int calculated=BarsCalculated(ExtMAHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtMAHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//---- get ma buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtMAHandle,0,0,to_copy,ExtMABuffer)<=0)
{
Print("Getting MA data is failed! Error",GetLastError());
return(0);
}
//--- preliminary calculations
if(prev_calculated<InpForcePeriod)
limit=InpForcePeriod;
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++){
ExtForceBuffer[i]=price[i]/(ExtMABuffer[i]);
if(ExtForceBuffer[i]>UpperThreshold){
//Print("IF");
buffer_color_line[i]=0;
}else if(ExtForceBuffer[i]<LowerThreshold){
//Print("ELSE IF");
buffer_color_line[i]=2;
}else{
//Print("ELSE");
buffer_color_line[i]=1;
}
//Print("ExtForceBuffer " + ExtForceBuffer[i]);
//Print("buffer_color_line " + buffer_color_line[i]);
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
Cheers und Danke,
H4rry