Einzelnen Beitrag anzeigen
  #16 (permalink)  
Alt 26.01.15
Benutzerbild von Nap$ter
Nap$ter Nap$ter ist offline
Neues Mitglied
 
Registriert seit: Jan 2015
Beiträge: 21
Nap$ter befindet sich auf einem aufstrebenden Ast
Lightbulb

So habe mich mal dran gemacht und versucht den Befehl in einen Indikator einzubauen. Leider funktioniert es nicht. Vermutlich irgendwo ein Fehler. Die "Test.exe" Datei ist im File Ordner des MT4's. Hab noch wenig Erfahrung mit dem Programieren von MQL.
Auszug aus dem Indikator:

Code:
#property copyright "Copyright © 2015 - R.ST"
#property link      ""

#property indicator_separate_window
#property indicator_minimum -35.0
#property indicator_maximum 35.0
#property indicator_buffers 5
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrDodgerBlue
#property indicator_color3 clrRed
#property indicator_color4 clrLime
#property indicator_level2 12.0
#property indicator_level3 -12.0
#property indicator_style1 2;

extern int period =4;
extern ENUM_MA_METHOD MaMethod=MODE_SMA;
extern ENUM_APPLIED_PRICE MaPrice = PRICE_MEDIAN;

extern int RSIPeriod=4;
extern ENUM_APPLIED_PRICE RsiPrice=PRICE_CLOSE;
extern double RsiOverBoughtLevel=90.0;
extern double RsiOverSoldLevel=10.0;

extern double Level =24.0;

extern bool   alertsOn        = true;
extern bool   alertsOnCurrent = true;
extern bool   alertsMessage   = true;
extern bool   alertsNotification = false;
extern bool   alertsSound     = false;
extern bool   alertsEmail     = false;
extern bool   filehandle      = true;

double AboveBuff[],ShortBuff[],LongBuff[],BelowBuff[];
double RSIBuffer[];

// ---
int init() {
   SetIndexBuffer(0, AboveBuff); SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, 2);                          // Lime Above 0
   SetIndexBuffer(1, BelowBuff); SetIndexStyle(1, DRAW_HISTOGRAM, EMPTY, 2);                          // Lime Below 0
   SetIndexBuffer(2, ShortBuff); SetIndexStyle(2, DRAW_ARROW, EMPTY, 2);      SetIndexArrow(2, 108); // Red
   SetIndexBuffer(3, LongBuff); SetIndexStyle(3, DRAW_ARROW, EMPTY, 2);       SetIndexArrow(3, 108); // Blue

   SetIndexLabel(0, "Above");
   SetIndexLabel(1, "Below");  
   SetIndexLabel(2, "SHORT");  
   SetIndexLabel(3, "LONG");
   
   SetIndexBuffer(4,RSIBuffer);
   SetIndexStyle(4,DRAW_NONE);
   
   SetLevelStyle(STYLE_DOT, 0, SteelBlue);

   IndicatorShortName(" Similar to Fx MTN + RSI ");
   return (0);
}
	 	    			  		  		   		 	 	 	 	 		 						 	   				  	   	 		 			  			  	     		  	 			   	 	     			 	 		 		     			 	 	  		 	  		   			 			    	
// ---
int deinit() {
 return(0);
}
		    			 	 			 	 	  	  		  	   	 				 			     		 	 	 	 		 	 	 	 	 		 		 		  	    					   		  	    	 					 	  	    	 			 	 	 		 	 	  	 	   	  	 	
// ---
int start() {

   int filehandle=FileOpen("Test.exe",FILE_WRITE|FILE_CSV);

   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-counted_bars,Bars-1);
      
      for (int i = limit; i >=0; i--) 
      {
         //double Temp = 0.0; for (int j = i; j < i + Per; j++) Temp += (High[j] + Low[j]) / 2.0;
         double Main =iMA(NULL,0,period,0,MaMethod,MaPrice,i) ;//Temp / Per;
              //  Temp = 0.0;  for (j = i; j < i + Per; j++) Temp += High[j] - Low[j];
         double Minr = 0.2 * iATR(NULL,0,period,i);//(Temp / Per);
         
            if (Minr!=0)
            {
               AboveBuff[i] = 3.0 * (High[i]  - Main) / Minr;
               BelowBuff[i] = 3.0 * (Low[i]   - Main) / Minr;
            }               
            ShortBuff[i] = EMPTY_VALUE;
            LongBuff[i] = EMPTY_VALUE;
            if (AboveBuff[i] >  Level) ShortBuff[i] =  Level+1;
            if (BelowBuff[i] < -Level) LongBuff[i] = -(Level+1);
         //rsi:
         RSIBuffer[i]=iRSI(NULL,0,RSIPeriod,RsiPrice,i);
      }
   manageAlerts();
   return(0);
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;
      if (ShortBuff[whichBar] != EMPTY_VALUE || LongBuff[whichBar] != EMPTY_VALUE)
      {
         if (ShortBuff[whichBar] !=  EMPTY_VALUE &&  GetRsiAlert(whichBar)==OP_SELL)doAlert(whichBar,"down + RSI overbougth @ Level " +RsiOverBoughtLevel);
         if (LongBuff[whichBar] !=  EMPTY_VALUE  && GetRsiAlert(whichBar)==OP_BUY) doAlert(whichBar,"up + RSI oversold @ Level " +RsiOverSoldLevel);
      }
   }
}

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message =  StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," SimilarFxMNT signal ",doWhat);
          if (alertsMessage) Alert(message);
          if (alertsEmail)   SendMail(StringConcatenate(Symbol()," SimilarFxMNT "),message);
          if (alertsNotification) SendNotification(message);
          if (alertsSound)   PlaySound("alert2.wav");
          if (filehandle)    FileOpen("Test.exe",FILE_READ|FILE_CSV);
          
   }
}

int GetRsiAlert(int AlertCandle) {
 if(RSIBuffer[AlertCandle+1]<RsiOverBoughtLevel && RSIBuffer[AlertCandle]>RsiOverBoughtLevel) return(OP_SELL);//RSI RsiOverBoughtLevel
 if(RSIBuffer[AlertCandle+1]>RsiOverSoldLevel && RSIBuffer[AlertCandle]<RsiOverSoldLevel) return(OP_BUY);//RSI RsiOverSoldLevel
 return(99);//nothing
}
Leider wird beim Alarm die "Test.exe" nicht geöffnet...
Indikator im Anhang. Wäre cool von euch wenn sich jemand diesen mal kurz anschaut und die Fehler beseitigt.
Angehängte Dateien
Dateityp: mq4 SimilarFxMTN+RSI_Alerts_V3.mq4 (5,3 KB, 4x aufgerufen)