← Назад к списку файлов

mgh ea_v2.2.mq4

Поиск по коду файла

#property description "MGH System (Martingale Grid & Hedging) by Kfx"
#property description ""
#property description "EA autor: GoldenEA; some changes: SwingMan"
#property description "minor modifications proposed by Paracelsus #post 707"

#include <WinUser32.mqh>

#include <OrderSendReliable_v2.1.mqh>

input double   LotsMultiplier =2.5;
extern int     MaxLevel       =2;
extern double  BaseLot        = 0.10;
extern double  maxLot         =2;
extern int     MagicNo        = 2900;
extern   int   BasicOrder_Grid=10;
input double Basket_TakeProfit=6;
int  InsideOrder_Grid=5;
bool Enable_InsideOrders=false;
double  ClsPercnt      = 0.1;

double OrderGap;

string         TextDisplay;

static double  pt;
string         TradeComment="mghA";

int            numBuy,numSell,prevnumBuy,prevnumSell,numPenBuy,numPenSell;

double         maxBuyLots,maxSellLots,totalProfit,AllProfit,prevEquity=0,currEquity=0;

static double  lowestBuyPrice,highestSellPrice,lowestSellPrice,highestBuyPrice,lowestSellPrice2,highestBuyPrice2;
datetime       lastBuyTime,lastSellTime;
double         totalSellProfit,totalBuyProfit;
int            lastestOrderCloseType;

double         AveragePrice,TotalVolume;
bool           EAsuspended=false;
datetime       SuspenEATime=0;

void init()
  {
      // код доступен только после оплаты
   }

void start()
  {
      // код доступен только после оплаты
   }

void PlaceSingleOrder(string sym,int type,double lotsize,double price)
  {
   int ticket;

   color cColor;
   if(type==OP_BUY) cColor=clrBlue; else
   if(type==OP_SELL) cColor=clrRed;

   lotsize=NormalizeDouble(lotsize,2);

   ticket=OrderSendReliable(sym,type,lotsize,price,0,0,0,TradeComment,MagicNo,0,cColor);

   Print("  ###  Lot size: ",DoubleToStr(lotsize,2));
   Print("  ###  Grid size: ",DoubleToStr(OrderGap,0),"   numBuy= ",numBuy,"   numSell=",numSell);  

   if(ticket>0 && type==OP_SELL)
     {
      while(prevnumSell==numSell)
        {
         CountOrders();
        }
      prevnumSell=numSell;
     }

   if(ticket>0 && type==OP_BUY)
     {
      while(prevnumBuy==numBuy)
        {
         CountOrders();
        }
      prevnumBuy=numBuy;
     }

   if(ticket<0)
     {

      int e=GetLastError();
      Print("Error: "+DoubleToStr(e,0));
     }

  }

void CountOrders()
  {
   numBuy=0; numSell=0; maxBuyLots=0; maxSellLots=0; totalSellProfit=0; totalBuyProfit=0;
   double buyProfit1=0; double buyProfit2=0; double sellProfit1=0; double sellProfit2=0;
   lowestBuyPrice=9999; highestSellPrice=0; lowestSellPrice=9999; highestBuyPrice=0;lowestSellPrice2=9999; highestBuyPrice2=0;
   bool bRes;
   for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
     {
      bRes=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)
           {
            numBuy++;
            buyProfit1+=OrderProfit()+OrderSwap()+OrderCommission();
            if(OrderOpenPrice()<lowestBuyPrice)
              {
               lowestBuyPrice=OrderOpenPrice();
               lastBuyTime=OrderOpenTime();
              }
            if(OrderOpenPrice()>highestBuyPrice)
              { highestBuyPrice=OrderOpenPrice();}

            if(OrderLots()>maxBuyLots) maxBuyLots=OrderLots();
           }
         else if(OrderType()==OP_SELL)
           {
            numSell++;
            sellProfit1+=OrderProfit()+OrderSwap()+OrderCommission();
            if(OrderOpenPrice()>highestSellPrice)
              {
               highestSellPrice=OrderOpenPrice();
               lastSellTime=OrderOpenTime();
              }
            if(OrderOpenPrice()<lowestSellPrice)
              { lowestSellPrice=OrderOpenPrice();}

            if(OrderLots()>maxSellLots) maxSellLots=OrderLots();
           }

         totalBuyProfit=buyProfit1;
         totalSellProfit=sellProfit1;
        }
     }
  }

void  SetTakeProfit(int type,double tp)
  {
   for(int i=0; i<OrdersTotal(); i++)
     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderType()==type)
         ModifySelectedOrder(type,tp);
     }
  }

void CloseOpenPairPositions()
  {
   bool bRes;
   for(int i=10; i>=0; i--)
     {
      for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
        {
         bRes=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         if(OrderMagicNumber()==MagicNo)
           {
            if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
               OrderCloseReliable(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5);
            else
            if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
               OrderCloseReliable(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5);
           }
        }
     }
  }

void ModifySelectedOrder(int type,double tp)
  {
   bool ok=OrderModifyR

Показано первые 50% кода (символов: 9753)

Как получить полную версию?

Введите ваш email и нажмите кнопку, чтобы перейти к оплате.