Experts: Angry Bird (Scalping) - page 14

To add comments, please log in or register
Shabir Ahmad Abdul Saleem
449
Shabir Ahmad Abdul Saleem  

Angry Bird works efficiently if it is used carefully. We need to include trading time option so that we could test the past. I have back tested EURUSD for the last one month, it seems promising but still I am not satisfied. Off course I made some changes to Angry Bird codes.Here is Strategy Tester Report. Please share you opinions.


Ertac Hassan
1911
Ertac Hassan  
No stop loss 🤔
Anacleto59
11
Anacleto59  
shabirmeer:

Angry Bird works efficiently if it is used carefully. We need to include trading time option so that we could test the past. I have back tested EURUSD for the last one month, it seems promising but still I am not satisfied. Off course I made some changes to Angry Bird codes.Here is Strategy Tester Report. Please share you opinions.



Seems doing nice. Only problem is the drawdown of over 92%, a huge risk.
Jack Thomas
1625
Jack Thomas  

This is not going to be a profitable autonomous trading stream over long periods of time.


The back testing shows a 92% drawdown with a 24% model quality.

The EA is not going to produce a reliable profit in it's current condition.

MUSTGAME LTD
234
Olabiyi Atose  
Please can someone send me a working version of the mq5?
MUSTGAME LTD
234
Olabiyi Atose  

After a week of thorough testing and another week of live trading, one can conclude the following:

1. It works!

2. You need a great broker and VPS..

3. A minimum of between £2500 and £7500 equity is advised

4. A single pair (fixed spread) and preferably non-USD.. (EURJPY is best).

5. Initial risk should not exceed 0.01 lot

6. Lastly keep a close eye on the charts and fundamentals...

Anacleto59
11
Anacleto59  

Generally speaking Angry Bird (and similarly Ilan) is a great EA with many inputs that I change often on the fly. For instance, when the market appears to trend strongly then a wider range (default pips) is strongly recommended to avoid excessive positioning before a correction or, better, a reversal.

It would be nice to make default pips a variable according to volatility. Anyone any ideas?


good & safe trading

A

tejeswar1
5
tejeswar1  
This ea some time not working correctly as per parameters if we change slippage to 5 or 6 this ea opening more trades please solve this problem author
EdwinJ
51
EdwinJ  

Made this, works well! Until a few days ago, must have added a line too much i guess... Works now only when i close and restart the platform, any idea's where to look for that?..

By the way, the trailing and modify stoploss, doesn't work, something wrong too…Doesn't matter, is profitable anayway!

4 or 5 digit broker, i think you know which one..Give it a try, didn't let me down for more than 2 months now.


//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí

#property copyright "" 
#property link      ""


//ííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí

//ííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí

extern double CheckAccountslippage;
extern int slippageMaximum = 4;
extern int slippageMinimum = -4;
extern double LotExponent = 0;   // íà ñêîëüêî óìíîæàòü ëîò ïðè âûñòàâëåíèè ñëåäóþùåãî êîëåíà. ïðèìåð: ïåðâûé ëîò 0.1, ñåðèÿ: 0.16, 0.26, 0.43 ...



extern int Glubina = 24;
extern int Glubina1 = 12;
extern bool UseTrendGlubina1= TRUE;
extern int DEL = 3;
extern double Lots = 0.1;          // ðàçåð ëîòà äëÿ íà÷àëà òîðãîâ
extern int lotdecimal = 1;          // ñêîëüêî çíàêîâ ïîñëå çàïÿòîé â ëîòå ðàññ÷èòûâàòü 0 - íîðìàëüíûå ëîòû (1), 1 - ìèíèëîòû (0.1), 2 - ìèêðî (0.01)
extern double TakeProfit = 15.0;    // ïî äîñòèæåíèè ñêîëüêèõ ïóíêòîâ ïðèáûëè çàêðûâàòü ñäåëêó

extern double Stoploss = 150;
extern double ModifySL=9; 
extern double Trail = True;
extern double TrailStart = 5;
extern double TrailStop = 10;

