Orders Execution
Checks for the total of closed ordersChecks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
0 Views
0 Downloads
0 Favorites
CM_X
//+------------------------------------------------------------------+
//|                                                         CM_X.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

// Ïàðàìåòðû îðäåðà.
extern int Magik=12345;       // Ìàãèê íîìåð.
extern int TakeProfit=500;    // Ïðîôèò.
extern double K_SL=0.75;      // Êîýô. ñòîïà.
extern bool CloseOrd=true;    // Çàêðûòèå îðäåðîâ ïî ñèãíàëàì.
// Ïàðàìåòðû ëîòà.
extern bool MM=true;          // Èñïîëüçîâàíèå ÌÌ.
extern double Min_lot=0.1;    // Ìèíèìàëüíûé ëîò.
extern double Risk=0.1;       // Ðèñê.
extern double K=2;            // Êîýô. ÌÌ
// Ïàðàìåòðû èíäèêàòîðà.
extern int Fx=12;             // Áûñòðàÿ.
extern double kx=1.682;       // Êîýô. ìåäëåííîé.
extern double L_adx=18;       // Óðîâåíü ADX.
extern double L_o=161.8;      // Óðîâåíü îòêðûòèÿ.
extern double L_c=0;          // Óðîâåíü çàêðûòèÿ.
// Ñòàðò.
int start()
  {
// Ðàñ÷åò ëîòà.
   double StopLoss=NormalizeDouble(TakeProfit*K_SL,0);  
   double lot=NormalizeDouble(AccountFreeMargin()*Risk/10000.0,2);
   if(MM==true)
     {
      if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true)
         {
          if(OrderProfit()<0) lot=OrderLots()*K;
         }
      if(lot<Min_lot) lot=Min_lot;
     }
// Ðàñ÷åò èíäèêàòîðà.
   double Fc,Fp;
   int cnt,ticket,total;
   Fc=iCustom(NULL,0,"CMx",Fx,kx,L_adx,0,1);
   Fp=iCustom(NULL,0,"CMx",Fx,kx,L_adx,0,2);
// Âûñòàâëåíèå îðäåðà.
   total=OrdersTotal();
   if(total<1) 
     {
      if(Fp<(0-L_o)&&Fc>(0-L_o))
        {
         ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"CM_X",Magik,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      if(Fp>L_o&&Fc<L_o)
        {
         ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"CM_X",Magik,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
//  Çàêðûòèå îðäåðà íå ïî ñòîïàì.
   if(CloseOrd==true)
     {  
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&OrderMagicNumber( )==Magik)
           {
            if((Fp>L_c&&Fc<L_c)||(Fc>423.6))
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
                 return(0);
                }
           }
         if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber( )==Magik)
           {
            if((Fp<(0-L_c)&&Fc>(0-L_c))||(Fc>-423.6))
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
               return(0);
              }
           }
     }
     }
   return(0);
  }
// Êîíåö.

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---