Download MetaTrader 5

Can someone please check this code?

To add comments, please log in or register
gehtdoch
52
gehtdoch  
Hello,

I Have times a EA code "found" and thought him easy to convert. Similarly Martingail (excluding hedge).

Of the original IS hardly remained.

My code makes what he wants. And driving me nuts. Do I think about it logically correct have made​​,

But probably not structural WILL die cast.

Would someone please check das. free and correct.

So, now I try using pure cave copy code here.

Prima has indeed worked.

Thanks in advance and have a nice weekend.

 

#property copyright     "Author: laplacianlab, CC Attribution-Noncommercial-No Derivate 3.0"
#property link          "https://www.mql5.com/en/forum/ea"
#property version       "1.00"
#property description   "This is a basic trading system which consists in buying when MACD crosses above the waterline line and selling when crosses below it. This EA works along with a monetary management system which has a positive mathematical expectation."

#include <Trade\Trade.mqh>

//+------------------------------------------------------------------+
//| Input block                                                      |
//+------------------------------------------------------------------+

// General inputs

input string pair = "EURUSD";                      // und Andere
input ENUM_TIMEFRAMES timeframe = PERIOD_M1;       // automatisch

// MACD inputs

input int fastEMAPeriod = 13;                      // Fast EMA period
input int slowEMAPeriod = 26;                      // Slow EMA period
input int signalPeriod  = 9;                       // Difference period

// Monetary management strategy inputs

input double size       = 0.1;                     // The size of the operation
input int stufe         = 30;                      // zwischen dem Nachkauf
 
//+------------------------------------------------------------------+
//| Var block                                                        |
//+------------------------------------------------------------------+

int MACDHandle;
double MACDValues[];
string flag;         // 'flag' is 'buy' when we want the robot to buy and 'sell' when we want it to sell. 
int takeProfit;
int flagab; 
int flagauf;

int OnInit()
  {      
   SymbolSelect(pair, true);    
   MACDHandle = iMACD(Symbol(), timeframe, fastEMAPeriod, slowEMAPeriod, signalPeriod, PRICE_CLOSE);   
   ArraySetAsSeries(MACDValues, true);   
//   flag = "buy";
   
   return(0);   
  }
  
void OnDeinit(const int reason)
  {
   IndicatorRelease(MACDHandle);
   ArrayFree(MACDValues);
  }

void OnTick()
  {    
   CTrade trade; 
   MqlTick tick;
   double sl = 0;
   double tp = 0;
   double flag1 = 0;
   double flag2 = 0;
   double ab1 = 0; double ab2 = 0; double ab3 = 0; double ab4 = 0; double ab5 = 0;
   double auf1 = 0; double auf2 = 0; double auf3 = 0; double auf4 = 0; double auf5 = 0; 
   double Lots = 0;
    
   SymbolInfoTick(_Symbol, tick);
         
   if(CopyBuffer(MACDHandle, 1, 0, 2, MACDValues) > 0) 
   { 

//     {   
//       double sl = tick.ask + stopLoss * _Point;     ??????
//       double tp = tick.bid - takeProfit * _Point;   ??????
//     }


//-------------------Short kaufen--------------------------------------      
      if (MACDValues[0] < MACDValues[1] && flag1 == 0)
       {
         {                            
         if (flag1 == 0 && Lots == 0)  
          {
          trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, size, tick.bid, sl, tp);
          Lots = Lots+size;
          ab1 = tick.bid - stufe * _Point;
          }
          
         if (flag1 == 0 && Lots > 0)
          {            
          ab2 = tick.bid - stufe * _Point;
          ab3 = ab2 - stufe * _Point;
          ab4 = ab3 - stufe * _Point;
          ab5 = ab4 - stufe * _Point;
          }
                 
          flag1= 0;
          flagauf = 1;    //für Martin short
          return;
          return;
        }
                   
        if (flagab == 1 && ab1 > tick.bid - stufe * _Point)  
         {    
          trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, size, tick.bid, sl, tp);
          Lots = Lots+size;
          flagab = 2;
         } 
        
        if (flagab == 2 && ab2 > tick.bid - stufe * _Point)
         { 
          trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, size, tick.bid, sl, tp);
          Lots = Lots+size;
          flagab = 3;
         }
        
        if (flagab == 3 && ab3 > tick.bid - stufe * _Point)
         { 
          trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, size, tick.bid, sl, tp);
          Lots = Lots+size;
          flagab = 4;
         }
        
        if (flagab == 4 && ab4 > tick.bid - stufe * _Point) 
         { 
          trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, size, tick.bid, sl, tp);
          Lots = Lots+size;
          flagab = 5;
         }
       }
     return;