extern double Rsiperiod = 14;
extern double RsiMinimum = 30.0;    // íèæíÿÿ ãðàíèöà RSI
extern double RsiMaximum = 70.0;    // âåðõíÿÿ ãðàíèöà RSI
extern double MACDperiod = 14;
extern double MACDminimum = 12; 
extern double MACDmaximum = 26; 
extern double MACDtrigger = 9;
extern double CCIperiod = 14;
extern double CCIminimum = -100;
extern double CCImaximum = 100;
extern int MagicNumber = 2222;      // âîëøåáíîå ÷èñëî (ïîìîãàåò ñîâåòíèêó îòëè÷èòü ñâîè ñòàâêè îò ÷óæèõ)
int PipStep=0;
//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
extern int MinimalTrades = 2*999999999;                 // ìàêñèìàëüíî êîëè÷åñòâî îäíîâðåìåííî îòêðûòûõ îðäåðîâ
extern bool UseEquityStop = FALSE;
extern double TotalMarginRisk = 5;

//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
double PriceTarget, StartMargin, SellTarget,slippage, Prevorderclose;
double AveragePrice, SellLimit;
double LastBuyPrice, LastSellPrice, Spread;
  
bool flag;
string EAName="TEST25DAILY";
int timeprev = 0, expiration;
int NumOfTrades = 0;
double iLots;
int cnt = 0, total;
bool TradeNow = FALSE, LongTrade = FALSE, ShortTrade = FALSE;
int ticket,Error;
bool  NewOrdersPlaced = FALSE, NeedModifyOrder = False;
double AccountMarginHighAmt, PrevMargin;
//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
int init() {
   Spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   return (0);
}

