Author: Oleksii Chepurnyi
Price Data Components
Series array that contains open time of each bar
Orders Execution
It Closes Orders by itself It automatically opens orders when conditions are reached
Miscellaneous
It opens Message Boxes to the user
0 Views
0 Downloads
0 Favorites
Aurora
ÿþ//+------------------------------------------------------------------+

//|                                                       Aurora.mq4 |

//|                                                Oleksii Chepurnyi |

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

#property copyright "Oleksii Chepurnyi"

#property link      "https://www.mql5.com/ru/users/oleksiic"

#property version   "1.4"

#property strict

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

#include <Errors.mqh>               //  K7>2 DC=:F88 - ShowError

#include <Orders.mqh>

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

sinput string  menuGR="--------------------------------------------"; //  --------------- 0@0<5B@K 3@0D8:8 ---------------

extern double  TimeIn     = 5.00;       //  @5<O =0G0;0 >1;0AB8, ''.

extern double  TimeOut    = 9.00;       //  @5<O >:>=G0=8O >1;0AB8, ''.

extern double  TimeClose  = 15.00;      //  @5<O 70:@KB8O 2A5E ?>78F89, ''.

extern color   VlineColor = clrYellow;  //  &25B ;8=88 70:@KB8O 2A5E ?>78F89

extern color   RAColor    = clrRed;     //  &25B >1;0AB8

extern int     DaysToDraw = 10;         //  >;8G5AB2> 4=59 4;O >B@8A>2:8 >1;0AB59

sinput string  menuORD="--------------------------------------------"; //  --------------- 0@0<5B@K >@45@>2 ---------------

sinput bool    OrderFlag  = true;       //  B:@K205< >@45@0?

extern double  Lot        = 0.01;       //  !B0B8G=K9 ;>B

extern int     RangeO     = 50;         //   0AAB>O=85 >B >1;0AB8 4> >B;>65==>3> >@45@0, ?8?AK

extern int     SL         = 200;        //  !B>?-;>AA, ?8?AK

extern int     TP         = 200;        //  "59:-?@>D8B, ?8?AK

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

#include <Breakeven.mqh>            //  K7>2 DC=:F88 - Breakeven(B8:5B_>@45@0);

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

sinput string  menuCOM="--------------------------------------------"; //  --------------- 1I85 ?0@0<5B@K ---------------

extern int     Slippage   = 10;         //  @>A:0;L7K20=85, ?8?AK

sinput int     Magic      = 248249;     //  Magic



double HighPrice,LowPrice;

