Author: Big Mouth studio
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
r_No_1
ÿþ//+------------------------------------------------------------------+

//|                                                     r_No_1.mq4 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

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

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

#property copyright "Big Mouth studio"

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

#property version   "1.00"

#property strict



//*** API ***

extern double ratio = 0.01;         //ÝOÁ‹Ñ‘`SÔk

extern string magic = "reversal_";  //(u7bƋ+Rx

extern int    branching = 0;        //_ÓN;‘(0:Auto,1:O(u_ÓN
Ppe)

extern int    multiple  = 1;        //_ÓN
Ppe 



//*** PUBLC VARIABLE ***

//# ÂSpe #

string magicNo;         //(u7bƋ+Rx(Ƌ+Rx+t^gåe+öeR)

//# §c6R #

double wkhour = 99;    //MR°‹U_

int ticketNo;  //_ÓN÷S

//# _ÓNÂSpe #

double openLotsSave = 0;    //…__ÓNKbpe

double openPriceSave = 0;   //…__ÓN÷N<h

double stopPriceSave = 0;   //…_s^ÓN÷N<h

double openDirectionSave = 0;  //…__ÓN¹eT

//# †SòSÂSpe #

double lowPriceHistory = 0;    //gNO÷N

double highPriceHistory = 0;   //gؚ÷N

double lowOpenPriceHistory = 0;    //gNO_Øv÷N

string highOpenPriceHistory = "";  //gؚ_Øv÷N

double lowClosePriceHistory = 0;    //gNO6eØv÷N

string highClosePriceHistory = "";  //gؚ6eØv÷N

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

//| Expert initialization function                                   |

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

int OnInit()

  {

      //*** INITIALIZATION *** 

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//--- destroy timer

   EventKillTimer();



  }

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

//| Expert tick function                                             |

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

void OnTick()

   {

   //ò]ú^ÓNMO„vÀhåg

   //### ðXf ###

   double ms14 = iMA(NULL,0,14,0,MODE_EMA,PRICE_CLOSE,1);

   double ma30 = iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,1);



   //*** _ÓNÍd\O ***

   if(openPriceSave < Ask && openPriceSave > Bid)

      {

         //# _ÓN #

         MakeOrder();  

      }

   //*** ûy¨RbkÈv¾‹š[ ***

//   if(OrdersTotal() != 0 && isNewBar(30))

//      {

//         moveTargetProfit();

//      }

   //*** ÷N<h$R­e ***

   if(isNewBar(Period()))

      {

         PriceSaveEdit();  //_ÓN÷N<h„vÖS—_

      }

   }

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

//| _ÓNÍd\O                                                         |

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

void MakeOrder()

   {

      string openLog = "";    //bŸR_ÓNLOG

      magicNo = StringConcatenate(magic," ",iTime(Symbol(),0,0));

      //# pNUS #

      if (openDirectionSave == OP_BUY)

         {

            ticketNo = OrderSend(Symbol(),OP_BUY,openLotsSave,Ask,0,stopPriceSave,Ask+1500*Point,magicNo,Green);   //pNUS  stop = Bid-1000*Point

            openLog = StringConcatenate("## BUY ##","_ÓN÷N[",Ask,"];bk_c÷N[",stopPriceSave,"];bkÈv÷N[",Ask+2500*Point,"]");

         }

      //# VSUS #

      if (openDirectionSave == OP_SELL)

         {

            ticketNo = OrderSend(Symbol(),OP_SELL,openLotsSave,Bid,0,stopPriceSave,Bid-1500*Point,magicNo,Green);  //VSUS  stop = Ask+1000*Point

            openLog = StringConcatenate("## SELL ##","_ÓN÷N[",Bid,"];bk_c÷N[",stopPriceSave,"];bkÈv÷N[",Bid-1500*Point,"]");

         }

      //# hQ@\ØSϑ„vRËYS #

      initialization_Section();

   }

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

//| ûy¨RbkÈv„v¾‹š[                                                   |

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