int deinit() {
   return (0);
}
//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
int start()
{
 double hival=High[iHighest(NULL,0,MODE_HIGH*2,Glubina,1)];    // calculate highest and lowest price from last bar to 24 bars ago
    double loval=Low[iLowest(NULL,0,MODE_LOW/2,Glubina,1)];       // chart used for symbol and time period
    PipStep=NormalizeDouble((hival-loval)/DEL/Point,0);         // calculate pips for spread between orders
    //if (PipStep<DefaultPips/DEL) PipStep = NormalizeDouble(DefaultPips/DEL,0);
    //if (PipStep>DefaultPips*DEL) PipStep = NormalizeDouble(DefaultPips*DEL,0); 
int fibHigh = iHighest(Symbol(),Period(),MODE_HIGH,WindowFirstVisibleBar()-1,1);
     int fibLow  = iLowest(Symbol(),Period(),MODE_LOW,WindowFirstVisibleBar()-1,1);
  double PrevCl;
  double CurrCl;

  
  /************************************************************/
  /* Çäåñü ÷àñòü êîäà, êîòîðàÿ ðàáîòàåò ïðè êàæäîì íîâîì òèêå */ 
  /************************************************************/
  
  //===============================================================================
  // Óáèðàåì òðàë èç ñîâåòíèêà ââèäó ïîëíîãî îòñóòñòâèÿ íàäîáíîñòè â íåì
  //===============================================================================
  //if (UseTrailingStop) 
  //  TrailingAlls(TrailStart, TrailStop, AveragePrice);
  
  //===============================================================================
  // Óáèðàåì çàêðûòèå îðäåðîâ ïî CCI ââèäó îïàñíîñòè ïðèìåíåíèÿ äàííîãî ìåòîäà.
  // Ýòîò ó÷àñòîê êîäà ìîæåò çàêðûòü îðäåðà äàæå òîãäà, êîãäà ýòî íå íóæíî, 
  // äà åùå è ðàáîòàåò òîëüêî ïî òàéìôðåéìó Ì15. Êîðî÷å - ïåðåæèòîê ïðîøëîãî.
  //===============================================================================
  //if ((iCCI(NULL,15,55,0,0)>Stoploss && ShortTrade)||(iCCI(NULL,15,55,0,0)<(-Stoploss) && LongTrade)) 
  //{
  //  CloseThisSymbolAll();
  //  Print("Closed All due to TimeOut");
  //}

  if (timeprev == Time[0]) return(0);   //Ïðîâåðÿåì ïîÿâëåíèå íîâîãî áàðà

  /*****************************************************************************/
  /* Äàëüøå èäåò ÷àñòü êîäà, êîòîðàÿ ðàáîòàåò òîëüêî ïðè ïîÿâëåíèè íîâîãî áàðà */ 
  /*****************************************************************************/
  timeprev = Time[0];

  //===============================================================================
  // Òóò âû÷èñëÿåòñÿ äèíàìè÷åñêèé ïèïñòåï. Õîòü è êîðÿâåíüêî, íî ðàáîòàåò...
  //===============================================================================
   
  {
            // if dynamic pips fail, assign pips extreme value
    Print("PipStep = ",PipStep);

  }

  //===============================================================================
  // Çäåñü îáðàáàòûâàåòñÿ îãðàíè÷åíèå ïî åêâèòè. Ïóñòü ïîêà îñòàåòñÿ êàê åñòü.
  //===============================================================================
  double CurrentPairProfit = CalculateProfit();   //Ïîëó÷àåì òåêóùèé ïðîôèò/óáûòîê ïî ïàðå
  if (UseEquityStop)
    if (CurrentPairProfit < 0.0 && MathAbs(CurrentPairProfit) > TotalMarginRisk / 100.0 * AccountMargin()) 
    {
      CloseThisSymbolAll();
      Print("Closed All due to Stop Out");
      NewOrdersPlaced = FALSE;
    }
   
  //===============================================================================
  // Çäåñü îïðåäåëÿåòñÿ íàïðàâëåíèå, â êîòîðîì òîðãóåò ñîâåòíèê.
  //===============================================================================
  total = CountOfOrders();    //Ôóíêöèþ ïîäñ÷åòà îòêðûòûõ îðäåðîâ ìîæíî ñëåãêà èçìåíèì.
  //if (total == 0) flag = FALSE; //Íàçíà÷åíèå ïåðåìåííîé flag íå ïîíÿë, íî ïîêà ïóñòü îñòàåòñÿ
  
  // Íèæåñëåäóþùèé êîä ìîæíî ñäåëàòü áîëåå ðàöèîíàëüíûì
  /* ------------------------------------------------------------------------------
  for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY) {
            LongTrade = TRUE;
            ShortTrade = FALSE;
            break;
         }
      }
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_SELL) {
            LongTrade = FALSE;
            ShortTrade = TRUE;
            break;
         }
      }
  }*///-----------------------------------------------------------------------------
  if (total > 0)  //âûïîëíÿåì âñå ýòî òîëüêî åñëè åñòü îðäåðà â ðûíêå, èíà÷å íåò ñìûñëà.
  {
    Print("total > 0");
    for (int i = 0; i < OrdersTotal(); i++) 
      if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES))
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        {
          switch(OrderType())
          {
            case OP_BUY:
              LongTrade = TRUE;
              ShortTrade = FALSE;
              break;
            case OP_SELL:
              LongTrade = FALSE;
              ShortTrade = TRUE;
              break;//âûõîäèì èç ãðóïïû switch
          }
          break;//âûõîäèì èç öèêëà for
        }
  //===============================================================================
  // Ìåñòîïîëîæåíèå ñëåäóþùåãî êóñêà êîäà èçìåíèë, ÷òîá ëó÷øå ñëåäîâàòü ëîãèêå.
  // Çäåñü ïðîâåðÿåòñÿ íóæíî ëè îòêðûâàòü ñëåäóþùåå êîëåíî ñåðèè îðäåðîâ
  //===============================================================================
  //if (total > 0 && total <= MaxTrades) //Ýòî òóò óæå íå íóæíî, è MaxTrades òóò
  //{                                    //êàê-òî íè ê ñåëó íè ê ãîðîäó.
    //RefreshRates();   //Ýòî òîæå çäåñü è äàðîì íå íàäî
    LastBuyPrice = FindLastBuyPrice();
    LastSellPrice = FindLastSellPrice();
    if (LongTrade && LastBuyPrice - Ask >= PipStep * Point) TradeNow = TRUE;
    if (ShortTrade && Bid - LastSellPrice >= PipStep * Point) TradeNow = TRUE;
  //}
  }
  else 
  //===============================================================================
  // Ìåñòîïîëîæåíèå ñëåäóþùåãî êóñêà êîäà èçìåíèë, ÷òîá ëó÷øå ñëåäîâàòü ëîãèêå.
  // Çäåñü, åñëè íåò îðäåðîâ â ðûíêå, î÷èùàþòñÿ ïåðåìåííûå íàïðâëåíèÿ òîðãîâëè, ðàçðåøàåòñÿ 
  // íåìåäëåííàÿ òîðãîâëÿ è çà÷åì-òî óñòàíàâëèâàåòñÿ ñòàðòîâîå åêâèòè.
  //===============================================================================
  {
    Print("total = 0");
    ShortTrade = TRUE;
    LongTrade = TRUE;
    TradeNow = TRUE;
    StartMargin = AccountEquity();
  }
   
  //===============================================================================
  // Çäåñü âûñòàâëÿþòñÿ îðäåðà, êîãäà â ðûíêå óæå åñòü îòêðûòûå îðäåðà.
  // Ðåàëèçîâàíî ãðÿçíî è êîðÿâî.
  // Áóäåì ïðèâåñòè ýòî íåïîäîáñòâî ê áîæåìó âèäó.
  //===============================================================================
  /* if (TradeNow) {
      LastBuyPrice = FindLastBuyPrice();
      LastSellPrice = FindLastSellPrice();
      if (ShortTrade) {
         NumOfTrades = total;
         iLots = NormalizeDouble(Lots * MathPow(LotExponent, NumOfTrades), lotdecimal);
         RefreshRates();
         ticket = OpenPendingOrder(1, iLots, Bid, slip, Ask, 0, 0, EAName + "-" + NumOfTrades + "-" + PipStep, MagicNumber, 0, HotPink);
         if (ticket < 0) {
            Print("Error: ", GetLastError());
            return (0);
         }
         LastSellPrice = FindLastSellPrice();
         TradeNow = FALSE;
         NewOrdersPlaced = TRUE;
      } else {
         if (LongTrade) {
            NumOfTrades = total;
            iLots = NormalizeDouble(Lots * MathPow(LotExponent, NumOfTrades), lotdecimal);
            ticket = OpenPendingOrder(0, iLots, Ask, slip, Bid, 0, 0, EAName + "-" + NumOfTrades + "-" + PipStep, MagicNumber, 0, Lime);
            if (ticket < 0) {
               Print("Error: ", GetLastError());
               return (0);
            }
            LastBuyPrice = FindLastBuyPrice();
            TradeNow = FALSE;
            NewOrdersPlaced = TRUE;
         }
      }
   }*/
  if(total > 0) 
    if(TradeNow)
    {
      //Print("PipStep = ",PipStep);
      iLots = NormalizeDouble(Lots * MathPow(LotExponent, total), lotdecimal);
      if (ShortTrade) 
      {
        ticket = SendMarketOrder(OP_SELL, iLots, 0, 0, MagicNumber, EAName + "-" + NumOfTrades + "-" + PipStep, Error);
      }
      if (LongTrade) 
      {
        ticket = SendMarketOrder(OP_BUY, iLots, 0, 0, MagicNumber, EAName + "-" + NumOfTrades + "-" + PipStep, Error);
      }
      if(ticket > 0)
      {
        TradeNow = FALSE;
        NewOrdersPlaced = TRUE;
        NeedModifyOrder = TRUE;
      }
      else
        return(0);
    }

  //===============================================================================
  // Çäåñü âûñòàâëÿþòñÿ îðäåðà, êîãäà â ðûíêå íåò îòêðûòûõ îðäåðîâ.
  // Ðåàëèçîâàíî òàê æå ãðÿçíî è êîðÿâî.
  // È òîæå ïîïûòàåìñÿ ïðèâåñòè ýòî íåïîäîáñòâî ê áîæåìó âèäó.
  //===============================================================================
  /* if (TradeNow && total < 1) {
      PrevCl = iClose(Symbol(), 0, 2);
      CurrCl = iClose(Symbol(), 0, 1);
      SellLimit = Bid;
      BuyLimit = Ask;
      if (!ShortTrade && !LongTrade) {
         NumOfTrades = total;
         iLots = NormalizeDouble(Lots * MathPow(LotExponent, NumOfTrades), lotdecimal);
         if (PrevCl > CurrCl) {
            if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) > RsiMinimum ) {
               ticket = OpenPendingOrder(1, iLots, SellLimit, slip, SellLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink);
               if (ticket < 0) {
                  Print("Error: ", GetLastError());
                  return (0);
               }
               LastBuyPrice = FindLastBuyPrice();
               NewOrdersPlaced = TRUE;
            }
         } else {
            if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) < RsiMaximum ) {
               ticket = OpenPendingOrder(0, iLots, BuyLimit, slip, BuyLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, Lime);
               if (ticket < 0) {
                  Print("Error: ", GetLastError());
                  return (0);
               }
               LastSellPrice = FindLastSellPrice();
               NewOrdersPlaced = TRUE;
            }
         }
         if (ticket > 0) expiration = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours);
         TradeNow = FALSE;
      }
   }*/
  if (TradeNow && total < 1)
  {
    Print("Îòêðûâàåì ïåðâûé îðäåð");
    ticket = 0;
    PrevCl = iClose(Symbol(), 0, 2);
    CurrCl = iClose(Symbol(), 0, 1);
    if (PrevCl > CurrCl) 
     RefreshRates();
    {
      Print("Âûïîëíåíî óñëîâèå SELL");
     
      if (Spread<=8)
      if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) > RsiMinimum + CCIminimum )if((iMACD(NULL,PERIOD_D1,12,26,9,PRICE_CLOSE,MODE_MAIN,0)<0) && (iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,0)<0))
        Print("Ïðîâåðêà RSI ïðîéäåíà");
        
        ticket = SendMarketOrder(OP_SELL, Lots, TakeProfit, 0, MagicNumber, EAName + "-" + total , Error);
      }
    } 
    if (PrevCl < CurrCl) 
    {
      Print("Âûïîëíåíî óñëîâèå BUY");
       if (Spread<=8)
      if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) < RsiMaximum + CCImaximum ) if((iMACD(NULL,PERIOD_D1,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>0) && (iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>0)) 
        Print("Ïðîâåðêà RSI ïðîéäåíà");
        ticket = SendMarketOrder(OP_BUY, Lots, TakeProfit, 0, MagicNumber, EAName + "-" + total , Error);
      }
    }
   
    
      
    
   
      
  

  //total = CountOfOrders();
   
  //===============================================================================
  // Çäåñü äîëæåí ïåðåñ÷èòûâàòüñÿ óðîâåíü ÒÏ äëÿ âñåõ îðäåðîâ â êó÷å, íî íàôèãà
  // ýòî äåëàòü â öèêëå ïåðåáîðà îðäåðîâ òàê è íå âêóðèë.
  // Ðåàëèçîâàíî êîðÿâî.
  // Ïîïûòàåìñÿ ïðèâåñòè ê áîæåìó âèäó.
  //===============================================================================
  
  
      /*for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY) {
               PriceTarget = AveragePrice + TakeProfit * Point;
               BuyTarget = PriceTarget;
               Stopper = AveragePrice - Stoploss * Point;
               flag = TRUE;
            }
         }
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_SELL) {
               PriceTarget = AveragePrice - TakeProfit * Point;
               SellTarget = PriceTarget + Takeprofit * point;
                NeedModifyOrder == TRUE;
                 NewOrdersPlaced = FALSE;
             
               flag = TRUE;
            }
         }
      }*/
   
    
      
    
    
    
      
     
    
  
   
  
    
    
      
     
        
         
            
     
    
  

//ííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
int CountOfOrders()
{
  int count = 0;
  for (int i = 0; i < OrdersTotal(); i++) 
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber)) 
        if ((OrderType() == OP_SELL) || (OrderType() == OP_BUY)) 
          count++;
  return(count);
}

/*
int CountTrades() {
   int count = 0;
   for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
      OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         if (OrderType() == OP_SELL || OrderType() == OP_BUY) count++;
   }
   return (count);
}*/
//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí

void CloseThisSymbolAll() {
   for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
      OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
         }
         Sleep(1000);
      }
   }
}

//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí

//int OpenPendingOrder(int pType, double pLots, double pLevel, int sp, double pr, int sl, int tp, string pComment, int pMagic, int pDatetime, color pColor) {
//   int ticket = 0;
//   int err = 0;
//   int c = 0;
//   int NumberOfTries = 100;
//   switch (pType) {
//   case 2:
//      for (c = 0; c < NumberOfTries; c++) {
//         ticket = OrderSend(Symbol(), OP_BUYLIMIT, pLots, pLevel, sp, StopLong(pr, sl), TakeLong(pLevel, tp), pComment, pMagic, pDatetime, pColor);
//         err = GetLastError();
//         if (err == 0/* NO_ERROR */) break;
//         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
//         Sleep(1000);
//      }
//      break;
//   case 4:
//      for (c = 0; c < NumberOfTries; c++) {
//         ticket = OrderSend(Symbol(), OP_BUYSTOP, pLots, pLevel, sp, StopLong(pr, sl), TakeLong(pLevel, tp), pComment, pMagic, pDatetime, pColor);
//         err = GetLastError();
//         if (err == 0/* NO_ERROR */) break;
//         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
//         Sleep(5000);
//      }
//      break;
//   case 0:
//      for (c = 0; c < NumberOfTries; c++) {
//         RefreshRates();
//         ticket = OrderSend(Symbol(), OP_BUY, pLots, NormalizeDouble(Ask,Digits), sp, NormalizeDouble(StopLong(Bid, sl),Digits), NormalizeDouble(TakeLong(Ask, tp),Digits), pComment, pMagic, pDatetime, pColor);
//         err = GetLastError();
//         if (err == 0/* NO_ERROR */) break;
//         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
//         Sleep(5000);
//      }
//      break;
//   case 3:
//      for (c = 0; c < NumberOfTries; c++) {
//         ticket = OrderSend(Symbol(), OP_SELLLIMIT, pLots, pLevel, sp, StopShort(pr, sl), TakeShort(pLevel, tp), pComment, pMagic, pDatetime, pColor);
//         err = GetLastError();
//         if (err == 0/* NO_ERROR */) break;
//         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
//         Sleep(5000);
//      }
//      break;
//   case 5:
//      for (c = 0; c < NumberOfTries; c++) {
//         ticket = OrderSend(Symbol(), OP_SELLSTOP, pLots, pLevel, sp, StopShort(pr, sl), TakeShort(pLevel, tp), pComment, pMagic, pDatetime, pColor);
//         err = GetLastError();
//         if (err == 0/* NO_ERROR */) break;
//         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
//         Sleep(5000);
//      }
//      break;
//   case 1:
//      for (c = 0; c < NumberOfTries; c++) {
//         ticket = OrderSend(Symbol(), OP_SELL, pLots, NormalizeDouble(Bid,Digits), sp, NormalizeDouble(StopShort(Ask, sl),Digits), NormalizeDouble(TakeShort(Bid, tp),Digits), pComment, pMagic, pDatetime, pColor);
//         err = GetLastError();
//         if (err == 0/* NO_ERROR */) break;
//         if (!(err == 4/* SERVER_BUSY */ || err == 137/* BROKER_BUSY */ || err == 146/* TRADE_CONTEXT_BUSY */ || err == 136/* OFF_QUOTES */)) break;
//         Sleep(5000);
//      }
//   }
//   return (ticket);
//}
/*íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
double StopLong(double price, int stop) {
   if (stop == 0) return (0);
   else return (price - stop * Point);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double StopShort(double price, int stop) {
   if (stop == 0) return (0);
   else return (price + stop * Point);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double TakeLong(double price, int stop) {
   if (stop == 0) return (0);
   else return (price + stop * Point);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double TakeShort(double price, int stop) {
   if (stop == 0) return (0);
   else return (price - stop * Point);
}*/
//=========================================================================
int SendMarketOrder(int Type, double Lots, int TP, int SL, int Magic, string Cmnt, int& Error)
{
  double Price, Take, Stop;
  int Ticket, Slippage, Color, Err; 
  bool Delay = False;
  Print("Ôóíêöèÿ SendMarketOrder");
  while(!IsStopped())
  {
    if(!IsExpertEnabled())
    {
      Error = ERR_TRADE_DISABLED;
      Print("Ýêñïåðòó çàïðåùåíî òîðãîâàòü!");
      return(-1);
    }
    Print("Ýêñïåðòó ðàçðåøåíî òîðãîâàòü");
    if(!IsConnected())
    {
      Error = ERR_NO_CONNECTION;
      Print("Ñâÿçü îòñóòñòâóåò!");
      return(-1);
    }
    Print("Ñâÿçü ñ ñåðâåðîì óñòàíîâëåíà");
    if(IsTradeContextBusy())
    {
      Print("Òîðãîâûé ïîòîê çàíÿò!");
      Print("Îæèäàåì 3 ñåê...");
      Sleep(3000);
      Delay = True;
      continue;
    }
    Print("Òîðãîâûé ïîòîê ñâîáîäåí");
    if(Delay) 
    {
      Print("Îáíîâëÿåì êîòèðîâêè");
      RefreshRates();
      Delay = False;
    }
    else
    {
      Print("Çàäåðæåê íå áûëî");
    }
    switch(Type)
    {
      case OP_BUY:
        Print("Èíèöèàëèçèðóåì ïàðàìåòðû äëÿ BUY-îðäåðà");
        Price = NormalizeDouble( Ask, Digits);
        Take = IIFd(TP == 0, 0, NormalizeDouble( Ask + TP * Point, Digits));
        Stop = IIFd(SL == 0, 0, NormalizeDouble( Ask - SL * Point, Digits));
        Color = Blue;
        break;
      case OP_SELL:
        Print("Èíèöèàëèçèðóåì ïàðàìåòðû äëÿ SELL-îðäåðà");
        Price = NormalizeDouble( Bid, Digits);
        Take = IIFd(TP == 0, 0, NormalizeDouble( Bid - TP * Point, Digits));
        Stop = IIFd(SL == 0, 0, NormalizeDouble( Bid + SL * Point, Digits));
        Color = Red;
        break;
      default:
        Print("Òèï îðäåðà íå ñîîòâåòñòâóåò òðåáîâàíèÿì.");
        return(-1);
    }
    Slippage = MarketInfo(Symbol(), MODE_SPREAD);
    Print("Slippage = ",Slippage);
    if(IsTradeAllowed())
    {
      Print("Òîðãîâëÿ ðàçðåøåíà, îòïðàâëÿåì îðäåð...");
      Ticket = OrderSend(Symbol(), Type, Lots, Price, Slippage, Stop, Take, Cmnt, Magic, 0, Color);
      if(Ticket < 0)
      {
        Err = GetLastError();
        if (Err == 4   || /* SERVER_BUSY */
            //Err == 130 || /* INVALID_STOPS */ 
            Err == 135 || /* PRICE_CHANGED */ 
            Err == 137 || /* BROKER_BUSY */ 
            Err == 138 || /* REQUOTE */ 
            Err == 146 || /* TRADE_CONTEXT_BUSY */
            Err == 136 )  /* OFF_QUOTES */
        {
         
          Delay = True;
          continue;
        }
        else
        {
         
          break;
        }
      }
      break;
    }
    else
    {
      Print("Ýêñïåðòó çàïðåùåíî òîðãîâàòü èëè òîðãîâûé ïîòîê çàíÿò!");
      Print("Îæèäàåì 3 ñåê...");
      Sleep(3000);
      Delay = True;
      continue;
    }
  }
  Print("Îðäåð îòïðàâëåí óñïåøíî. Òèêåò = ",Ticket);
  return(Ticket);
}
//==================================================================
double IIFd(bool condition, double ifTrue, double ifFalse) 
{
  if (condition) return(ifTrue); else return(ifFalse);
}




