Author:
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Miscellaneous
It sends emailsIt plays sound alerts
0 Views
0 Downloads
0 Favorites
myea
ÿþ//÷‹èla1uŽN¥b•
Ný€ÑShˆMbúQdkNV{PóX
N^ÿMRb—«ˆèlʑ„vèRMb/f,gû|ß~0Nš[ Rd–ÿ/*   */	ÿÊSÿ*/	ÿTb—èR

//Please note that due to the error can not be published before the next policy backdoor listing, the previous annotated part is the system. Delete (/ * * /) and (* /) the back part.







/*





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

//|                                                         myea.mq4 |

//|                                                  Copyright peace |

//|                                                1006672928@qq.com |

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

#property copyright "peace"

#property link      "1006672928@qq.com"

#property version   "1.00"

#property strict

#include <stdlib.mqh>

#include <stderror.mqh>

 

extern int    MAGICMA            = 1688;

 

extern double Lots               = 0.1;

extern double multiplerate               = 2.0;

extern double maxlots             = 2; 

extern int    orderquantity           = 6;

extern double guaranteedbottomincome=5;

extern bool   SndMl              = false;

datetime SellTime,BuyTime;



//---------------------------------------------------------------------------  

   double currentlyorderlots()

     {

        double lots=0.0;

        if(OrdersTotal()>0)

           {

              for(int i=0;i<OrdersTotal();i++)

                {

                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

                     {

                         if(OrderSymbol()==Symbol())

                           {

                              if(OrderMagicNumber()==MAGICMA) 

                                {

                                   if(OrderLots()!=0)

                                     {

                                        lots=lots+OrderLots();

                                     }

                                   else

                                     {

                                        lots=lots;

                                     }

                                }

                          }

                    }

               }

           }

    else

      {

        return(0);

      }

    return(lots);

      }



//---------------------------------------------------------------------------  

   double currentlyprofit()

     {

        double profit=0.0;

        if(OrdersTotal()>0)

           {

              for(int i=0;i<OrdersTotal();i++)

                {

                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

                     {

                         if(OrderSymbol()==Symbol())

                           {

                              if(OrderMagicNumber()==MAGICMA) 

                                {

                                   if(OrderProfit()!=0)

                                     {

                                        profit=profit+OrderProfit()+OrderCommission()+OrderSwap();

                                     }

                                   else

                                     {

                                        profit=profit;

                                     }

                                }

                          }

                    }

               }

           }

    else

      {

        return(0);

      }

    return(profit);

      }

      

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

//| 

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

int CalculateCurrentOrders(string symbol)

  {

   int buys=0,sells=0;

//----

   for(int i=0;i<OrdersTotal();i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

        {

         if(OrderType()==OP_BUY)  buys++;

         if(OrderType()==OP_SELL) sells++;

        }

     }

//---- return orders volume

   return(buys+sells);

  }



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

//| 

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

double BuyOrders(string symbol)

  {

   double buys=0;

//----

   for(int i=0;i<OrdersTotal();i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

        {

         if(OrderType()==OP_BUY)  buys=buys+OrderLots();

        }

     }

     return(buys);

  }

  

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

//| 

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

double SellOrders(string symbol)

  {

   double sells=0;

//----

   for(int i=0;i<OrdersTotal();i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

        {

         if(OrderType()==OP_SELL) sells=sells+OrderLots();

        }

     }

     return(sells);

  }

  

//---------------------------------------------------------------------------  

   double getlots()

     {

        double lotsok=Lots;

        if(OrdersTotal()>0)

           {

              int i=OrdersTotal()-1;

                {

                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

                     {

                         if(OrderSymbol()==Symbol())

                           {

                              if(OrderMagicNumber()==MAGICMA) 

                                {

                                   if(currentlyprofit()>=0)

                                     {

                                        lotsok=Lots;

                                     }

                                   else

                                     {

                                       lotsok=DoubleToStr(NormalizeDouble(OrderLots()*multiplerate,1),1);

                                       if(lotsok>maxlots)

                                          {

                                             lotsok=maxlots;

                                          }

                                        //break;

                                     }

                                   //break;

                                }

                          }

                    }

               }

           }

    else

      {

        return(Lots);

      }

    return(lotsok);

      }

      

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

//| 

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

void CheckForOpen()

  {



   int    res;

   string sHeaderLetter;

   string sBodyLetter;

 //---- 

   if(Close[0]<Low[1]&&SellTime!=Time[0]&&(SellOrders(Symbol())<BuyOrders(Symbol())||currentlyorderlots()==0))  

     {

      res=OrderSend(Symbol(),OP_SELL,getlots(),Bid,3,0,0,"",MAGICMA,0,Red);

      SellTime=Time[0];BuyTime=Time[1];

       if (SndMl == True && res != -1) 

         {

         sHeaderLetter = "Operation SELL by" + Symbol()+"";

         sBodyLetter = "Order Sell by"+ Symbol() + " at " + DoubleToStr(Bid,4)+ ", and set stop/loss at " + DoubleToStr(0,4)+"";

         sndMessage(sHeaderLetter, sBodyLetter);

         }

      return;

     }

//---- 

   if(Close[0]>High[1]&&BuyTime!=Time[0]&&(BuyOrders(Symbol())<SellOrders(Symbol())||currentlyorderlots()==0))  

     {

      res=OrderSend(Symbol(),OP_BUY,getlots(),Ask,3,0,0,"",MAGICMA,0,Blue);

      BuyTime=Time[0];SellTime=Time[1];

      if ( SndMl == True && res != -1)

      { 

      sHeaderLetter = "Operation BUY at" + Symbol()+"";

      sBodyLetter = "Order Buy at"+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and set stop/loss at " + DoubleToStr(0,4)+"";

      sndMessage(sHeaderLetter, sBodyLetter);

      }

      return;

     }

//----

  }

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

//| 

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

void CheckForClose()

  {

   string sHeaderLetter;

   string sBodyLetter;

   bool rtvl;

   //----  

   if (currentlyorderlots()>Lots&&currentlyprofit()>=guaranteedbottomincome)

      {rtvl=breakorderstotalclose();}

//----  

   for(int i=0;i<OrdersTotal();i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;

      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;

      if(OrderType()==OP_BUY)

        {

         if(Close[0]<Low[1]&&currentlyprofit()>=0){rtvl=OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);}

            if ( SndMl == True && rtvl != False )

            {

            sHeaderLetter = "Operation CLOSE BUY at" + Symbol()+"";

            sBodyLetter = "Close order Buy at"+ Symbol() + " for " + DoubleToStr(Bid,4)+ ", and finish this Trade";

            sndMessage(sHeaderLetter, sBodyLetter);

            }

         break;

        }

      if(OrderType()==OP_SELL)

        {

         if(Close[0]>High[1]&&currentlyprofit()>=0){rtvl=OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);}

         if ( SndMl == True && rtvl != False ) 

         {

         sHeaderLetter = "Operation CLOSE SELL at" + Symbol()+"";

         sBodyLetter = "Close order Sell at"+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and finish this Trade";

         sndMessage(sHeaderLetter, sBodyLetter);

         }

         break;

        }

     }

//----

  }

  

//------------------ èRs^ÓN -------------------

//====================================================================

bool breakorderstotalclose()

  {

  bool rtvl;

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

    {

    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)

      {

      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;

      if(OrderType()==OP_BUY&&OrderMagicNumber()==MAGICMA)

        {rtvl=OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);}

      if(OrderType()==OP_SELL&&OrderMagicNumber()==MAGICMA)

        {rtvl=OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);}

      }

    }

  return(rtvl);

  }

  

//--------------------------------------------------------------------

// 

//--------------------------------------------------------------------

void sndMessage(string HeaderLetter, string BodyLetter)

{

   int RetVal;

   SendMail( HeaderLetter, BodyLetter );

   RetVal = GetLastError();

   if (RetVal!= ERR_NO_MQLERROR) Print ("s^ÓN1Y%: ", ErrorDescription(RetVal));

}

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

//|                                                      

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

void start()

  {

    

       Comment("","\n",

            "¤NfÁTÍy ÿ "+ChartSymbol(0),"\n",

            "","\n",

            "þVhˆhTg ÿ ", _Period,"RŸ”", "\n",

            "","\n",

            "S_MR¢‹US;`ϑ ÿ ", currentlyorderlots()," Kb", "\n",

            "","\n",

            "S_MRYUS;`ϑ ÿ ", BuyOrders(Symbol()),"  Kb", "\n",

            "","\n",

            "S_MRzzUS;`ϑ ÿ ", SellOrders(Symbol())," Kb", "\n",

            "","\n",

            "S_MR¢‹US;`pe ÿ ", CalculateCurrentOrders(Symbol()),"  _", "\n",

            "","\n",

            "S_MR¢‹US;`ÈvN ÿ ", currentlyprofit(),"   $", "\n",

            "","\n",

            "N*N¢‹US¤Nfϑ :  ", getlots()," Kb","\n",

            "","\n"

           );

//---- check for history and trading

   if(Bars<25 || IsTradeAllowed()==false) return;

//----

   if(CalculateCurrentOrders(Symbol())>0){CheckForClose();}

   

   if(CalculateCurrentOrders(Symbol())<orderquantity){CheckForOpen();}

//----

  }

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



*/









#property copyright ""

#property link      ""

#property version   "1.0"

#property strict

#property description ""

#property description ""

string globGVName="PTA_lastOrderTicket";

input int inpNum = 10;                    

input int inpTimerFreqSec = 1;            

input int inpMagic = 0;                  

input string inpSymbol = "";             

input bool inpUsePrint = true;          

input string inpSoundName = "Alert2.wav"; 

int OnInit()

  {

   EventSetTimer(inpTimerFreqSec);

   if(!GlobalVariableCheck(globGVName ) )     

      GlobalVariableSet( globGVName,0 );     

   return( INIT_SUCCEEDED );

  }

void OnTimer()

  {

   int total = OrdersTotal();                  

   if(total <= 0 ) return;                   

   int oType;                                

   int oTicket;                                 

   datetime oTime;                              

   datetime currentTime;                        

   int lastOrderTicket=int(GlobalVariableGet(globGVName));      

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

     {

      if(OrderSelect(i,SELECT_BY_POS)) 

        {

         if(inpSymbol=="" || inpSymbol==OrderSymbol()) 

           {

            oType = OrderType();                                    

            if( oType == OP_BUY || oType == OP_SELL )          

              {

               if(inpMagic==0 || inpMagic==OrderMagicNumber())

                 {

                  oTime=OrderOpenTime();                         

                  currentTime= TimeCurrent();                    

                  oTicket = OrderTicket();                       

                  if( currentTime - oTime >= inpNum && lastOrderTicket < oTicket )     

                    {                                                                 

                     if( inpUsePrint )                                                 

                        Print(_Symbol+"",OrderTicket(),"",inpNum,"");



                     if(!PlaySound(inpSoundName)) 

                        Print(""+inpSoundName+"");



                     GlobalVariableSet(globGVName,oTicket);      

                     break;                                      

                    }

                  else if(lastOrderTicket>=oTicket) break;      

                 }

              }

           }

        }

      else                                     

      Print("",_LastError,"",OrderTicket(),"");

     }

  }

void OnDeinit(const int reason) 

  {

   if(reason == REASON_REMOVE ||      

      reason == REASON_ACCOUNT ||    

      reason == REASON_TEMPLATE )    

     {

      GlobalVariableDel(globGVName);

     }

   EventKillTimer();

  }

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