//+------------------------------------------------------------------+
//|                                            panelektrik@yandex.ru |
//|                                              skype pan--elektrik |
//|                                                    ISQ 561090193 |
//|                                             Моб. +380 50 7115118 |
//+------------------------------------------------------------------+
#property copyright "panelektrik@yandex.ru"

 extern int magic_buy  = 84356;
 extern int magic_sell = 76432;
 extern int sl =250;
 extern int tp =250;
 extern double lot =0.1;
 extern int delta  =50;
 extern int N  =10;
 
 int den;double high;double low;int M=100;
//+------------------------------------------------------------------+ 
int orders()
  {int j=0;for (int i=0;i<OrdersTotal();i++)
  {if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
  if((OrderMagicNumber()==magic_buy||OrderMagicNumber()==magic_sell)&&(OrderSymbol()==Symbol()))j++;
  }return(j);}
//+------------------------------------------------------------------+
int orders_buystop()
  {int j;for(int i=0;i<OrdersTotal();i++)
  {if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
  if((OrderType()==OP_BUYSTOP)&&(OrderMagicNumber()==magic_buy)&&(OrderSymbol()==Symbol()))j++;}return(j);}
//+------------------------------------------------------------------+
int orders_sellstop()
  {int j=0;for (int i=0;i<OrdersTotal();i++)
  {if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
  {if((OrderType()==OP_SELLSTOP)&&(OrderMagicNumber()==magic_sell)&&(OrderSymbol()==Symbol()))j++;}}return(j);}
//+------------------------------------------------------------------+
void Send_buystop()
  {int G;double d;while(!IsStopped()){RefreshRates();
  if(G==130)d=MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD);
  OrderSend(Symbol(),OP_BUYSTOP,lot,(high+(delta+d)*Point),10*Point,(high+(delta+d)*Point)-sl*Point,(high+(delta+d)*Point)+tp*Point,"пробой-M"+Symbol(),magic_buy,0,Blue);
  G=GetLastError();if(orders_buystop()==1)break;Sleep(5000);int i=i+1;if(i>10)break;}}
//+------------------------------------------------------------------+  
void Send_sellstop()
   {int G;double d;while(!IsStopped()){RefreshRates();
   if(G==130)d=MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD);
   OrderSend(Symbol(),OP_SELLSTOP,lot,(low-(delta+d)*Point),10*Point,(low-(delta+d)*Point)+sl*Point,(low-(delta+d)*Point)-tp*Point,"пробой-M"+Symbol(),magic_sell,0,Red);
   Print(GetLastError());if(orders_sellstop()==1)break;Sleep(5000);int i=i+1;if(i>10)break;}}
//+------------------------------------------------------------------+
int close()
  {for(int i=OrdersTotal(); i+1>=0; i--)
   {RefreshRates();
    if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderSymbol()==Symbol()))
    if((OrderMagicNumber()==magic_buy||OrderMagicNumber()==magic_sell)&&(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP))
    {OrderDelete(OrderTicket());Sleep(1000);}}}
//+------------------------------------------------------------------+
int start()
 { 
  if(Day()>=N)close();
  if((den!=Day())&&(Day()>1)&&(Day()<N))
  {
  if(M!=Month()){M=Month();den=Day();return;}
//+---  
  if(orders()<2)
  {
//+---  
  high = iHigh(Symbol(),PERIOD_MN1,0);
  low = iLow(Symbol(),PERIOD_MN1,0);
//+---
  if(orders_buystop()==0)Send_buystop();
  if(orders_sellstop()==0)Send_sellstop();
  }
//+---
   den=Day();
//+---
  }}
int init()
{
if((IsTesting()==false)&&(IsOptimization()==false)&&(IsVisualMode()==false))
{
den=GlobalVariableGet("den"+Symbol());
M=GlobalVariableGet("M"+Symbol());
}}
int deinit()
{
if((IsTesting()==false)&&(IsOptimization()==false)&&(IsVisualMode()==false))
{
GlobalVariableSet("den"+Symbol(),den);
GlobalVariableSet("M"+Symbol(),M);
}}
//+------------------------------------------------------------------+