//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
double CalculateProfit() 
{
  double Profit = 0;
  for (int i = 0; i < OrdersTotal(); i++) 
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber))
        if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL)) 
          Profit += OrderProfit();
  return (Profit);
}
//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
/*
void TrailingAlls(int pType, int stop, double AvgPrice) {
   int profit;
   double stoptrade;
   double stopcal;
   if (stop != 0) {
      for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
         if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
               if (OrderType() == OP_BUY) {
                  profit = NormalizeDouble((Bid - AvgPrice) / Point, 0);
                  if (profit < pType) continue;
                  stoptrade = OrderStopLoss();
                  stopcal = Stoploss;
                  if (stoptrade == 0.0 || (stoptrade != 0.0 && stopcal > stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Aqua);
               }
               if (OrderType() == OP_SELL) {
                  profit = NormalizeDouble((AvgPrice - Ask) / Point, 0);
                  if (profit < pType) continue;
                  stoptrade = OrderStopLoss();
                  stopcal = Stoploss;
                  if (stoptrade == 0.0 || (stoptrade != 0.0 && stopcal < stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Red);
               }
            }
            Sleep(1000);
         }
      }
   }
}*/
//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí



//íííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí

double FindLastBuyPrice() {
   double oldorderopenprice;
   int oldticketnumber;
   double unused = 0;
   int ticketnumber = 0;
   for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
         oldticketnumber = OrderTicket();
         if (oldticketnumber > ticketnumber) {
            oldorderopenprice = OrderOpenPrice();
            unused = oldorderopenprice;
            ticketnumber = oldticketnumber;
         }
      }
   }
   return (oldorderopenprice);
}

