Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedChecks for the total of closed orders
Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
MAmod
//+------------------------------------------------------------------+
//|                                                        MAExp.mq4 |
//|                                             http://liteforex.net |
//|                                                              Alf |
//+------------------------------------------------------------------+
#property copyright "http://liteforex.net"
#property link      "Alf"

//---- input parameters
extern int       ST=50;


double    Lot=0.1;

extern int MaFast = 6;

extern int MaSlow = 2;
extern double    MinLot=0.1;
extern double    MaxLot=5;
extern double    K=1.68;// êîýôèöìåíò èçìåíåíèÿ ëîòà, 1 ëîò íåèçìåíÿåòñÿ 2 óäâîåíèå 3 óòðîåíèå è ò.ä.

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   lot();
   Comment("Lot=",Lot);
   
   if(OrdersTotal()==1)
   {
      OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()==OP_BUY && sell()) {OrderSend(Symbol(),OP_SELL,Lot,Bid,3,Ask+ST*Point,0);Alert("Sell");return(0);}
      if(OrderType()==OP_SELL && buy()) {OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Bid-ST*Point,0);Alert("Buy");return(0);}
      
   }
   
   if(OrdersTotal()==0)
   {
      
      if(buy()){OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Bid-ST*Point,0);Alert("Buy");return(0);}
      if(sell()){OrderSend(Symbol(),OP_SELL,Lot,Bid,3,Ask+ST*Point,0);Alert("Sell");}
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

bool buy()
{
   if(iMA(Symbol(),0,MaFast,0,MODE_EMA,PRICE_MEDIAN,1)<iMA(Symbol(),0,MaSlow,0,MODE_EMA,PRICE_MEDIAN,1)&&iMA(Symbol(),0,MaFast,0,MODE_EMA,PRICE_MEDIAN,0)>iMA(Symbol(),0,MaSlow,0,MODE_EMA,PRICE_MEDIAN,0))return(true);
   return(false); 
}

bool sell()
{
      if(iMA(Symbol(),0,MaFast,0,MODE_EMA,PRICE_MEDIAN,1)>iMA(Symbol(),0,MaSlow,0,MODE_EMA,PRICE_MEDIAN,1)&&iMA(Symbol(),0,MaFast,0,MODE_EMA,PRICE_MEDIAN,0)<iMA(Symbol(),0,MaSlow,0,MODE_EMA,PRICE_MEDIAN,0))return(true);
   return(false); 
}

void lot()
{
   if(OrdersHistoryTotal()==0) {Lot=MinLot;return;}
   OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
   if(OrderProfit()>0) {Lot=MinLot;return;}
   Lot=OrderLots()*K;
   if(MinLot<1) Lot=MathRound(Lot*10)/10;
   else Lot=MathRound(Lot);
   if(Lot<MinLot)Lot=MinLot;
   if(Lot>MaxLot)Lot=MaxLot;

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