// ----------------------------- Short glattstellen + 1 size drehen ------------         
       if (MACDValues[0] > MACDValues[1])       
        {
              if (flagab == 1)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, Lots+size, tick.ask, sl, tp);
                flagauf = 0;
                Lots = size;
               }  
              if (flagab == 2)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, Lots+size, tick.ask, sl, tp);
                flagauf = 0;
                Lots = size;
               }
              if (flagab == 3)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, Lots+size, tick.ask, sl, tp);
                flagauf = 0;
                Lots = size;
               } 
              if (flagab == 4)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, Lots+size, tick.ask, sl, tp);
                flagauf = 0;
                Lots = size;
               }
              if (flagab == 5)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, Lots+size, tick.ask, sl, tp);
                flagauf = 0;
                Lots = size;
               }
        }
      return;        
//------------------------------------Long kaufen-------------------------------------------         
       if (MACDValues[0] > MACDValues[1] && flag1 == 0) 
        {
         {                            
         if (flag1 == 0 && Lots == 0)  
          {
          trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, size, tick.bid, sl, tp);
          Lots = Lots+size;
          auf1 = tick.ask + stufe * _Point;
          }

         if (flag1 == 0 && Lots > 0)
          {            
          auf2 = tick.ask + stufe * _Point;
          auf3 = auf2 + stufe * _Point;
          auf4 = auf3 + stufe * _Point;
          auf5 = auf4 + stufe * _Point;
          }       
          flag1= 0;
          flagauf = 1;    //für Martin short
          return;
          return;
        }                  
        if (flagauf == 1 && auf1 < tick.ask + stufe * _Point)         
         {
          trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, size, tick.ask, sl, tp);
          Lots = Lots+size;
          flagauf = 2;
         }   
        if (flagauf == 2 && auf2 < tick.ask + stufe * _Point)         
         {
          trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, size, tick.ask, sl, tp);
          Lots = Lots+size;
          flagauf = 3;
         }
        if (flagauf == 3 && auf3 < tick.ask + stufe * _Point)          
         {
          trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, size, tick.ask, sl, tp);
          Lots = Lots+size;
          flagauf = 4;
         }
        if (flagauf == 4 && auf4 < tick.ask + stufe * _Point)         
         {
          trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, size, tick.ask, sl, tp);
          Lots = Lots+size;
          flagauf = 5;
         }                  
        }
      return;
//--------------------------------Long glatt stellen------------------  
       if (MACDValues[0] < MACDValues[1])
        {       
              if (flagauf == 1)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots+size, tick.bid, sl, tp);
                flagab = 0;
                Lots = size;
               }  
              if (flagauf == 2)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots+size, tick.bid, sl, tp);
                flagab = 0;
                Lots = size;
               }
              if (flagauf == 3)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots+size, tick.bid, sl, tp);
                flagab = 0;
                Lots = size;
               } 
              if (flagauf == 4)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots+size, tick.bid, sl, tp);
                flagab = 0;
                Lots = size;
               }
              if (flagauf == 5)
               {
                trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots+size, tick.bid, sl, tp);
                flagab = 0;
                Lots = size;
               }
        }
       return;
   }
  }

 

Alain Verleyen
Moderator
31181
Alain Verleyen  
gehtdoch:
Hello,

I Have times a EA code "found" and thought him easy to convert. Similarly Martingail (excluding hedge).

Of the original IS hardly remained.

My code makes what he wants. And driving me nuts. Do I think about it logically correct have made​​,

But probably not structural WILL die cast.

Would someone please check das. free and correct.

So, now I try using pure cave copy code here.

Prima has indeed worked.

Thanks in advance and have a nice weekend.

Your code is all but logically correct.

I have made comments with my initials (AV). Only first part, see attached file.

Files:
testforum.mq5 10 kb
gehtdoch
52
gehtdoch  
angevoyageur:

Your code is all but logically correct.

I have made comments with my initials (AV). Only first part, see attached file.

Whoa, I'm not a trained programmer. And will probably never be one.
Thanks for the comments.
To add comments, please log in or register