double FindLastSellPrice() {
   double oldorderopenprice;
   int oldticketnumber;
   double unused = 0;
   int ticketnumber = 0;
   for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
         oldticketnumber = OrderTicket();
         if (oldticketnumber > ticketnumber) {
            oldorderopenprice = OrderOpenPrice();
            unused = oldorderopenprice;
            ticketnumber = oldticketnumber;
         }
      }
   }
   return (oldorderopenprice);
}
//ííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííííí
double CalculateAveragePrice()
{
  double AveragePrice = 0;
  double Count = 0;
  for (int i = 0; i < OrdersTotal(); i++)
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        if (OrderType() == OP_BUY || OrderType() == OP_SELL) 
        {
           AveragePrice += OrderOpenPrice() * OrderLots();
           Count += OrderLots();
        }
  if(AveragePrice > 0 && Count > 0)
    return( NormalizeDouble(AveragePrice / Count, Digits));
  else
    return(0);
}


bool ModifyOrder( double takeprofit)

{
  while(!IsStopped())
  {
    Print("Ôóíêöèÿ ModifyOrder");
    if(IsTradeContextBusy())
    {
      Print("Òîðãîâûé ïîòîê çàíÿò!");
      Sleep(3000);
      continue;
    }
    Print("Òîðãîâûé ïîòîê ñâîáîäåí");
    if(!IsTradeAllowed())
    {
      Print("Ýêñïåðòó çàïðåùåíî òîðãîâàòü èëè òîðãîâûé ïîòîê çàíÿò!");
      Sleep(3000);
      continue;
    }
    Print("Òîðãîâëÿ ðàçðåøåíà, ìîäèôèöèðóåì îðäåð #",OrderTicket());
    if(!OrderModify(OrderTicket(), OrderOpenPrice(), 0, NormalizeDouble(takeprofit,Digits), 0, Yellow))
    {
      Print("Íå óäàëîñü ìîäèôèöèðîâàòü îðäåð");
      int Err = GetLastError();
     
      break;
      //Sleep(1000);
      //continue;
    }
    else
    {
      Print("Ìîäèôèêàöèÿ îðäåðà âûïîëíåíà óñïåøíî");
      break;
    }
  }

  return(True);
  
}

EdwinJ
51
EdwinJ  
Sorry!!! Didn't knew it would eating that much space... 
To add comments, please log in or register