Author:
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
EA
ÿþ//+------------------------------------------------------------------+

//|                                                           EA.mq4 |

//|                                                                hg |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "hg"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict



extern double my_lots= 0.01;        //Lots

extern int    zhi_s  =100;      //StopLoss

extern string magic  ="yang15d25@163.com";



int    dian_c=6,

       wei_s =100;

double dian_z=0.1;

      

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

    if(Point < 0.001)

    {

        dian_z=0.0001;

        wei_s=100000;

    }

     else if(Point == 0.001)

     {

         dian_z=0.01;

         wei_s=1000;

     }

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//---

      static datetime  time=0;

      static double    zhi_y  =0;      //takepofit

      int       ab=0;

      bool      bo=false;

      double    close_1=Close[1],

                 close_2=Close[2],

                 open_1=Open[1],

                 open_2=Open[2];

      

      

      double MA_5 =iMA(NULL, 0,14,0,MODE_SMMA,PRICE_MEDIAN,0);

      

      dian_c=StrToInteger(DoubleToStr((Ask-Bid)*wei_s, 0));

      

      for(int i=OrdersTotal()-1; i>=0; i--)

      {

          bo= OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);

          if(bo==false)break;

          if(OrderSymbol()!=Symbol())continue;

          if(OrderType() == OP_BUY && Bid >= zhi_y)

          {

              bo=OrderClose(OrderTicket(), OrderLots(), Bid, 5);

              if(bo==true)

              {

                  for(int L=OrdersTotal()-1; L>=0; L--)

                  {

                      bo=OrderSelect(L, SELECT_BY_POS, MODE_HISTORY);

                      if(bo==false)break;

                      if(OrderSymbol()!=Symbol())continue;

                      if(OrderType() == OP_BUY)

                      {

                          OrderClose(OrderTicket(), OrderLots(), Bid, 5);

                          zhi_y=0;

                      }

                      RefreshRates();

                  }

              }

          }

          else if(OrderType() == OP_SELL && Ask <= zhi_y)

          {

              bo=OrderClose(OrderTicket(), OrderLots(), Ask, 5);

              if(bo==true)

              {

                  for(int LI=OrdersTotal()-1; LI>=0; LI--)

                  {

                      bo=OrderSelect(LI, SELECT_BY_POS, MODE_HISTORY);

                      if(bo==false)break;

                      if(OrderSymbol()!=Symbol())continue;

                      if(OrderType() == OP_SELL)

                      {

                          OrderClose(OrderTicket(), OrderLots(), Ask, 5);

                          zhi_y=0;

                      }

                      RefreshRates();

                  }

              }

              

          }

      }

      if(close_2 > MA_5 && close_1 > MA_5 && open_2 - close_2 >0 && open_1 - close_1 > 0 && time != Time[0])

      {

          if(!Check(Symbol(), my_lots, OP_SELL)) return;

          if(my_lots<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))

          {

              Comment("¤NfϑǏ\àeÕl¤Nf");

              return;

          }

          OrderSend(Symbol(), OP_BUY, my_lots, Bid, dian_c, 0, 0, magic, 00000000);

          

              time=Time[0];

              zhi_y=Low[1];

            

      }

      else if(close_2 < MA_5 && close_1 < MA_5 && close_2 - close_2 >0 && close_1 - open_1 > 0 && time != Time[0])

      {

         if(!Check(Symbol(), my_lots, OP_SELL)) return;

         if(my_lots<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))

          {

              Comment("¤NfϑǏ\àeÕl¤Nf");

              return;

          }

          OrderSend(Symbol(), OP_SELL, my_lots, Ask, dian_c, 0, 0, magic, 0000000);

          

              time=Time[0];

              zhi_y=High[1];

          

      }

  }

//+------------------------------------------------------------------+

bool Check(string symb, double lots,int type)

  {

   double free_margin=AccountFreeMarginCheck(symb,type, lots);

   //-- ‚YœgDÑ‘
NY

   if(free_margin<0)

     {

      string oper=(type==OP_BUY)?"pNeQ":"VSúQ";

      Print("DÑ‘
N³åNۏLˆ", oper," ",lots, " ", symb, " •ï‹÷S",GetLastError());

      return(false);

     }

   //--- ÀhŒšbŸR

   return(true);

  }

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