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

Wäääh?

Wer die Zeitsch... hinbekommt, kriegt nen EA umsonst.

Code:
//+-------------------------------+
//|Valerius_3MA_EA_Metatrader4.mq4|
//+-------------------------------+
#property copyright "Valerius_3MA_EA_Metatrader4"
int MagicNumber = 541371052;
string Name = "Valerius_3MA_EA_Metatrader4";

//Globale Variablen
//Zeitbegrenzung
extern Time Open_Orders_From = 09:00:00;
extern Time Open_Orders_Till = 17:00:00;
extern int TimeFrame = 60;
extern string TimeFrames = "Current:0;M1:1; M5:5; M15:15; M30:30; H1:60; H4:240; D1:1440";
//GDs
extern int Moving_Average_1 = 2;
extern int Moving_Average_2 = 3;
extern int Moving_Average_3 = 6;
extern int GD_Type = 0;
extern string GD_Types = "SMA:0; EMA:1; SMMA;2; LWMA:3";
int GD_Shift = 0;//EA funktioniert nicht mit Shift
//Sonstige GV
extern double Lots = 0.01;
int Slippage = 1000;
extern int Max_Spread = 35;
int Ticket, i;
double Spread, PointSet;
bool IsInvested, CloseTicket;
//+------------------------------+
//|expert initialization function|
//+------------------------------+
int init(){
return(0);}
//+--------------------------------+
//|expert deinitialization function|
//+--------------------------------+
int deinit(){
return(0);}
//+---------------------+
//|expert start function|
//+---------------------+
int start(){
if (Digits <= 3) PointSet = 0.01; else PointSet = 0.0001;
if (Digits <= 1) PointSet = 1;
Spread=Ask-Bid;
Lots = MathMax(MathMin(Lots, MarketInfo(Symbol(),MODE_MAXLOT)),MarketInfo(Symbol(),MODE_MINLOT));

//Define Vars
//Zeitbegrenzung
if (TimeFrame==0) TimeFrame=NULL;
datetime Time TC = datetime TimeCurrent; //Semicolon expected?
datetime Time F = Open_Orders_From; //Semicolon expected?
datetime Time T = Open_Orders_Till; //Semicolon expected?
//Kurse
double LC = iClose(Symbol(), TimeFrame, 1);
double O = iOpen(Symbol(), TimeFrame, 0);
double H = iHigh(Symbol(), TimeFrame, 1);
double L = iLow(Symbol(), TimeFrame, 1);
//GDs
double MA1 = iMA(Symbol(), TimeFrame, Moving_Average_1, GD_Shift, GD_Type, PRICE_CLOSE, 1);//2
double MA2 = iMA(Symbol(), TimeFrame, Moving_Average_2, GD_Shift, GD_Type, PRICE_CLOSE, 1);//3
double MA3 = iMA(Symbol(), TimeFrame, Moving_Average_3, GD_Shift, GD_Type, PRICE_CLOSE, 1);//6

//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 && Spread <= Max_Spread && O>MA1 && L>MA1 && MA1>MA2 && MA2>MA3) OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, Name + " Buy(#" + MagicNumber + ")", MagicNumber, 0, Blue);
if (TC>F && TC<T && Spread <= Max_Spread && O<MA1 && H<MA1 && MA1<MA2 && MA2<MA3) 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(LC<MA1 && MA1<MA2) OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, DarkBlue);}
if (OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()){
if(LC>MA1 && MA1>MA2) OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, FireBrick);}}}}
return(0);}