Author:
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Moving average indicatorMACD HistogramMovement directional index
1 Views
0 Downloads
0 Favorites
iliaaz_EA
/*

*********************************************************************
          
                        Iliaazshareef EA
             http://www.forex-tsd.com/metatrader-4/
                  
*********************************************************************

*/

#property copyright ""
#property link      "http://www.forex-tsd.com/metatrader-4/"

extern int        stopLoss=25;
extern int        takeProfit=200;
extern int        maxLots = 1;
extern double     Lots = 1;
extern int        trailingStop=5;
extern double     macdLevel = 0.00040;
extern int        adxLevel = 22;
extern int        trailingStopStart = 200;

int init() {

   Print ("---- Initializing ----");
   
   return(0);
   
}

int start() {
   
   int total, i;
   double l, ma1, ma2, macdLine, macdHist, adx;
   
   total=OrdersTotal();
   
   ma1 = iMA(NULL,0,24,0,MODE_EMA,PRICE_HIGH,0);
   ma2 = iMA(NULL,0,24,0,MODE_EMA,PRICE_LOW,0);
   macdLine = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
	macdHist = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   adx = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);
      
   for (i=0;i<total;i++){

      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL) {
         
         if ((OrderOpenPrice()-Low[1] >= trailingStopStart*Point) || (macdHist > 0 && High[0] > ma1)) {
               
               OrderModify(OrderTicket(),OrderOpenPrice(),Ask+5*Point,0,0,White);
               
         }
   
      }
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY){
         
         if ((High[1]-OrderOpenPrice() >= trailingStopStart*Point) || (macdHist < 0 && Low[0] < ma2)) {
               
               OrderModify(OrderTicket(),OrderOpenPrice(),Bid-5*Point,0,0,White);
               
         }
      
      }
   
   }
   
   if (total < maxLots) {
	   
	   if (Open[0] > ma1 && macdHist > macdLevel && adx > adxLevel) {
	     
	     placeLongTrade();
	     
	   } else if (Open[0] < ma2 && macdHist < -macdLevel && adx < adxLevel) {
	     
	     placeShortTrade();
	     
	   }
	   
	}

   return(0);

}

void placeLongTrade () {

   double ticket;

   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-stopLoss*Point,Ask+takeProfit*Point,"",16384,0,Blue);
    
   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); 
   }

}

void placeShortTrade () {
   
   double ticket;

   ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+stopLoss*Point,Bid-takeProfit*Point,"",16384,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);   
   }

}

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