int    HighIndex,LowIndex;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

   if(floor(TimeIn) >= 24)                           {TimeIn = 5.00;     MessageBox(">-<>5<C, 2 ACB:0E 2A53> 24 G0A0.\n(H81:0 2: @5<O =0G0;0 >1;0AB8)\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(round((TimeIn-floor(TimeIn))*100) >= 60)       {TimeIn = 5.00;     MessageBox(">-<>5<C, 2 G0A5 2A53> 60 <8=CB.\n(H81:0 2: @5<O =0G0;0 >1;0AB8)\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(floor(TimeOut) >= 24)                          {TimeOut = 9.00;    MessageBox(">-<>5<C, 2 ACB:0E 2A53> 24 G0A0.\n(H81:0 2: @5<O >:>=G0=8O >1;0AB8)\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(round((TimeOut-floor(TimeOut))*100) >= 60)     {TimeOut = 9.00;    MessageBox(">-<>5<C, 2 G0A5 2A53> 60 <8=CB.\n(H81:0 2: @5<O >:>=G0=8O >1;0AB8)\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(floor(TimeClose) >= 24)                        {TimeClose = 15.00; MessageBox(">-<>5<C, 2 ACB:0E 2A53> 24 G0A0.\n(H81:0 2: @5<O 70:@KB8O 2A5E ?>78F89)\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(round((TimeClose-floor(TimeClose))*100) >= 60) {TimeClose = 15.00; MessageBox(">-<>5<C, 2 G0A5 2A53> 60 <8=CB.\n(H81:0 2: @5<O 70:@KB8O 2A5E ?>78F89)\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(GetTime(TimeIn) >= GetTime(TimeOut))           {TimeIn = 5.00;

                                                      TimeOut = 9.00;

                                                      TimeClose = 15.00; MessageBox("@5<O >:>=G0=8O >1;0AB8 ?>G5<C-B> @0=LH5 =0G0;0...\n;8 >1;0ABL =C;52>3> @07<5@0.\n\nC4CB ?@8<5=5=K 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(GetTime(TimeOut) >= GetTime(TimeClose))        {TimeIn = 5.00;

                                                      TimeOut = 9.00;

                                                      TimeClose = 15.00; MessageBox("C45< 70:@K20BL >@45@0, B0: 8 =5 >B:@K2?..\n\nC4CB ?@8<5=5=K 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(RangeBEpos >= RangeBE && RangeBE != 0)         {RangeBE = 0;       MessageBox("5@52>4 2 # 1C45B =5C40G=K<, =>2K9 AB>? 1C45B @025= 8;8 1>;LH5 F5=K.\n\n5@52>4 2 # >B:N;G5=!!!","#?A...",MB_OK);}

   if(RangeO < 0)                                    {RangeBE = 50;      MessageBox(" 0AAB>O=85 >B >1;0AB8 4> >B;>65==>3> >@45@0 =5 <>65B 1KBL >B@8F0B5;L=K<.\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(RangeBE >= TP)                                 MessageBox("5@52>40 2 # =5 1C45B, " @0=LH5.",""0:, 5A;8 H>...",MB_OK);

   

   if(SL < MarketInfo(Symbol(),MODE_STOPLEVEL))      {SL = 200; MessageBox("!B>?-;>AA A;8H:>< 1;87:> : F5=5 >B:@KB8O.\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

   if(TP < MarketInfo(Symbol(),MODE_STOPLEVEL))      {TP = 200; MessageBox(""59:-?@>D8B A;8H:>< 1;87:> : F5=5 >B:@KB8O.\n\nC45B ?@8<5=5=> 7=0G5=85 ?>-C<>;G0=8N!!!","#?A...",MB_OK);}

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

     {

      string Message = "1J5< ?>78F88 <5=LH5 <8=8<0;L=>3>.\n0 MB>< AG5BC <8=8<0;L=K9 >1J5< ?>78F88 A>AB02;O5B: "+SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN)+"\n@8<5=8BL MB> 7=0G5=85?";

      if(MessageBox(Message,">B <5=LH5 <8=8<0;L=>3>",MB_OKCANCEL)==1) Lot = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);

      else {MessageBox("@>3@0<<0 C40;5=0 A 3@0D8:0","525@=K5 ?0@0<5B@K",MB_OK);return(INIT_PARAMETERS_INCORRECT);}

     }

//------ !>7405< ;8=8N 70:@KB8O 2A5E >@45@>2

   if(GetTime(TimeClose) > TimeCurrent())

     {

      ObjectDelete(0,"AuroraVlineClose");

      if(!ObjectCreate(0,"AuroraVlineClose",OBJ_VLINE,0,GetTime(TimeClose),0)) ShowError;

      ObjectSetInteger(0,"AuroraVlineClose",OBJPROP_COLOR,VlineColor);

     }

//------  8AC5< >1;0AB8

   if(TimeCurrent() > GetTime(TimeOut))

     {

      ObjectDelete(0,"AuroraRA0");

      HighLow();

      if(!ObjectCreate(0,"AuroraRA0",OBJ_RECTANGLE,0,GetTime(TimeIn),HighPrice,GetTime(TimeOut)-60,LowPrice)) ShowError;

      ObjectSetInteger(0,"AuroraRA0",OBJPROP_COLOR,RAColor);

     }

   CreateRA();

//------

   ChartRedraw();



   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

   ObjectsDeleteAll(0,"Aurora");                       // #40;O5< A2>8 >1J5:BK

   ChartRedraw();

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//------ 5@5@8A>2K205< 3@0D8: 4;O =>2>3> 4=O

   if(isTime(1.00))

     {

      ObjectsDeleteAll(0,"Aurora");

      ObjectDelete(0,"AuroraVlineClose");

      if(!ObjectCreate(0,"AuroraVlineClose",OBJ_VLINE,0,GetTime(TimeClose),0)) ShowError;

      ObjectSetInteger(0,"AuroraVlineClose",OBJPROP_COLOR,VlineColor);

      CreateRA();

      ChartRedraw();

     }

     

//------  8AC5</?5@5@8A>2C5< >1;0ABL

   if(TimeCurrent() > GetTime(TimeIn))

     {

      ObjectDelete(0,"AuroraRA0");

      HighLow();

      if(!ObjectCreate(0,"AuroraRA0",OBJ_RECTANGLE,0,GetTime(TimeIn),HighPrice,GetTime(TimeOut)-60,LowPrice)) ShowError;

      ObjectSetInteger(0,"AuroraRA0",OBJPROP_COLOR,RAColor);

      ChartRedraw();

     }

     

//------ @5<O @01>BK @>1>B0

   if(Hour()<floor(TimeIn) || Hour()>floor(TimeClose)) return;

   

//------ #40;O5< 2A5 >@45@0 8 ?>78F88 ?> 2@5<5=8

   if(isTime(TimeClose))

     {

      Get_Orders();

      if(Orders_Quant != 0)

        {

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

           {

            if(!OrderSelect(Tickets[i],SELECT_BY_TICKET)) ShowError;

            switch(OrderType())

              {

               case OP_BUY:      if(!OrderClose(Tickets[i],OrderLots(),Bid,Slippage)) ShowError;break;

               case OP_SELL:     if(!OrderClose(Tickets[i],OrderLots(),Ask,Slippage)) ShowError;break;

               case OP_BUYSTOP:  

               case OP_SELLSTOP: if(!OrderDelete(Tickets[i])) ShowError;

              }

           }

         ObjectDelete(0,"AuroraVlineClose");   // #40;O5< ;8=8N 70:@KB8O 2A5E >@45@>2

         ChartRedraw();

        }

     }

     

//------ KAB02;O5< >@45@0

   if(isTime(TimeOut) && OrderFlag)

     {

      Get_Orders();

      if(Orders_Quant == 0)

        {

         if(!HighLow()) return;

         double OpenPrice_Buy = NormalizeDouble(HighPrice+RangeO*Point,Digits);

         double OpenPrice_Sell = NormalizeDouble(LowPrice-RangeO*Point,Digits);

         if(HighIndex > 4)

           if(!OrderSend(Symbol(),OP_BUYSTOP,Lot,OpenPrice_Buy,Slippage,NormalizeDouble(OpenPrice_Buy-SL*Point,Digits),NormalizeDouble(OpenPrice_Buy+TP*Point,Digits),"Order by Aurora "+Symbol(),Magic)) ShowError;

         if(LowIndex > 4)

           if(!OrderSend(Symbol(),OP_SELLSTOP,Lot,OpenPrice_Sell,Slippage,NormalizeDouble(OpenPrice_Sell+SL*Point,Digits),NormalizeDouble(OpenPrice_Sell-TP*Point,Digits),"Order by Aurora "+Symbol(),Magic)) ShowError;

        }

     }

     

//------ #40;O5< >B;>65==K9 >@45@, 5A;8 5ABL >B:@KBK9

   Get_Orders();

   if(Orders_Quant_Opened != 0 && Orders_Quant_Opened != Orders_Quant)

     {

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

        {

         if(!OrderSelect(Tickets[i],SELECT_BY_TICKET)) ShowError;

         switch(OrderType())

           {

            case OP_BUY:      break;

            case OP_SELL:     break;

            case OP_BUYSTOP:  

            case OP_SELLSTOP: if (!OrderDelete(Tickets[i])) ShowError;

           }

        }

      return;

     }

     

//------ 5@52>48< 2 #

   if(Orders_Quant_Opened != 0 && RangeBE != 0) Breakeven(Tickets_Opened[0]);

  }

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

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

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

// @>25@O5< 2@5<O

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

bool isTime(double time)

  {

   double Current_time = NormalizeDouble(Hour() + Minute()/100.0,2);

   if(NormalizeDouble(time - Current_time,2) == 0) return(true);

   return(false);

  }

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

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

// >;CG05< 2@5<O 87 double

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

datetime GetTime(double time)

  {

   MqlDateTime str_time;

   str_time.year = Year();

   str_time.mon  = Month();

   str_time.day  = Day();

   str_time.hour = floor(time);

   str_time.min  = round((time-floor(time))*100);

   str_time.sec  = 0;

   return(StructToTime(str_time));

  }

//------ 

datetime GetTime(double time,datetime date)

  {

   MqlDateTime str_time;

   str_time.year = TimeYear(date);

   str_time.mon  = TimeMonth(date);

   str_time.day  = TimeDay(date);

   str_time.hour = floor(time);

   str_time.min  = round((time-floor(time))*100);

   str_time.sec  = 0;

   return(StructToTime(str_time));

  }

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

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

// 0:A8<0;L=0O 8 <8=8<0;L=0O F5=0 >1;0AB8

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

bool HighLow()

  {

   HighPrice = 0;

   LowPrice  = 0;

   double Highs[];

   double Lows[];

   ArraySetAsSeries(Highs,true);

   ArraySetAsSeries(Lows,true);

   datetime time2 = GetTime(TimeOut) - 60;

   if(TimeCurrent() < time2) time2 = TimeCurrent();

   if(CopyHigh(Symbol(),PERIOD_M1,time2,GetTime(TimeIn),Highs) <= 0) return(false);

   if(CopyLow (Symbol(),PERIOD_M1,time2,GetTime(TimeIn),Lows) <= 0) return(false);

   HighIndex = ArrayMaximum(Highs,WHOLE_ARRAY,0);

   LowIndex  = ArrayMinimum(Lows,WHOLE_ARRAY,0);

   HighPrice = Highs[HighIndex];

   LowPrice  = Lows[LowIndex];

   return(true);

  }

//------ 

bool HighLow(datetime date)

  {

   HighPrice = 0;

   LowPrice  = 0;

   double Highs[];

   double Lows[];

   ArraySetAsSeries(Highs,true);

   ArraySetAsSeries(Lows,true);

   datetime time2 = GetTime(TimeOut,date) - 60;

   if(TimeCurrent() < time2) time2 = TimeCurrent();

   if(CopyHigh(Symbol(),PERIOD_M1,time2,GetTime(TimeIn,date),Highs) <= 0) return(false);

   if(CopyLow (Symbol(),PERIOD_M1,time2,GetTime(TimeIn,date),Lows) <= 0) return(false);

   HighIndex = ArrayMaximum(Highs,WHOLE_ARRAY,0);

   LowIndex  = ArrayMinimum(Lows,WHOLE_ARRAY,0);

   HighPrice = Highs[HighIndex];

   LowPrice  = Lows[LowIndex];

   return(true);

  }

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

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

//  8AC5< >1;0AB8

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

void CreateRA()

  {

   ObjectsDeleteAll(0,"AuroraRA");

   if(DaysToDraw == 0) return;

   int i = 0;

   int e = 0;

   datetime date = GetTime(2.00);

   while(i < DaysToDraw)

     {

      date -= 86400;

      if(iBarShift(Symbol(),PERIOD_M1,date,true) != -1)

        {

         HighLow(date);

         string name = "AuroraRA" + IntegerToString(i+1);

         if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,GetTime(TimeIn,date),HighPrice,GetTime(TimeOut,date)-60,LowPrice)) ShowError;

         ObjectSetInteger(0,name,OBJPROP_COLOR,RAColor);

         i++;   e = 0;

        }

      else

        {

         e++;

         if(e >= 5) { MessageBox("54>AB0B>G=> :>B8@>2>: 4;O =0=5A5=8O 2A5E >1;0AB59.\n0=5A5=> >1;0AB59: "+i+".\n(C6=K :>B8@>2:8 1 ?> "+Symbol()+")","#?A...",MB_OK); return; }

        }

     }

  }

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

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