Einzelnen Beitrag anzeigen
  #132 (permalink)  
Alt 22.05.16
MA-EA MA-EA ist offline
Elite Mitglied
 
Registriert seit: Sep 2015
Beiträge: 1.178
MA-EA befindet sich auf einem aufstrebenden Ast
Standard

Hallo.

Muss statt "CCIPeriod" im EA "InpCCIPeriod" eingetragen werden?

CCI Quellcode
Code:
//+------------------------------------------------------------------+
//|                                                          CCI.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Commodity Channel Index"
#property strict

#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers    1
#property indicator_color1     LightSeaGreen
#property indicator_level1    -100.0//im EA ein getragen
#property indicator_level2     100.0//im EA ein getragen
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//--- input parameter
input int InpCCIPeriod=14; // ?
//--- buffers
double ExtCCIBuffer[];
double ExtPriceBuffer[];
double ExtMovBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
// ???
int OnInit(void)
  {
   string short_name;
//--- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
   SetIndexBuffer(1,ExtPriceBuffer);
   SetIndexBuffer(2,ExtMovBuffer);
//--- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtCCIBuffer);
//--- check for input parameter
// ???
//-------------------------------------------------------------------------------------------------------------

   if(InpCCIPeriod<=1) // ?
     {
      Print("Wrong input parameter CCI Period=",InpCCIPeriod); // ?
      return(INIT_FAILED);
     }//im EA eingetragen
//-------------------------------------------------------------------------------------------------------------

//---
   SetIndexDrawBegin(0,InpCCIPeriod); // ?
//--- name for DataWindow and indicator subwindow label
   short_name="CCI("+IntegerToString(InpCCIPeriod)+")"; // ?
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//-------------------------------------------------------------------------------------------------------------

//+------------------------------------------------------------------+
//| Commodity Channel 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,k,pos;
   double dSum,dMul;
//---
   if(rates_total<=InpCCIPeriod || InpCCIPeriod<=1) // ?
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtCCIBuffer,false);
   ArraySetAsSeries(ExtPriceBuffer,false);
   ArraySetAsSeries(ExtMovBuffer,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
//--- initial zero
   if(prev_calculated<1)
     {
      for(i=0; i<InpCCIPeriod; i++) // ?
        {
         ExtCCIBuffer[i]=0.0;
         ExtPriceBuffer[i]=(high[i]+low[i]+close[i])/3;
         ExtMovBuffer[i]=0.0;
        }
     }
//--- calculate position
   pos=prev_calculated-1;
   if(pos<InpCCIPeriod) // ?
      pos=InpCCIPeriod; // ?

//--- typical price and its moving average
   for(i=pos; i<rates_total; i++)
     {
      ExtPriceBuffer[i]=(high[i]+low[i]+close[i])/3;
      ExtMovBuffer[i]=SimpleMA(i,InpCCIPeriod,ExtPriceBuffer); // ? 
     }

//--- standard deviations and cci counting
   dMul=0.015/InpCCIPeriod; // ?
   pos=InpCCIPeriod-1; // ?
   if(pos<prev_calculated-1)
      pos=prev_calculated-2;
   i=pos;
   while(i<rates_total)
     {
      dSum=0.0;
      k=i+1-InpCCIPeriod; // ?
      while(k<=i)
        {
         dSum+=MathAbs(ExtPriceBuffer[k]-ExtMovBuffer[i]);
         k++;
        }
      dSum*=dMul;
      if(dSum==0.0)
         ExtCCIBuffer[i]=0.0;
      else
         ExtCCIBuffer[i]=(ExtPriceBuffer[i]-ExtMovBuffer[i])/dSum;
      i++;
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
CCI-ichimoku EA
Code:
#property copyright "Valerius_CCI_Ichimoku_EA_Metatrader4.mq4"
int MagicNumber = 541371052;
string Name = "Valerius_CCI_Ichimoku_EA_Metatrader4";
//-------------------------------------------------------------------------------------------------------------

//Globale Variablen
//Open Time
extern string Open_Orders_From = "07:00:00";
extern string Open_Orders_Till = "20:15:00";
extern int TimeFrame = 60;
extern string TimeFrames = "Current:0;M1:1; M5:5; M15:15; M30:30; H1:60; H4:240; D1:1440";
//-------------------------------------------------------------------------------------------------------------

//Close Time
extern string Close_all_Orders = "true=Yes/false=No";
extern bool Close_all_Orders_after_Time_O_Clock = true;
extern string Close_all_Orders_after = "20:40:00";
//-------------------------------------------------------------------------------------------------------------

//Sonstige GV
extern double Lots = 0.01;
extern int Slippage = 100000;
extern int Max_Spread = 40;
int Ticket, i;
double Spread, PointSet;
bool IsInvested, CloseTicket;
//-------------------------------------------------------------------------------------------------------------

//Ichimoku Kinko Hyu Globale Variablen
extern int TENKANSEN = 5;// Tenkan-sen
extern int KIJUNSEN = 20;// Kijun-sen
extern int SENKOUSPANB = 50;// Senkou Span B
//-------------------------------------------------------------------------------------------------------------

//CCI GV
extern int InpCCIPeriod = 14; // ?
extern double indicator_level1 = -100.0;
extern double indicator_level2 = 100.0;
input ENUM_APPLIED_PRICE CCI_Price = PRICE_WEIGHTED;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init(){
return(0);}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){
return(0);}
//+------------------------------------------------------------------+
//| expert star function                                            |
//+------------------------------------------------------------------+
int start(){
//-------------------------------------------------------------------------------------------------------------
{//Ichi
double TKS= iIchimoku(NULL,0,5,20,50,MODE_TENKANSEN,1);//5 rot
double KJS = iIchimoku(NULL,0,5,20,50,MODE_KIJUNSEN,1);//20 blau
double SKS_A = iIchimoku(NULL,0,5,20,50,MODE_SENKOUSPANA,1);//nicht einstellbar
double SKS_B = iIchimoku(NULL,0,5,20,50,MODE_SENKOUSPANB,1);//50
double CKS = iIchimoku(NULL,0,5,20,50,MODE_CHIKOUSPAN,1);//nicht einstellbar

//CCI
double CCI = iCCI(_Symbol,_Period, InpCCIPeriod, CCI_Price, 1);// ?
double IL1 = iCCI(_Symbol,_Period, indicator_level1, CCI_Price, 1);//-100
double IL2 = iCCI(_Symbol,_Period, indicator_level2, CCI_Price, 1);//+100
}
//-------------------------------------------------------------------------------------------------------------

if (Digits <= 3) PointSet = 0.01; else PointSet = 0.0001;
if (Digits <= 1) PointSet = 1;
Spread=Ask-Bid;
double S = Spread;
double MS = Max_Spread;
Lots = MathMax(MathMin(Lots, MarketInfo(Symbol(),MODE_MAXLOT)),MarketInfo(Symbol(),MODE_MINLOT));
//-------------------------------------------------------------------------------------------------------------

//Define Vars
if (TimeFrame==0) TimeFrame=NULL;

//Time
datetime TC = TimeCurrent();
datetime F = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Open_Orders_From);
datetime T = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Open_Orders_Till);

