Einzelnen Beitrag anzeigen
  #10 (permalink)  
Alt 18.11.16
Kronenchakra Kronenchakra ist offline
Gesperrter Benutzer
 
Registriert seit: Feb 2016
Ort: 2100 Österreich
Beiträge: 313
Kronenchakra befindet sich auf einem aufstrebenden Ast
Standard

Na klar sind die dynamisch, sonst hätt's ja keinen Sinn.
Wieviel ist es dir denn wert? Mach einen Vorschlag!
Einstellbar sind Anzahl der Kanäle (1-3) und die Periodenlängen.

Das mit den Wendepunkten ist auch nicht gerade das gelbe vom Ei.
Ich stell das mal hier rein.

Code:
//+------------------------------------------------------------------+
//|                                             DEMA_Peak_Signal.mq5 |
//|                                Copyright © 2016 Ing. Otto Pauser |
//+------------------------------------------------------------------+

#include <MyBuffers.mqh>

#property copyright "Copyright © 2016 Ing. Otto Pauser"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3

input int  inp_PeriodFast = 5;      // MA Period fast
input int  inp_PeriodSlow = 6;      // MA Period slow
input bool inp_Realtime   = true;   // Realtime
input bool inp_UseDEMAs   = true;   // Use DEMAs
input bool inp_ShowMAs    = true;   // Show MAs
input int  inp_LineWidth  = 1;      // MA Linewidth
input int  inp_ArrowSize  = 1;      // Arrowsize

double MA_fast[],    // buffer for fast MA
       CrossUp[],    // buffer for signal UP
       CrossDn[];    // buffer for signal DN

int    haFastMA;     // handle for fast MA
int    idxStart;     // startindex for calculation

int OnInit()         // Custom indicator initialization function  
{                    // initialize the plotbuffers
   InitIndi(CrossUp,INDICATOR_DATA,DRAW_ARROW,STYLE_SOLID,inp_ArrowSize,clrLime,233,"Signal UP");
   InitIndi(CrossDn,INDICATOR_DATA,DRAW_ARROW,STYLE_SOLID,inp_ArrowSize,clrRed ,234,"Signal DN");
   
   ENUM_DRAW_TYPE  Draw_Type = DRAW_NONE;
   if(inp_ShowMAs) Draw_Type = DRAW_LINE;

   InitIndi(MA_fast,INDICATOR_DATA,Draw_Type ,STYLE_SOLID,inp_LineWidth,clrLime);
   
   if(inp_UseDEMAs)
      haFastMA = iDEMA(NULL, 0, inp_PeriodFast, 0, PRICE_CLOSE);
   else
      haFastMA = iMA(NULL, 0, inp_PeriodFast, 0, MODE_LWMA, PRICE_CLOSE);
      
   if(haFastMA==INVALID_HANDLE)
      return(MyAlert("Invalid handle for iMA"));

   return(INIT_SUCCEEDED);
}
                                             // Custom indicator iteration function
int OnCalculate (const int rates_total,      // size of input time series 
                 const int prev_calculated,  // bars handled in previous call 
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[])        // Spread 
{
   if(prev_calculated==0)                    // first call of OnCalculate
      {
         ArrayInitialize(CrossUp,NULL);
         ArrayInitialize(CrossDn,NULL);
         ArrayInitialize(MA_fast,NULL);
         idxStart=0;
      }
   else
      idxStart=prev_calculated-1;

   if(BarsCalculated(haFastMA)<rates_total) return(0);   // check if all data calculated, try again next call 

   if(!inp_Realtime)                                     // no Realtime, only new candles
      if(prev_calculated==rates_total) 
         return(rates_total);
   
   int to_copy;                                          // calculate wow much to copy 
   if(prev_calculated>rates_total || prev_calculated<=0) 
      to_copy=rates_total; 
   else 
     { 
      to_copy=rates_total-prev_calculated;               // last value is always copied 
      to_copy++; 
     } 
   
   if(CopyBuffer(haFastMA,0,0,to_copy,MA_fast)<=0) return(MyAlert("Error CopyBuffer fastMA",0));   // try to copy and check

   for(int i=idxStart;i<rates_total;i++)                 // calculate the signals
      {
         double Range=GetAverage(high, low, i, 9);
         if(PeakPassedLo(MA_fast, i)) CrossUp[i] = low [i]-Range*0.5; else
                                      CrossUp[i] = NULL;
         if(PeakPassedHi(MA_fast, i)) CrossDn[i] = high[i]+Range*0.5; else
                                      CrossDn[i] = NULL;
      }
      
   return(rates_total);
}
Die Funktionen PeakPassedHi und PeakPassedLo gehören noch in die Buffers.mqh Datei hinein.
Code:
bool PeakPassedHi(const double &Buf[], int idx)
{
   if(idx<3) return(false);
   return((Buf[idx-1]> Buf[idx  ]) &&
          (Buf[idx-2]<=Buf[idx-1]) &&
          (Buf[idx-3]<=Buf[idx-2])
         );
};

bool PeakPassedLo(const double &Buf[], int idx)
{
   if(idx<3) return(false);
   return((Buf[idx-1]< Buf[idx  ]) &&
          (Buf[idx-2]>=Buf[idx-1]) &&
          (Buf[idx-3]>=Buf[idx-2])
         );
};
Für einen TradingRobot sind das allerdings noch zuwenig Informationen.
Ausserdem ist da noch ein Fisch drin, da ja die Signale abwechseld kommen sollten.
Ich adaptiere gerade ähnliches für die echten Ticks (Marktübersicht->Tab Ticks) für einen ScalpingRobot.
Der sollte Anfang nächsten Jahres laufen. Bin schon sehr gespannt auf die ersten Tests.

LG Otto