Einzelnen Beitrag anzeigen
  #7 (permalink)  
Alt 17.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

Zuerst kompilieren, dann evtl. den MT5 neu starten damit er es mitbekommt.
Sollte er aber normalerweise.
Eine kleine Korrektur ist noch dazugekommen, so ab Zeile 101.
Das ist erforderlich um im RealTime Mode die Signale wieder wegzulöschen falls sich die MAs doch nicht kreuzen.
Code:
//+------------------------------------------------------------------+
//|                                        LWMA_Crossover_Signal.mq5 |
//|                                Copyright © 2016 Ing. Otto Pauser |
//| Original code                          LWMA-Crossover_Signal.mq4 |
//|         Copyright © 2005, Jason Robinson (jnrtrading)            |
//|                   http://www.jnrtading.co.uk                     |
//+------------------------------------------------------------------+
//| Allows you to enter two lwma periods and it will then show you at|
//| which point they crossed over. It is more usful on the shorter   |
//| periods that get obscured by the bars / candlesticks and when    |
//| the zoom level is out. Also allows you then to remove the emas   |
//| from the chart. (lwmas are initially set at 5 and 6)             |
//+------------------------------------------------------------------+

#include <MyBuffers.mqh>

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

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_ShowMAs    = true;   // Show MAs
input int  inp_LineWidth  = 1;      // MA Linewidth
input int  inp_ArrowSize  = 1;      // Arrowsize

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

int    haFastMA,     // handle for fast MA
       haSlowMA;     // handle for slow 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);
   InitIndi(MA_slow,INDICATOR_DATA,Draw_Type ,STYLE_SOLID,inp_LineWidth,clrRed );

   haFastMA = iMA(NULL, 0, inp_PeriodFast, 0, MODE_LWMA, PRICE_CLOSE);
   haSlowMA = iMA(NULL, 0, inp_PeriodSlow, 0, MODE_LWMA, PRICE_CLOSE);
   
   if((haFastMA==INVALID_HANDLE) || (haSlowMA==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);
         ArrayInitialize(MA_slow,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(BarsCalculated(haSlowMA)<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
   if(CopyBuffer(haSlowMA,0,0,to_copy,MA_slow)<=0) return(MyAlert("Error CopyBuffer slowMA",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(IsCrossingUp(MA_fast, MA_slow, i)) CrossUp[i] = low [i]-Range*0.5; else
                                               CrossUp[i] = NULL;
         if(IsCrossingDn(MA_fast, MA_slow, i)) CrossDn[i] = high[i]+Range*0.5; else
                                               CrossDn[i] = NULL;
      }
      
   return(rates_total);
}
Ich probier noch eine Variante mit DEMA anstelle von LWMA und verwende die Wendepunkte des schnelleren. Das schmeiß ich dann auch hier rein, aber erst morgen.

Wahrscheinlich könntest du LR-Kanäle (LR=Lineare Regression) brauchen, die sind IMHO absolut super, hab ich auf Lager, muss ich aber schon was dafür verlangen, war viel Arbeit.

LG Otto

Geändert von Kronenchakra (17.11.16 um 23:12 Uhr) Grund: Ergänzung