void moveTargetProfit()

   {

      //# 12USMOGW¿~ #

      double y2Dot12 = iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,1);

      double y1Dot12 = iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,13);

      double Ma12Tan = (y2Dot12-y1Dot12)/(13-1);

      //# 50USMOGW¿~ #

      double y2Dot50 = iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1);

      double y1Dot50 = iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,51);

      double Ma50Tan = (y2Dot50-y1Dot50)/(51-1);

      //# 100USMOGW¿~ #

      double y2Dot100 = iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,1);

      double y1Dot100 = iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,101);

      double Ma100Tan = (y2Dot100-y1Dot100)/(101-1);

      //# 200USMOGW¿~ 

      double y2Dot200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,1);

      double y1Dot200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,201);

      double Ma200Tan = (y2Dot200-y1Dot200)/(201-1);



      string openLog = "";



      //# bkÈv¹pMO„v¾‹š[ #

      int rCode = 0;

      int openCnt = OrdersTotal();

      for(int pos=0;pos < openCnt;pos++)

         {

            if(OrderSelect(pos,SELECT_BY_POS) == true)

               {

                  if(OrderProfit() > 5)

                     {

                        if(OrderType()==0)   //BUY

                           {

                              if(Ma12Tan > Ma50Tan && Ma50Tan > Ma100Tan && rCode == 0)

                                 {

                                    openLog = StringConcatenate("## 1 ##","_ÓN÷N[",OrderOpenPrice(),"];bkÈv÷N[",Ask+1000*Point,"];bk_c÷NA[",Bid-1000*Point,"];bk_c÷NB = _ÓN÷N");

                                    if (Bid-1000*Point > OrderOpenPrice())

                                       {

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+1000*Point,0,Blue);

                                       }else{

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+100*Point,Ask+1000*Point,0,Blue);

                                       }

                                 }

                              if(y2Dot12 > y2Dot50 && y2Dot50 > y2Dot100 && y2Dot100 > y2Dot200 && rCode == 0)

                                 {

                                    openLog = StringConcatenate("## 2 ##","_ÓN÷N[",OrderOpenPrice(),"];bkÈv÷N[",Ask+1000*Point,"];bk_c÷NA[",Bid-1000*Point,"];bk_c÷NB = _ÓN÷N");

                                    if (Bid-1000*Point > OrderOpenPrice())

                                       {

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+1000*Point,0,Blue);

                                       }else{

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+100*Point,Ask+1000*Point,0,Blue);

                                       }

                                 }

                           }

                        if(OrderType()==1)

                           {

                              if(Ma12Tan < Ma50Tan && Ma50Tan < Ma100Tan && rCode == 0)

                                 {

                                    openLog = StringConcatenate("## 3 ##","_ÓN÷N[",OrderOpenPrice(),"];bkÈv÷N[",Bid-1000*Point,"];bk_c÷NA[",Ask+1000*Point,"];bk_c÷NB = _ÓN÷N");

                                    if (Ask+1000*Point > OrderOpenPrice())

                                       {

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-1000*Point,0,Blue);

                                       }else{

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-100*Point,Bid-1000*Point,0,Blue);

                                       }

                                 }

                              if(y2Dot12 < y2Dot50 && y2Dot50 < y2Dot100 && y2Dot100 < y2Dot200 && rCode == 0)

                                 {

                                    openLog = StringConcatenate("## 4 ##","_ÓN÷N[",OrderOpenPrice(),"];bkÈv÷N[",Bid-1000*Point,"];bk_c÷NA[",Ask+1000*Point,"];bk_c÷NB = _ÓN÷N");

                                    if (Ask+1000*Point > OrderOpenPrice())

                                       {

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-1000*Point,0,Blue);

                                       }else{

                                          rCode = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-100*Point,Bid-1000*Point,0,Blue);

                                       }

                                 }

                           }

                     }

               }

            if(openLog != "")

               {

                  Print("---------- ûy¨RÈv_c ----------");

                  Print("## openLog ## ",openLog);

                  Print("------------------------------");

               }               

         }

   }

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

//| ÷N<h$R­e                                                         |

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

