MAcross_1.1

Author: Mr Gao
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyChecks for the total of closed ordersIt automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
MAcross_1.1
ÿþ//+------------------------------------------------------------------+

//|                                                  MA Cross1.1.mq4 |

//|                                                          Mr Gao  |

//|                                                 364429340@qq.com |

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

#property copyright "Mr Gao"

#property link      "364429340@qq.com"

#property version   "1.10"

#property strict

//---

input double            Kbpe=0.1;

input string            ô‹f1="bk_c‰'YŽNs^ðSbk_cP–6R+¹pî]";

input double            bk_c=100;

input double            bkÈv=300;

input bool              ÍSTs^ÓN=false;

input bool              ûy¨Rbk_c=false;

input int               YUSÐc_c=400;

input int               zzUSÐc_c=400;

input string            ô‹f2="S_Ðc_cY¹pÿRbk_cûy¨RX¹p";

input int               ûy¨Rbk_cE^¦^=200;

input double            
P•bû|pe=1.5;

input double            g'Y
P•bKbpe=20;

input bool              eQ:WGW¿~¤NÉS_ÓN=true;

input ENUM_MA_METHOD    MA1{|‹W=MODE_EMA;//eQ:Wë_¿~{|‹W

input int               MA1=10;//eQ:WáO÷S„vë_¿~

input ENUM_MA_METHOD    MA2{|‹W=MODE_EMA;//eQ:Wba¿~{|‹W

input int               MA2=20;//eQ:WáO÷S„vba¿~

input ENUM_MA_METHOD    MA3{|‹W=MODE_EMA;//¹eTë_¿~{|‹W

input int               MA3=50;//$R­e¹eT„vë_¿~

input ENUM_MA_METHOD    MA4{|‹W=MODE_EMA;//¹eTba¿~{|‹W

input int               MA4=60;//$R­e¹eT„vba¿~

input int               Ñn¹p=30;

//---

int buyfuwei=YUSÐc_c;

int sellfuwei=zzUSÐc_c;

double lots_min,lots_max,lots_step;

int lots_digits;

//---

int OnInit()

  {

//---

   if(MA4<=MA3 || MA2<=MA1)

     {

      Alert("GW¿~¾‹n•ï‹ÿë_¿~¾‹n‰\ŽNba¿~");

      return(INIT_FAILED);

     }

   lots_min=MarketInfo(Symbol(),MODE_MINLOT);//g\Kbpe

   lots_max=MarketInfo(Symbol(),MODE_MAXLOT);//g'YKbpe

   lots_step=MarketInfo(Symbol(),MODE_LOTSTEP);

   if(lots_step<10)  lots_digits=0;

   if(lots_step<1)   lots_digits=1;

   if(lots_step<0.1) lots_digits=2;

   return(INIT_SUCCEEDED);

  }

//---

void OnTick()

  {

//š[INGW¿~<P-------------------------------------------------------------------

   double ma1=iMA(Symbol(),0,MA1,0,MA1{|‹W,PRICE_CLOSE,1);

   double ma2=iMA(Symbol(),0,MA2,0,MA2{|‹W,PRICE_CLOSE,1);

   double ma3=iMA(Symbol(),0,MA3,0,MA3{|‹W,PRICE_CLOSE,1);

   double ma4=iMA(Symbol(),0,MA4,0,MA4{|‹W,PRICE_CLOSE,1);

   double ma1p=iMA(Symbol(),0,MA1,0,MA1{|‹W,PRICE_CLOSE,2);

   double ma2p=iMA(Symbol(),0,MA2,0,MA2{|‹W,PRICE_CLOSE,2);

//buyagöNÿ¡l0RbkÈvúQ°sÍSTáO÷Ss^ÓN--------------------------------------------

   if(ma3>ma4 &&

      ((eQ:WGW¿~¤NÉS_ÓN && ma1>ma2 && ma1p<ma2p) ||

        (!eQ:WGW¿~¤NÉS_ÓN && ma1>ma2)))

     {

      if(ÍSTs^ÓN)

        {

         for(int i=0;i<OrdersTotal();i++) //kbÏc¢‹US;`pe

           {

            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) //	š[S_MRcUS

              {

               if((OrderComment()==(Symbol()+"sell"))) //‚Yœgc	gzzUSèlʑN7h   

                 {

                   bool odc=OrderClose(OrderTicket(),OrderLots(),Ask,Ñn¹p); //zzÓNs^ÓN            

                 } 

              }

           }

        }

         double lots=getlots();

         if(lots<=lots_max && lots>=lots_min)

           {

            if((buy(lots,bk_c,bkÈv,Symbol()+"buy",0)>0)&&(ûy¨Rbk_c==true)) //NYUS

              {

                 buyfuwei=YUSÐc_c;

              }

            }

      }

      

//sellagöNÿ¡l0RbkÈvúQ°sÍSTáO÷Ss^ÓN-------------------------------------------------------------------

   if(ma3<ma4 &&

     ((eQ:WGW¿~¤NÉS_ÓN && ma1<ma2 && ma1p>ma2p) ||

      (!eQ:WGW¿~¤NÉS_ÓN && ma1<ma2)))

     {

      if(ÍSTs^ÓN)

        {

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

           {

            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

              {

               if((OrderComment()==(Symbol()+"buy")))

                 {

                   bool odc=OrderClose(OrderTicket(),OrderLots(),Bid,Ñn¹p);           

                 } 

              }

           }

        }

         double lots=getlots();

         if(lots<=lots_max && lots>=lots_min)

           {

            if((sell(lots,bk_c,bkÈv,Symbol()+"sell",0)>0)&&(ûy¨Rbk_c==true))

              {

                 sellfuwei=zzUSÐc_c;

              }

           }

      }

  

//ý*Žbk_c¾‹n------------------------------------------------------------------- 

    if(ûy¨Rbk_c==true)

      { 

        for(int i=0;i<OrdersTotal();i++) //kbÏc¢‹US;`pe

          {

            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) //	š[S_MRcUS

              {

                if((OrderComment()==(Symbol()+"buy"))) //‚YœgcUS÷SNô

                  {

                    if(((Bid-OrderOpenPrice())/Point)>=buyfuwei) //‚YœgpN÷N-_ÓN÷N/¹ppe>=ûy¨Rbk_c

                      {

                        double buysl=OrderStopLoss(); //·ƒÖS¢‹USbk_c÷N<h

                        if(OrderModify(OrderTicket(),OrderOpenPrice(),buysl+ûy¨Rbk_cE^¦^*Point,OrderTakeProfit(),0)==true) 

                        //îO9ebk_c:bk_c÷N+ûy¨Rbk_cE^¦^ 

                          {

                            buyfuwei=buyfuwei+ûy¨Rbk_cE^¦^; //ÎN°eK<Pûy¨Rbk_c

                          }

                      }                 

                  } 

                if((OrderComment()==(Symbol()+"sell")))    

                  {

                    if(((OrderOpenPrice()-Ask)/Point)>=sellfuwei)

                      {

                        double sellsl=OrderStopLoss();

                        if(OrderModify(OrderTicket(),OrderOpenPrice(),sellsl-ûy¨Rbk_cE^¦^*Point,OrderTakeProfit(),0)==true)

                          {

                           sellfuwei=sellfuwei+ûy¨Rbk_cE^¦^;

                          }

                      }                 

                  }

              }

          }

      }

  }

 

//·ƒÖSlotýQpe---------------------------------------------------------------------------  

double getlots()

  {

    double lotsok=Kbpe;

    if(OrdersHistoryTotal()>0)

      {

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

          {

            if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

              {

                if(OrderSymbol()==Symbol())

                  {

                    if(OrderMagicNumber()==0) 

                      {

                        if(OrderProfit()>0)

                          {

                            lotsok=Kbpe;

                          }

                        else

                          {

                            lotsok=OrderLots()*
P•bû|pe;

                            lotsok=NormalizeDouble(lotsok,lots_digits);

                            if(lotsok>g'Y
P•bKbpe)

                              {

                               Print("…úQg'Y
P•bKbpeÿž[E–Kbpe”^:N: "+DoubleToStr(lotsok,lots_digits));

                               lotsok=g'Y
P•bKbpe;

                              }

                            break;

                          }

                         break;

                      }

                  }

              }

          }

      }

    else

      {

       return(lotsok);

      }

   if(lotsok>lots_max)  {lotsok=lots_max; Alert(Symbol()+" f‹JTÿLots…Çg'YKbpeÿèlaΘi–ÿg'YKbpe:Nÿ"+DoubleToStr(lots_max,lots_digits));}

   if(lotsok<lots_min)  {Alert(Symbol()+" f‹JTÿLotsNOŽNg\Kbpeÿ\Pbk_ÓNÿg\Kbpe:Nÿ"+DoubleToStr(lots_min,lots_digits));}

   return(lotsok);

  }



//buyýQpe----------------------------------------------------------------

int buy(double Lots,double sun,double ying,string comment,int magic)

  {

    int kaiguan=0; //RËYS_sQ:NSb_

    for(int i=0;i<OrdersTotal();i++) //kbÏc¢‹US;`pe

      {

        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) //	š[S_MRcUS

          {

            if((OrderComment()==comment)&&(OrderMagicNumber()==magic)) //‚YœgS_MRcUSèlʑŒT÷SŒT¾‹š[„vNôÿR_sQsQí•
NNUS0    

              {

                kaiguan=1;                     

              } 

          }

      }

    if(kaiguan==0) //‚Yœg_sQSb_

      {

        int ticket=OrderSend(Symbol( ) ,OP_BUY,Lots,Ask,Ñn¹p,0,0,comment,magic,0,White); //_ÓNpNeQYUSÿ
N¾‹bkÈvbk_cÿNUSbŸRԏÞV÷Sÿ1Y%ÔÞV-1	ÿ

        if(ticket>0) //NUSbŸR

          {

            if(OrderSelect(ticket, SELECT_BY_TICKET)==true) //	š[¢‹US‚Yœg÷SNô

              {

                double tp=0,sl=0;

                if(ying>0) tp=OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT);//bkÈv÷N<h

                if(sun>0)  sl=OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT);//bk_c÷N<h

                if(tp>0 && tp<=Bid) Alert("bkÈv÷N<h\ŽNVS÷NÿàeÕl¾‹n");

                if(sl>0 && sl>=Bid) Alert("bk_c÷N<h'YŽNVS÷NÿàeÕl¾‹n");

                //îO9e¢‹USbk_cbkÈv

                bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Red);

              }

          }

       return(ticket);

     }

   else

     {

      return(0);

     }

  }

  

//sellýQpe----------------------------------------------------------------

int sell(double Lots,double sun,double ying,string comment,int magic)

  {

    int kaiguan=0;

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

      {

        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

          {

            if((OrderComment()==comment)&&(OrderMagicNumber()==magic))   

              {

                kaiguan=1;                     

              } 

          }

      }

    if(kaiguan==0)

      {

        int ticket=OrderSend(Symbol( ) ,OP_SELL,Lots,Bid,Ñn¹p,0,0,comment,magic,0,Red);

        if(ticket>0)

          {

            if(OrderSelect(ticket, SELECT_BY_TICKET)==true)

              {

                double tp=0,sl=0;

                if(ying>0) tp=OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT);

                if(sun>0)  sl=OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT);

                if(tp>0 && tp>=Ask) Alert("bkÈv÷N<h'YŽNpN÷NÿàeÕl¾‹n");

                if(sl>0 && sl<=Ask) Alert("bk_c÷N<h\ŽNpN÷NÿàeÕl¾‹n");

                bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Red);

              }

          }

        return(ticket);

      }

    else

      {

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