Author: BredSS
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt Closes Orders by itself
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
BSS_1_0
//+------------------------------------------------------------------+
//|                                           BSS 1_0.mq4 |
//|                                                           BredSS |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "BredSS"
#property link      ""
double Lot;
extern int    Magic = 66666;

int NObay;
int NOsell;



double MA9, MA21, MA50;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
      
      MA9 = iMA(Symbol(), 0, 4, 0, MODE_EMA, PRICE_CLOSE, 1);
      MA21 = iMA(Symbol(), 0, 8, 0, MODE_EMA, PRICE_CLOSE, 1);
      MA50 = iMA(Symbol(), 0, 100, 0, MODE_EMA, PRICE_CLOSE, 1);
    
      double risk = 0.01;
      double Balans =  AccountBalance( );
      
      Lot = (Balans * risk)/(30*10); 
    
    
      
      if (CountBay() == 0)
   
   if (MA9 < MA21 && MA21 < MA50)
    {
    NObay=OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),3,0,0,0,Magic,0,Blue);
       }  
   if (CountBay() > 0 && MA9 > MA21)
   
    {
    for (int i=OrdersTotal()-1; i>=0; i--)
  {    
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)== true)
    {
      if (OrderType()== OP_BUY && OrderMagicNumber() == Magic)
          
        
    OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);   
    }
    
    }  
    } 
       //--------------------------------------------------------------------
    
        
    if (CountSell() == 0)
    
  if (MA9 > MA21 && MA21 > MA50)
    {
   NOsell=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),3,0,0,0,Magic,0,Red);  
 
    }
   if (CountSell() > 0 && MA9 < MA21)
   
    {
    for ( i=OrdersTotal()-1; i>=0; i--)
  {    
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)== true)
    {
      if (OrderType()== OP_SELL && OrderMagicNumber() == Magic)
          
        
    OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);   
    }
    
    }  
    } 
     
    
   return(0);
  }
//+------------------------------------------------------------------+


int CountSell()
  
   {
   int count = 0;
   for (int trade = OrdersTotal() -1; trade >=0; trade --)
      { OrderSelect (trade, SELECT_BY_POS, MODE_TRADES);
          if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magic)
          {  if (OrderType() ==  OP_SELL)
             count ++;
             
          }
          
      }
      
    return(count);
    }  
    
    //+------------------------------------------------------------------+


int CountBay()
  
   {
   int count = 0;
   for (int trade = OrdersTotal() -1; trade >=0; trade --)
      { OrderSelect (trade, SELECT_BY_POS, MODE_TRADES);
          if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magic)
          {  if (OrderType() ==  OP_BUY)
             count ++;
             
          }
          
      }
      
    return(count);
    }      

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 ---