void PriceSaveEdit()

   {

      string msgUp = StringConcatenate("'^ù[0" , Symbol(), "0,þVhˆöeµk0" , Period() , "0ÿúQ°slY K ¿~");

      string msgDown = StringConcatenate("'^ù[0" , Symbol(), "0,þVhˆöeµk0" , Period() , "0ÿúQ°slzz K ¿~");

      double valueDiff = iHigh(NULL,0,1) - iLow(NULL,0,1);  //ñg•



      if(valueDiff > MathAbs(iClose(NULL,0,1) - iOpen(NULL,0,1)) * 5)   //valueDiff > cycleTime() && 

         {

            if(iClose(NULL,0,1) > iOpen(NULL,0,1))

               {  //# 3–¿~ #

                  if(iHigh(NULL,0,1) - iClose(NULL,0,1) > iOpen(NULL,0,1) - iLow(NULL,0,1))

                     {  //# 
Nq_¿~ > Nq_¿~ #

                        if(iHigh(NULL,0,1) - iClose(NULL,0,1) > MathAbs(iClose(NULL,0,1) - iOpen(NULL,0,1)) * 5)

                           {

                              sendNotice(msgDown,"1");   //åw

                              OrderEdit(OP_SELL,NormalizeDouble((iHigh(NULL,0,1) + iClose(NULL,0,1))/2,3),iHigh(NULL,0,1));    //cUSÍd\O

                           }

                        

                     }else{  //# Nq_¿~ > 
Nq_¿~ #

                        if(iOpen(NULL,0,1) - iLow(NULL,0,1) > MathAbs(iClose(NULL,0,1) - iOpen(NULL,0,1)) * 5)

                           {

                              sendNotice(msgUp,"2");   //åw

                              OrderEdit(OP_BUY,NormalizeDouble((iOpen(NULL,0,1) + iLow(NULL,0,1))/2,3),iLow(NULL,0,1));    //cUSÍd\O

                           }

                     }

               }else{  //# 4–¿~ #

                  if(iHigh(NULL,0,1) - iOpen(NULL,0,1) > iClose(NULL,0,1) - iLow(NULL,0,1))

                     {  //# 
Nq_¿~ > Nq_¿~ #

                        if(iHigh(NULL,0,1) - iOpen(NULL,0,1) > MathAbs(iClose(NULL,0,1) - iOpen(NULL,0,1)) * 5)

                           {

                              sendNotice(msgDown,"3");   //åw

                              OrderEdit(OP_SELL,NormalizeDouble((iHigh(NULL,0,1) + iOpen(NULL,0,1))/2,3),iHigh(NULL,0,1));    //cUSÍd\O

                           }

                     }else{  //# Nq_¿~ > 
Nq_¿~ #

                        if(iClose(NULL,0,1) - iLow(NULL,0,1) > MathAbs(iClose(NULL,0,1) - iOpen(NULL,0,1)) * 5)

                           {

                              sendNotice(msgUp,"4");   //åw

                              OrderEdit(OP_BUY,NormalizeDouble((iClose(NULL,0,1) + iLow(NULL,0,1))/2,3),iLow(NULL,0,1));    //cUSÍd\O

                           }

                     }

               }

         }

   }

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

//|  GW¿~pNVS$Rš[                                                    |

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

double maDetermine()

   {

      return(0);

   }



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

//|  ÂSpeRËYS                                                      |

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

void initialization_Section()

   {

      openLotsSave = 0;

      openPriceSave = 0;

      openDirectionSave = 0;

   }

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

//|  _ÓNÂSpe„v¾‹š[                                                  |

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

void OrderEdit(double direction,double openPrice,double stopClose)  //¹eTÿ_ÓN÷Nÿbk_c÷N

   {

      if(openLotsF(openPrice) > 0)

         {

            initialization_Section();

            openLotsSave = openLotsF(openPrice);   //_ÓNKbpe

            openPriceSave = openPrice;   //_ÓN÷N

            openDirectionSave = direction;  //¹eT

            if(MathAbs(stopClose - openPrice) < 10)

               {

                  if(openDirectionSave == OP_BUY)

                     {

                        stopPriceSave = openPrice - 1000*Point;   //bk_c÷N

                     }else{

                        stopPriceSave = openPrice + 1000*Point;   //bk_c÷N

                     }

               }else{

                  stopPriceSave = stopClose;

               }



            Print("---------- _ÓNÂSpe¾‹š[ ----------");

            string msglog = StringConcatenate(" öeô• ",iTime(Symbol(),0,0)," ¹eT ",openDirectionSave," Kbpe ",openLotsSave," _ÓN÷N ",openPriceSave," bk_c÷N ",stopPriceSave);

            Print("## _ÓNÂSpe¾‹š[ ## ",msglog);

            Print("----------------------------------");

         }

   }

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