//Close all Order after
bool CAA = (Close_all_Orders_after_Time_O_Clock);
datetime CA = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Close_all_Orders_after);
//-------------------------------------------------------------------------------------------------------------

//Kurs
double CP = iClose(Symbol(), TimeFrame, 1);
//-------------------------------------------------------------------------------------------------------------

//Check position
IsInvested = false;
for (i=OrdersTotal()-1; i>=0; i--){
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if((OrderType()==OP_SELL || OrderType()==OP_BUY) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) IsInvested=true;}}
//-------------------------------------------------------------------------------------------------------------

//Open Trade
if (!IsInvested){
if (TC>F && TC<T && S<=MS && CCI>IL2 && CP>TKS && TKS>KJS) OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, Name + " Buy(#" + MagicNumber + ")", MagicNumber, 0, Blue);
if (TC>F && TC<T && S<=MS && CCI<IL1 && CP<TKS && TKS<KJS) OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, Name + " Sell(#" + MagicNumber + ")", MagicNumber, 0, Red);}
//-------------------------------------------------------------------------------------------------------------

//Close Trade
if (IsInvested){
for (i=OrdersTotal()-1; i>=0; i--){
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){

if (OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()){
if((CP<TKS && TKS<KJS) || (CAA=true && TC>CA)) OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, DarkBlue);}

if (OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()){
if((CP>TKS && TKS>KJS) || (CAA=true && TC>CA)) OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, FireBrick);}}}}
return(0);}
Angehängte Dateien
Dateityp: mq4 Valerius_CCI_Ichimoku_EA_Metatrader4.mq4 (5,6 KB, 4x aufgerufen)
Dateityp: mq4 CCI.mq4 (4,5 KB, 0x aufgerufen)