//| _ÓNKbpenx¤‹                                                     |

//| ÝOÁ‹Ñ‘¡‹—{lQ_ÿ¤Nf÷N<h * ¤NfKbpe * T¦~b—<P * ÝOÁ‹Ñ‘Ôk‹O      |

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

double openLotsF(double openPrice)  //_ÓN÷N

   {

      double usablePrice = AccountBalance() * ratio - AccountMargin(); //ïS(uё˜ÿUSMOÿCQ	ÿ ( ÀQ<P * _ÓNÔk‡s - 1\_ÓNÝOÁ‹Ñ‘ )

      double minLots = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN); //g\_ÓNpeϑÿUSMOÿUS	ÿ

      double maxLots = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX); //g'Y_ÓNpeϑÿUSMOÿUS	ÿ

      double minLotsPrice = minLots(openPrice);  //gNO_ÓNÝOÁ‹Ñ‘ÿUSMOÿCQ	ÿ

      double openLot = 0;

      if(usablePrice < minLotsPrice)

         {

            openLot = 0;

         }else if(usablePrice > minLotsPrice && usablePrice < minLotsPrice * multiple)

            {

               openLot = minLots;

            }else{

               openLot = minLots * multiple;

            }

      if(openLot > maxLots)

         {

            openLot = maxLots;

         }

      return(openLot);

   }

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

//| '^ù[gNO_ÓNÝOÁ‹Ñ‘¡‹—{                                         |

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

double minLots(double openPrice)   //'^ù[

   {

      double minLots = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);

      double singleBalance = 0;  //USMOÝOÁ‹Ñ‘

      if (Symbol() == "XAUUSD")

         {

            singleBalance = openPrice * minLots * 0.75;

         }else{

            singleBalance = 5;

         }

      return(singleBalance);

   }

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

//| ÑS MetaQuotes åw                                             |

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

void sendNotice(string message,string no)  //¨c…Q¹[ÿöeô•hTg

  {

      Print("## message ##",message + no);

      bool res=SendNotification(message);    //MetaQuotesåw¨c

      if(!res)

         {

//            Print("Message sending failed");

         }else{

//            Print("Message sent");

         }

  }

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

//|  hÆQ<hî]<PÿUSMO:CQ	ÿ                                           |

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

int cycleTime()

   {

      int wkInt;

      switch(Period())   //ÖSöeô•hTg

         {

            case 60:    //H1

               wkInt = 10;

               break;

            case 240:   //D1

               wkInt = 15;

               break;

            case 1440:  //W1

               wkInt = 20;

               break;

            default:

               wkInt = 5;

         }

      return(wkInt);

   }

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

//|  ù[aŒK¿~$Rš[                                                     |

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

bool isNewBar(int min)

   {

      int minBk = 0;    //¤Nfæ‰ÑSöeô•

      double modM = MathMod(Minute(),min);   //RŸ”ÖSYO

      double modH = MathMod(Hour(),min/60);   //\öeÖSYO

      if(min < 60 && modM == 0 && minBk == 0 && (wkhour != Hour() || wkhour == 99))

         {

            minBk = Minute() + 1;

            wkhour = Hour();

         }

      if(min == 60 && (wkhour != Hour() || wkhour == 99))

         {

            minBk = 1;

            wkhour = Hour();

         }

      if(min > 60 && modH == 0 && minBk == 0 && (wkhour != Hour() || wkhour == 99))

         {

            minBk = 1;

            wkhour = Hour();

         }

      //gbLˆ:Sô•µk

      if(wkhour == Hour() && Minute() == minBk && Seconds() < 2)

         {

            return(true);

         }else{

            return(false);

         }

   }

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