Navigation:Home > Content >

SK_2_Mar_(Crazy_setka)_v10.0.mq4

Time: 2010-08-22 | Download file:SK_2_Mar_(Crazy_setka)_v10.0.mq4

//+------------------------------------------------------------------+
//|                                                         Reka.mq4 |
//|                                                   Semenov Alexey |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Semenov Alexey"
#property link      ""



/*-------------------------------------------------------------------------------------------------------------------+
|  В Х О Д Н Ы Е   П Е Р Е М Е Н Н Ы Е                                                                               |
+-------------------------------------------------------------------------------------------------------------------*/

//----  Внешние входные переменные  ----------------------------------------------------------------------------------
//------------Общие установки для советника
extern double  Lots             =  0.1;
extern double  Profit           =  30;
extern double  Mult             =  1.2;
extern int     Slippage         =  30;
extern int     MaxSpread        =  25;
extern string Сomment           =  "SK";
//------------Сетка 1
extern int Step1                =  50;       // Шаг сетки для открытия следующего колена
extern int Magic_Setka_1        =  111;
//------------Сетка 2
extern int Step2                =  50;       // Шаг сетки для открытия следующего колена
extern int Setka2_open_parametr =  7;        // начиная с какого колена сетки 1 можно открывать сетку 2
extern int Otstup_setka_2       =  200;      // отступ в пипсах от последнего колена для открытия сетки 2
extern int Magic_Setka_2        =  211;
//------------Сетка 3
extern bool Setkа_3_switch      =  TRUE;     // Включить 3-ую сетку
extern int Step3                =  50;      // Шаг сетки для открытия следующего колена 
extern int Setka3_open_parametr =  7;        // начиная с какого колена сетки 2 можно открывать сетку 3
extern int Otstup_setka_3       =  200;      // отступ в пипсах от последнего колена для открытия сетки 3
extern int Magic_Setka_3        =  311;
//------------Сетка 4
extern bool Setkа_4_switch      =  TRUE;     // Включить 4-ую сетку
extern int Step4                =  50;      // Шаг сетки для открытия следующего колена 
extern int Setka4_open_parametr =  7;        // начиная с какого колена сетки 2 можно открывать сетку 4
extern int Otstup_setka_4       =  200;      // отступ в пипсах от последнего колена для открытия сетки 4
extern int Magic_Setka_4        =  411;
//------------Мультипликатор увеличения лотности колен сетки (единый параметр для всех сеток)
extern double Multiple_1        =  1.0;
extern double Multiple_2        =  1.2;
extern double Multiple_3        =  1.5;
extern double Multiple_4        =  2.0;
extern double Multiple_5        =  2.5;
extern double Multiple_6        =  4.5;
//------------Технические индикаторы
extern string  MA1              =  "MA_1"; 
extern int MA_Period_1          =  5; 
extern int MA_Shift_1           =  0;  
extern int MA_Method_1          =  3; 
extern int MA_applied_price_1   =  0;

extern int Level                =  30;

extern bool TestMode            =  false;

//----  Внутренние входные переменные  -------------------------------------------------------------------------------
int total, Ticket;
string Text, GlName;
bool answer;
int ttb_B1,ttb_S1, tts_B1, tts_S1;
//------------Сетка 1
int Sell = 0, Buy = 0;
int x, PositionSell, PositionBuy;
int LastProfit=0;
double Lot2, LastLot;
//------------Сетка 2
int Sell_2 = 0, Buy_2 = 0;
int PositionSell_2, PositionBuy_2;
int LastProfit_2=0;
double Lot2_2, LastLot_2;
//------------Сетка 3
int Sell_3 = 0, Buy_3 = 0;
int PositionSell_3, PositionBuy_3;
int LastProfit_3=0;
double Lot2_3, LastLot_3;
//------------Сетка 4
int Sell_4 = 0, Buy_4 = 0;
int PositionSell_4, PositionBuy_4;
int LastProfit_4=0;
double Lot2_4, LastLot_4;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
 //------------Сетка 1 
 GlName=StringConcatenate("Buy"+DoubleToString(Magic_Setka_1,0));
 if (GlobalVariableCheck (GlName)) Buy=GlobalVariableGet(GlName);
 GlName=StringConcatenate("Sell"+DoubleToString(Magic_Setka_1,0));
 if (GlobalVariableCheck (GlName)) Sell=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionBuy"+DoubleToString(Magic_Setka_1,0));
 if (GlobalVariableCheck (GlName)) PositionBuy=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionSell"+DoubleToString(Magic_Setka_1,0));
 if (GlobalVariableCheck (GlName)) PositionSell=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastProfit"+DoubleToString(Magic_Setka_1,0));
 if (GlobalVariableCheck (GlName)) LastProfit=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastLot"+DoubleToString(Magic_Setka_1,0));
 if (GlobalVariableCheck (GlName)) LastLot=GlobalVariableGet(GlName);
 //------------Сетка 2
 GlName=StringConcatenate("Buy_2"+DoubleToString(Magic_Setka_2,0));
 if (GlobalVariableCheck (GlName)) Buy_2=GlobalVariableGet(GlName);
 GlName=StringConcatenate("Sell_2"+DoubleToString(Magic_Setka_2,0));
 if (GlobalVariableCheck (GlName)) Sell_2=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionBuy_2"+DoubleToString(Magic_Setka_2,0));
 if (GlobalVariableCheck (GlName)) PositionBuy_2=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionSell_2"+DoubleToString(Magic_Setka_2,0));
 if (GlobalVariableCheck (GlName)) PositionSell_2=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastProfit_2"+DoubleToString(Magic_Setka_2,0));
 if (GlobalVariableCheck (GlName)) LastProfit_2=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastLot_2"+DoubleToString(Magic_Setka_2,0));
 if (GlobalVariableCheck (GlName)) LastLot_2=GlobalVariableGet(GlName);
 //------------Сетка 3
 GlName=StringConcatenate("Buy_3"+DoubleToString(Magic_Setka_3,0));
 if (GlobalVariableCheck (GlName)) Buy_3=GlobalVariableGet(GlName);
 GlName=StringConcatenate("Sell_3"+DoubleToString(Magic_Setka_3,0));
 if (GlobalVariableCheck (GlName)) Sell_3=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionBuy_3"+DoubleToString(Magic_Setka_3,0));
 if (GlobalVariableCheck (GlName)) PositionBuy_3=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionSell_3"+DoubleToString(Magic_Setka_3,0));
 if (GlobalVariableCheck (GlName)) PositionSell_3=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastProfit_3"+DoubleToString(Magic_Setka_3,0));
 if (GlobalVariableCheck (GlName)) LastProfit_3=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastLot_3"+DoubleToString(Magic_Setka_3,0));
 if (GlobalVariableCheck (GlName)) LastLot_3=GlobalVariableGet(GlName);   
 //------------Сетка 4
 GlName=StringConcatenate("Buy_4"+DoubleToString(Magic_Setka_4,0));
 if (GlobalVariableCheck (GlName)) Buy_4=GlobalVariableGet(GlName);
 GlName=StringConcatenate("Sell_4"+DoubleToString(Magic_Setka_4,0));
 if (GlobalVariableCheck (GlName)) Sell_4=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionBuy_4"+DoubleToString(Magic_Setka_4,0));
 if (GlobalVariableCheck (GlName)) PositionBuy_4=GlobalVariableGet(GlName);
 GlName=StringConcatenate("PositionSell_4"+DoubleToString(Magic_Setka_4,0));
 if (GlobalVariableCheck (GlName)) PositionSell_3=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastProfit_4"+DoubleToString(Magic_Setka_4,0));
 if (GlobalVariableCheck (GlName)) LastProfit_4=GlobalVariableGet(GlName);
 GlName=StringConcatenate("LastLot_4"+DoubleToString(Magic_Setka_4,0));
 if (GlobalVariableCheck (GlName)) LastLot_4=GlobalVariableGet(GlName);  
 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if (TestMode)
    {
     //------------Сетка 1
     GlName=StringConcatenate("Buy"+DoubleToString(Magic_Setka_1,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("Sell"+DoubleToString(Magic_Setka_1,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionBuy"+DoubleToString(Magic_Setka_1,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionSell"+DoubleToString(Magic_Setka_1,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastProfit"+DoubleToString(Magic_Setka_1,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastLot"+DoubleToString(Magic_Setka_1,0));
     GlobalVariableDel (GlName);
     //------------Сетка 2
     GlName=StringConcatenate("Buy_2"+DoubleToString(Magic_Setka_2,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("Sell_2"+DoubleToString(Magic_Setka_2,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionBuy_2"+DoubleToString(Magic_Setka_2,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionSell_2"+DoubleToString(Magic_Setka_2,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastProfit_2"+DoubleToString(Magic_Setka_2,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastLot_2"+DoubleToString(Magic_Setka_2,0));
     GlobalVariableDel (GlName);
     //------------Сетка 3
     GlName=StringConcatenate("Buy_3"+DoubleToString(Magic_Setka_3,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("Sell_3"+DoubleToString(Magic_Setka_3,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionBuy_3"+DoubleToString(Magic_Setka_3,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionSell_3"+DoubleToString(Magic_Setka_3,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastProfit_3"+DoubleToString(Magic_Setka_3,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastLot_3"+DoubleToString(Magic_Setka_3,0));
     GlobalVariableDel (GlName);
     //------------Сетка 4
     GlName=StringConcatenate("Buy_4"+DoubleToString(Magic_Setka_4,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("Sell_4"+DoubleToString(Magic_Setka_4,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionBuy_4"+DoubleToString(Magic_Setka_4,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("PositionSell_4"+DoubleToString(Magic_Setka_4,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastProfit_4"+DoubleToString(Magic_Setka_4,0));
     GlobalVariableDel (GlName);
     GlName=StringConcatenate("LastLot_4"+DoubleToString(Magic_Setka_4,0));
     GlobalVariableDel (GlName);     
         
    }
  }

//-------------------------------------------------------------------+
int start()
{
  string symbol = Symbol();
  int spread=MarketInfo(symbol,MODE_SPREAD);
  if (spread>MaxSpread) return(0);


double TP=0,SL=0;
Buy=0;Sell=0;
Buy_2=0;Sell_2=0;
Buy_3=0;Sell_3=0;
Buy_4=0;Sell_4=0;

//-------------учет ордеров
 //------------Сетка 1
 Buy = OrdersTotalMagic (OP_BUY);
 Sell = OrdersTotalMagic (OP_SELL);
 if (Sell==0) PositionSell=0;
 if (Buy==0)PositionBuy=0;
 if (LastProfit == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
 double MultProfit = Profit;
 if (LastProfit == 1) MultProfit= Profit*Mult;
 //------------Сетка 2
 Buy_2 = OrdersTotalMagic_2 (OP_BUY);
 Sell_2 = OrdersTotalMagic_2 (OP_SELL);
 if (Sell_2==0) PositionSell_2=0;
 if (Buy_2==0)PositionBuy_2=0;
 if (LastProfit_2 == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
 double MultProfit_2 = Profit;
 if (LastProfit_2 == 1) MultProfit_2= Profit*Mult; 
 //------------Сетка 3
 Buy_3 = OrdersTotalMagic_3 (OP_BUY);
 Sell_3 = OrdersTotalMagic_3 (OP_SELL);
 if (Sell_3==0) PositionSell_3=0;
 if (Buy_3==0)PositionBuy_3=0;
 if (LastProfit_3 == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
 double MultProfit_3 = Profit;
 if (LastProfit_3 == 1) MultProfit_3= Profit*Mult; 
 //------------Сетка 3
 Buy_4 = OrdersTotalMagic_4 (OP_BUY);
 Sell_4 = OrdersTotalMagic_4 (OP_SELL);
 if (Sell_4==0) PositionSell_4=0;
 if (Buy_4==0)PositionBuy_4=0;
 if (LastProfit_4 == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
 double MultProfit_4 = Profit;
 if (LastProfit_4 == 1) MultProfit_4= Profit*Mult; 
 
//-------------общие функции 
string SymbolNow = Symbol();
double AskNow=SymbolInfoDouble(SymbolNow,SYMBOL_ASK);
double BidNow=SymbolInfoDouble(SymbolNow,SYMBOL_BID);
double PointNow=SymbolInfoDouble(SymbolNow,SYMBOL_POINT);

//-------------технические индикаторы
   double MA1_0 = iMA(NULL,0,MA_Period_1,MA_Shift_1,MA_Method_1,MA_applied_price_1,0); 


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Закрываем ордера
//-------------------- Сетка 1
  // для села
   if(OrdersTotal()>0 && ((MA1_0 - Level*_Point > Ask && Sell==1) || SummProfit(OP_SELL) > MultProfit)) { if(closeall(OP_SELL)) LastProfit=LP();} 
  // для бая
   if(OrdersTotal()>0 && ((MA1_0 + Level*_Point < Bid && Buy==1) || SummProfit(OP_BUY) > MultProfit)) { if(closeall(OP_BUY)) LastProfit=LP();}

//-------------------- Сетка 2
  // для села
   if(OrdersTotal()>0 && ((MA1_0 - Level*_Point > Ask && Sell_2==1) || SummProfit_2(OP_SELL) > MultProfit_2)) { if(closeall_2(OP_SELL)) LastProfit_2=LP_2();} 
  // для бая
   if(OrdersTotal()>0 && ((MA1_0 + Level*_Point < Bid && Buy_2==1) || SummProfit_2(OP_BUY) > MultProfit_2)) { if(closeall_2(OP_BUY)) LastProfit_2=LP_2();}

//-------------------- Сетка 3
  // для села
   if(OrdersTotal()>0 && ((MA1_0 - Level*_Point > Ask && Sell_3==1) || SummProfit_3(OP_SELL) > MultProfit_3)) { if(closeall_3(OP_SELL)) LastProfit_3=LP_3();} 
  // для бая
   if(OrdersTotal()>0 && ((MA1_0 + Level*_Point < Bid && Buy_3==1) || SummProfit_3(OP_BUY) > MultProfit_3)) { if(closeall_3(OP_BUY)) LastProfit_3=LP_3();}

//-------------------- Сетка 4
  // для села
   if(OrdersTotal()>0 && ((MA1_0 - Level*_Point > Ask && Sell_4==1) || SummProfit_4(OP_SELL) > MultProfit_4)) { if(closeall_4(OP_SELL)) LastProfit_4=LP_4();} 
  // для бая
   if(OrdersTotal()>0 && ((MA1_0 + Level*_Point < Bid && Buy_4==1) || SummProfit_4(OP_BUY) > MultProfit_4)) { if(closeall_4(OP_BUY)) LastProfit_4=LP_4();}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ открываем ордера - Сетка 1

// Открытие ордеров при продаже 2 и 3
Buy = OrdersTotalMagic (OP_BUY);
Sell = OrdersTotalMagic (OP_SELL);

 if(PositionSell > 0 && Sell ==1 && LastPrice(OP_SELL)+Step1*PointNow*2 <= AskNow) 
    {
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_1,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red);
    } 
 if(PositionSell > 0 && Sell ==2 && LastPrice(OP_SELL)+Step1*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_2,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red);
     }
 if(PositionSell > 0 && Sell ==3 && LastPrice(OP_SELL)+Step1*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_3,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red);
     }
 if(PositionSell > 0 && Sell ==4 && LastPrice(OP_SELL)+Step1*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_4,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red);
     }   
 if(PositionSell > 0 && Sell ==5 && LastPrice(OP_SELL)+Step1*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_5,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red);
     }    
 if(PositionSell > 0 && Sell ==6 && LastPrice(OP_SELL)+Step1*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_6,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red);
     }    
// продажа и открытие первого ордера    
if (Sell==0)
  {   
   if (LP() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
   if(MA1_0 + Level*_Point < Bid)
   
            {
             PositionSell=OrderSend(Symbol(),OP_SELL,Lot2,Bid,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Red); // Alert ("Sell", Symbol())
             if(PositionSell>0) LastProfit=0;
             LastLot = Lot2;
            }
    //    }
  } 
   // Открытие ордеров при покупке 2 и 3
 if(PositionBuy > 0 && Buy ==1 && LastPrice(OP_BUY)-Step1*PointNow*2 >=  BidNow) 
    {
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_1,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
    } 
 if(PositionBuy > 0 && Buy ==2 && LastPrice(OP_BUY)-Step1*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_2,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
     }
 if(PositionBuy > 0 && Buy ==3 && LastPrice(OP_BUY)-Step1*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_3,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
     }
 if(PositionBuy > 0 && Buy ==4 && LastPrice(OP_BUY)-Step1*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_4,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
     }
if(PositionBuy > 0 && Buy ==5 && LastPrice(OP_BUY)-Step1*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_5,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
     }
if(PositionBuy > 0 && Buy ==6 && LastPrice(OP_BUY)-Step1*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_6,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
     }

  //покупка и открытие первого ордера 
if (Buy == 0)
 {
  if (LP() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
  if (MA1_0 - Level*_Point > Ask)
  
            {
              PositionBuy=OrderSend(Symbol(),OP_BUY,Lot2,Ask,Slippage,SL,TP,Сomment,Magic_Setka_1,0,Blue);
              if(PositionBuy>0) LastProfit=0;
              LastLot = Lot2;
            }
  } 
    GlName=StringConcatenate("Buy"+DoubleToString(Magic_Setka_1,0));
    GlobalVariableSet (GlName, Buy);
    GlName=StringConcatenate("Sell"+DoubleToString(Magic_Setka_1,0));
    GlobalVariableSet (GlName, Sell);
    GlName=StringConcatenate("PositionBuy"+DoubleToString(Magic_Setka_1,0));
    GlobalVariableSet (GlName, PositionBuy);
    GlName=StringConcatenate("PositionSell"+DoubleToString(Magic_Setka_1,0));
    GlobalVariableSet (GlName, PositionSell);
    GlName=StringConcatenate("LastProfit"+DoubleToString(Magic_Setka_1,0));
    GlobalVariableSet (GlName, LastProfit);
    GlName=StringConcatenate("LastLot"+DoubleToString(Magic_Setka_1,0));
    GlobalVariableSet (GlName, LastLot);


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ открываем ордера - SETKA 2

// Открытие ордеров при продаже 2 и 3
Buy_2 = OrdersTotalMagic_2 (OP_BUY);
Sell_2 = OrdersTotalMagic_2 (OP_SELL);

 if(PositionSell_2 > 0 && Sell_2 ==1 && LastPrice_2(OP_SELL)+Step2*PointNow*2 <= AskNow) 
    {
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_1,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red);
    } 
 if(PositionSell_2 > 0 && Sell_2 ==2 && LastPrice_2(OP_SELL)+Step2*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_2,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red);
     }
 if(PositionSell_2 > 0 && Sell_2 ==3 && LastPrice_2(OP_SELL)+Step2*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_3,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red);
     }
 if(PositionSell_2 > 0 && Sell_2 ==4 && LastPrice_2(OP_SELL)+Step2*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_4,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red);
     }   
 if(PositionSell_2 > 0 && Sell_2 ==5 && LastPrice_2(OP_SELL)+Step2*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_5,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red);
     }    
 if(PositionSell_2 > 0 && Sell_2 ==6 && LastPrice_2(OP_SELL)+Step2*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot*Multiple_6,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red);
     }    
// продажа и открытие первого ордера    
if (Sell_2==0 &&  ((Sell ==Setka2_open_parametr && LastPrice(OP_SELL)+Otstup_setka_2*PointNow <= AskNow) || (Buy ==Setka2_open_parametr && LastPrice(OP_BUY)-Otstup_setka_2*PointNow >= BidNow)))
  {   
   if (LP_2() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
   if(MA1_0 + Level*_Point < Bid)
   
            {
             PositionSell_2=OrderSend(Symbol(),OP_SELL,Lot2,Bid,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Red); // Alert ("Sell", Symbol())
             if(PositionSell_2>0) LastProfit=0;
             LastLot = Lot2;
            }
  } 
   // Открытие ордеров при покупке 2 и 3
 if(PositionBuy_2 > 0 && Buy_2 ==1 && LastPrice_2(OP_BUY)-Step2*PointNow*2 >=  BidNow) 
    {
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_1,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
    } 
 if(PositionBuy_2 > 0 && Buy_2 ==2 && LastPrice_2(OP_BUY)-Step2*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_2,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
     }
 if(PositionBuy_2 > 0 && Buy_2 ==3 && LastPrice_2(OP_BUY)-Step2*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_3,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
     }
 if(PositionBuy_2 > 0 && Buy_2 ==4 && LastPrice_2(OP_BUY)-Step2*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_4,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
     }
if(PositionBuy_2 > 0 && Buy_2 ==5 && LastPrice_2(OP_BUY)-Step2*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_5,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
     }
if(PositionBuy_2 > 0 && Buy_2 ==6 && LastPrice_2(OP_BUY)-Step2*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot*Multiple_6,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
     }

  //покупка и открытие первого ордера 
if (Buy_2 == 0 && ((Sell ==Setka2_open_parametr && LastPrice(OP_SELL)+Otstup_setka_2*PointNow <= AskNow) || (Buy ==Setka2_open_parametr && LastPrice(OP_BUY)-Otstup_setka_2*PointNow >= BidNow)))
 {
  if (LP_2() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
  if (MA1_0 - Level*_Point > Ask)
  
            {
              PositionBuy_2=OrderSend(Symbol(),OP_BUY,Lot2,Ask,Slippage,SL,TP,Сomment,Magic_Setka_2,0,Blue);
              if(PositionBuy_2>0) LastProfit_2=0;
              LastLot = Lot2;
            }
  } 
    GlName=StringConcatenate("Buy_2"+DoubleToString(Magic_Setka_2,0));
    GlobalVariableSet (GlName, Buy_2);
    GlName=StringConcatenate("Sell_2"+DoubleToString(Magic_Setka_2,0));
    GlobalVariableSet (GlName, Sell_2);
    GlName=StringConcatenate("PositionBuy_2"+DoubleToString(Magic_Setka_2,0));
    GlobalVariableSet (GlName, PositionBuy_2);
    GlName=StringConcatenate("PositionSell_2"+DoubleToString(Magic_Setka_2,0));
    GlobalVariableSet (GlName, PositionSell_2);
    GlName=StringConcatenate("LastProfit_2"+DoubleToString(Magic_Setka_2,0));
    GlobalVariableSet (GlName, LastProfit_2);
    GlName=StringConcatenate("LastLot_2"+DoubleToString(Magic_Setka_2,0));
    GlobalVariableSet (GlName, LastLot);


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ открываем ордера - SETKA 2

// Открытие ордеров при продаже 2 и 3
Buy_3 = OrdersTotalMagic_3 (OP_BUY);
Sell_3 = OrdersTotalMagic_3 (OP_SELL);

 if(PositionSell_3 > 0 && Sell_3 ==1 && LastPrice_3(OP_SELL)+Step3*PointNow*2 <= AskNow) 
    {
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red);
    } 
 if(PositionSell_3 > 0 && Sell_3 ==2 && LastPrice_3(OP_SELL)+Step3*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red);
     }
 if(PositionSell_3 > 0 && Sell_3 ==3 && LastPrice_3(OP_SELL)+Step3*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red);
     }
 if(PositionSell_3 > 0 && Sell_3 ==4 && LastPrice_3(OP_SELL)+Step3*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red);
     }   
 if(PositionSell_3 > 0 && Sell_3 ==5 && LastPrice_3(OP_SELL)+Step3*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red);
     }    
 if(PositionSell_3 > 0 && Sell_3 ==6 && LastPrice_3(OP_SELL)+Step3*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red);
     }    
// продажа и открытие первого ордера    
if (Sell_3==0 && Setkа_3_switch==TRUE && ((Sell_2 ==Setka3_open_parametr && LastPrice_2(OP_SELL)+Otstup_setka_3*PointNow <= AskNow) || (Buy_2 ==Setka3_open_parametr && LastPrice_2(OP_BUY)-Otstup_setka_3*PointNow >= BidNow)))
  {   
   if (LP_3() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
   if(MA1_0 + Level*_Point < Bid)
   
            {
             PositionSell_3=OrderSend(Symbol(),OP_SELL,Lot2,Bid,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Red); // Alert ("Sell", Symbol())
             if(PositionSell_3>0) LastProfit_3=0;
             LastLot = Lot2;
            }
  } 
   // Открытие ордеров при покупке 2 и 3
 if(PositionBuy_3 > 0 && Buy_3 ==1 && LastPrice_3(OP_BUY)-Step3*PointNow*2 >=  BidNow) 
    {
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
    } 
 if(PositionBuy_3 > 0 && Buy_3 ==2 && LastPrice_3(OP_BUY)-Step3*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
     }
 if(PositionBuy_3 > 0 && Buy_3 ==3 && LastPrice_3(OP_BUY)-Step3*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
     }
 if(PositionBuy_3 > 0 && Buy_3 ==4 && LastPrice_3(OP_BUY)-Step3*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
     }
if(PositionBuy_3 > 0 && Buy_3 ==5 && LastPrice_3(OP_BUY)-Step3*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
     }
if(PositionBuy_3 > 0 && Buy_3 ==6 && LastPrice_3(OP_BUY)-Step3*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
     }

  //покупка и открытие первого ордера 
if (Buy_3 == 0 && Setkа_3_switch==TRUE && ((Sell_2 ==Setka3_open_parametr && LastPrice_2(OP_SELL)+Otstup_setka_3*PointNow <= AskNow) || (Buy_2 ==Setka3_open_parametr && LastPrice_2(OP_BUY)-Otstup_setka_3*PointNow >= BidNow)))
 {
  if (LP_3() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
  if (MA1_0 - Level*_Point > Ask)
  
            {
              PositionBuy_3=OrderSend(Symbol(),OP_BUY,Lot2,Ask,Slippage,SL,TP,Сomment,Magic_Setka_3,0,Blue);
              if(PositionBuy_3>0) LastProfit_3=0;
              LastLot = Lot2;
            }
  } 
    GlName=StringConcatenate("Buy_3"+DoubleToString(Magic_Setka_3,0));
    GlobalVariableSet (GlName, Buy_3);
    GlName=StringConcatenate("Sell_3"+DoubleToString(Magic_Setka_3,0));
    GlobalVariableSet (GlName, Sell_3);
    GlName=StringConcatenate("PositionBuy_3"+DoubleToString(Magic_Setka_3,0));
    GlobalVariableSet (GlName, PositionBuy_3);
    GlName=StringConcatenate("PositionSell_3"+DoubleToString(Magic_Setka_3,0));
    GlobalVariableSet (GlName, PositionSell_3);
    GlName=StringConcatenate("LastProfit_3"+DoubleToString(Magic_Setka_3,0));
    GlobalVariableSet (GlName, LastProfit_3);
    GlName=StringConcatenate("LastLot_3"+DoubleToString(Magic_Setka_3,0));
    GlobalVariableSet (GlName, LastLot);

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ открываем ордера - SETKA 2

// Открытие ордеров при продаже 2 и 3
Buy_4 = OrdersTotalMagic_4 (OP_BUY);
Sell_4 = OrdersTotalMagic_4 (OP_SELL);

 if(PositionSell_4 > 0 && Sell_4 ==1 && LastPrice_4(OP_SELL)+Step4*PointNow*2 <= AskNow) 
    {
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red);
    } 
 if(PositionSell_4 > 0 && Sell_4 ==2 && LastPrice_4(OP_SELL)+Step4*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red);
     }
 if(PositionSell_4 > 0 && Sell_4 ==3 && LastPrice_4(OP_SELL)+Step4*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red);
     }
 if(PositionSell_4 > 0 && Sell_4 ==4 && LastPrice_4(OP_SELL)+Step4*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red);
     }   
 if(PositionSell_4 > 0 && Sell_4 ==5 && LastPrice_4(OP_SELL)+Step4*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red);
     }    
 if(PositionSell_4 > 0 && Sell_4 ==6 && LastPrice_4(OP_SELL)+Step4*PointNow <= AskNow) 
     {  
       tts_S1 = OrderSend(Symbol(),OP_SELL,LastLot,BidNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red);
     }    
// продажа и открытие первого ордера    
if (Sell_4==0 && Setkа_4_switch==TRUE && ((Sell_3 ==Setka4_open_parametr && LastPrice_3(OP_SELL)+Otstup_setka_4*PointNow <= AskNow) || (Buy_3 ==Setka4_open_parametr && LastPrice_3(OP_BUY)-Otstup_setka_4*PointNow >= BidNow)))
  {   
   if (LP_4() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
   if(MA1_0 + Level*_Point < Bid)
   
            {
             PositionSell_4=OrderSend(Symbol(),OP_SELL,Lot2,Bid,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Red); // Alert ("Sell", Symbol())
             if(PositionSell_4>0) LastProfit_4=0;
             LastLot = Lot2;
            }
  } 
   // Открытие ордеров при покупке 2 и 3
 if(PositionBuy_4 > 0 && Buy_4 ==1 && LastPrice_4(OP_BUY)-Step4*PointNow*2 >=  BidNow) 
    {
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
    } 
 if(PositionBuy_4 > 0 && Buy_4 ==2 && LastPrice_4(OP_BUY)-Step4*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
     }
 if(PositionBuy_4 > 0 && Buy_4 ==3 && LastPrice_4(OP_BUY)-Step4*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
     }
 if(PositionBuy_4 > 0 && Buy_4 ==4 && LastPrice_4(OP_BUY)-Step4*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
     }
if(PositionBuy_4 > 0 && Buy_4 ==5 && LastPrice_4(OP_BUY)-Step4*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
     }
if(PositionBuy_4 > 0 && Buy_4 ==6 && LastPrice_4(OP_BUY)-Step4*PointNow >= BidNow) 
     {  
       ttb_B1 = OrderSend(Symbol(),OP_BUY,LastLot,AskNow,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
     }

  //покупка и открытие первого ордера 
if (Buy_4 == 0 && Setkа_4_switch==TRUE && ((Sell_3 ==Setka4_open_parametr && LastPrice_3(OP_SELL)+Otstup_setka_4*PointNow <= AskNow) || (Buy_3 ==Setka3_open_parametr && LastPrice_3(OP_BUY)-Otstup_setka_4*PointNow >= BidNow)))
 {
  if (LP_4() == 1) Lot2= NormalizeDouble (Lots*2,2); else Lot2=Lots;
  if (MA1_0 - Level*_Point > Ask)
  
            {
              PositionBuy_4=OrderSend(Symbol(),OP_BUY,Lot2,Ask,Slippage,SL,TP,Сomment,Magic_Setka_4,0,Blue);
              if(PositionBuy_4>0) LastProfit_4=0;
              LastLot = Lot2;
            }
  } 
    GlName=StringConcatenate("Buy_4"+DoubleToString(Magic_Setka_4,0));
    GlobalVariableSet (GlName, Buy_4);
    GlName=StringConcatenate("Sell_4"+DoubleToString(Magic_Setka_4,0));
    GlobalVariableSet (GlName, Sell_4);
    GlName=StringConcatenate("PositionBuy_4"+DoubleToString(Magic_Setka_4,0));
    GlobalVariableSet (GlName, PositionBuy_4);
    GlName=StringConcatenate("PositionSell_4"+DoubleToString(Magic_Setka_4,0));
    GlobalVariableSet (GlName, PositionSell_4);
    GlName=StringConcatenate("LastProfit_4"+DoubleToString(Magic_Setka_4,0));
    GlobalVariableSet (GlName, LastProfit_4);
    GlName=StringConcatenate("LastLot_4"+DoubleToString(Magic_Setka_4,0));
    GlobalVariableSet (GlName, LastLot);

   return(0);
 
}

/*-------------------------------------------------------------------------------------------------------------------+
|  П О Л Ь З О В А Т Е Л Ь С К И Е   Ф У Н К Ц И И - C E Т К А 1                                                     |
+-------------------------------------------------------------------------------------------------------------------*/ 

//---------------------------------------------------------------------------------------------//
//Определение количества ордеров серии 
//---------------------------------------------------------------------------------------------//
int OrdersTotalMagic (int Type)
  {
  int totalmagic=0;
  RefreshRates();
  for (int i=OrdersTotal()-1;i>=0;i--) 
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic_Setka_1 && OrderType()==Type) 
   totalmagic++;
   }
   }
   return (totalmagic);
  }     

//---------------------------------------------------------------------------------------------//
//Определение цены открытия первого ордера серии 
//---------------------------------------------------------------------------------------------// 
double FirstPrice (int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=OrdersTotal()-1;i2>=0;i2--)
   {
   if(OrderSelect(i2,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magic_Setka_1 && OrderType()==Type) 
   Price=OrderOpenPrice();
   }
   }
   return (Price);
  }   
  //---------------------------------------------------------------------------------------------//
//Определение цены открытия последнего ордера серии 
//---------------------------------------------------------------------------------------------// 
double LastPrice (int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=0;i2= 0; cnt--) 
   { 
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
   { 
   if (OrderSymbol() == Symbol() && (OrderMagicNumber() == Magic_Setka_1 && OrderType()==Type  && OrderCloseTime()==0)) 
    { 
    if(OrderType()==OP_BUY)  
    {
     if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue)) 
     {i++; continue;}
    }
    if(OrderType()==OP_SELL) 
    {
     if(OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red))
     {i++; continue;}
    } 
    }
   }
   }
   if(i==OrdersTotal()) res=true;
   return(res);
  }
//---------------------------------------------------------------------------------------------//
//Определение суммарного профита
//---------------------------------------------------------------------------------------------//
double SummProfit (int Type)
  {
  double Summ=0;
  RefreshRates();
  for (int i2=0;i2ht-4; i--)
 {
 if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderSymbol()==_Symbol && OrderMagicNumber () == Magic_Setka_1))
  //if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
  {
   if(OrderProfit()>0) break;
   n++;
  }
 }
 if(n>=3) r=1;
 return(r);
}  


/*-------------------------------------------------------------------------------------------------------------------+
|  П О Л Ь З О В А Т Е Л Ь С К И Е   Ф У Н К Ц И И - C E Т К А 2                                                     |
+-------------------------------------------------------------------------------------------------------------------*/ 

//---------------------------------------------------------------------------------------------//
//Определение количества ордеров серии 
//---------------------------------------------------------------------------------------------//
int OrdersTotalMagic_2 (int Type)
  {
  int totalmagic=0;
  RefreshRates();
  for (int i=OrdersTotal()-1;i>=0;i--) 
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic_Setka_2 && OrderType()==Type) 
   totalmagic++;
   }
   }
   return (totalmagic);
  }     

//---------------------------------------------------------------------------------------------//
//Определение цены открытия первого ордера серии 
//---------------------------------------------------------------------------------------------// 
double FirstPrice_2 (int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=OrdersTotal()-1;i2>=0;i2--)
   {
   if(OrderSelect(i2,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magic_Setka_2 && OrderType()==Type) 
   Price=OrderOpenPrice();
   }
   }
   return (Price);
  }   
  //---------------------------------------------------------------------------------------------//
//Определение цены открытия последнего ордера серии 
//---------------------------------------------------------------------------------------------// 
double LastPrice_2(int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=0;i2= 0; cnt--) 
   { 
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
   { 
   if (OrderSymbol() == Symbol() && (OrderMagicNumber() == Magic_Setka_2 && OrderType()==Type  && OrderCloseTime()==0)) 
    { 
    if(OrderType()==OP_BUY)  
    {
     if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue)) 
     {i++; continue;}
    }
    if(OrderType()==OP_SELL) 
    {
     if(OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red))
     {i++; continue;}
    } 
    }
   }
   }
   if(i==OrdersTotal()) res=true;
   return(res);
  }
//---------------------------------------------------------------------------------------------//
//Определение суммарного профита
//---------------------------------------------------------------------------------------------//
double SummProfit_2(int Type)
  {
  double Summ=0;
  RefreshRates();
  for (int i2=0;i2ht-4; i--)
 {
 if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderSymbol()==_Symbol && OrderMagicNumber () == Magic_Setka_2))
  //if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
  {
   if(OrderProfit()>0) break;
   n++;
  }
 }
 if(n>=3) r=1;
 return(r);
}



/*-------------------------------------------------------------------------------------------------------------------+
|  П О Л Ь З О В А Т Е Л Ь С К И Е   Ф У Н К Ц И И - C E Т К А 3                                                     |
+-------------------------------------------------------------------------------------------------------------------*/ 

//---------------------------------------------------------------------------------------------//
//Определение количества ордеров серии 
//---------------------------------------------------------------------------------------------//
int OrdersTotalMagic_3 (int Type)
  {
  int totalmagic=0;
  RefreshRates();
  for (int i=OrdersTotal()-1;i>=0;i--) 
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic_Setka_3 && OrderType()==Type) 
   totalmagic++;
   }
   }
   return (totalmagic);
  }     

//---------------------------------------------------------------------------------------------//
//Определение цены открытия первого ордера серии 
//---------------------------------------------------------------------------------------------// 
double FirstPrice_3 (int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=OrdersTotal()-1;i2>=0;i2--)
   {
   if(OrderSelect(i2,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magic_Setka_3 && OrderType()==Type) 
   Price=OrderOpenPrice();
   }
   }
   return (Price);
  }   
  //---------------------------------------------------------------------------------------------//
//Определение цены открытия последнего ордера серии 
//---------------------------------------------------------------------------------------------// 
double LastPrice_3(int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=0;i2= 0; cnt--) 
   { 
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
   { 
   if (OrderSymbol() == Symbol() && (OrderMagicNumber() == Magic_Setka_3 && OrderType()==Type  && OrderCloseTime()==0)) 
    { 
    if(OrderType()==OP_BUY)  
    {
     if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue)) 
     {i++; continue;}
    }
    if(OrderType()==OP_SELL) 
    {
     if(OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red))
     {i++; continue;}
    } 
    }
   }
   }
   if(i==OrdersTotal()) res=true;
   return(res);
  }
//---------------------------------------------------------------------------------------------//
//Определение суммарного профита
//---------------------------------------------------------------------------------------------//
double SummProfit_3(int Type)
  {
  double Summ=0;
  RefreshRates();
  for (int i2=0;i2ht-4; i--)
 {
 if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderSymbol()==_Symbol && OrderMagicNumber () == Magic_Setka_3))
  //if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
  {
   if(OrderProfit()>0) break;
   n++;
  }
 }
 if(n>=3) r=1;
 return(r);
} 



/*-------------------------------------------------------------------------------------------------------------------+
|  П О Л Ь З О В А Т Е Л Ь С К И Е   Ф У Н К Ц И И - C E Т К А 4                                                     |
+-------------------------------------------------------------------------------------------------------------------*/ 

//---------------------------------------------------------------------------------------------//
//Определение количества ордеров серии 
//---------------------------------------------------------------------------------------------//
int OrdersTotalMagic_4 (int Type)
  {
  int totalmagic=0;
  RefreshRates();
  for (int i=OrdersTotal()-1;i>=0;i--) 
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic_Setka_4 && OrderType()==Type) 
   totalmagic++;
   }
   }
   return (totalmagic);
  }     

//---------------------------------------------------------------------------------------------//
//Определение цены открытия первого ордера серии 
//---------------------------------------------------------------------------------------------// 
double FirstPrice_4 (int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=OrdersTotal()-1;i2>=0;i2--)
   {
   if(OrderSelect(i2,SELECT_BY_POS,MODE_TRADES))
   {
   if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magic_Setka_4 && OrderType()==Type) 
   Price=OrderOpenPrice();
   }
   }
   return (Price);
  }   
  //---------------------------------------------------------------------------------------------//
//Определение цены открытия последнего ордера серии 
//---------------------------------------------------------------------------------------------// 
double LastPrice_4(int Type)
  {
  double Price=0;
  RefreshRates();
  for (int i2=0;i2= 0; cnt--) 
   { 
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
   { 
   if (OrderSymbol() == Symbol() && (OrderMagicNumber() == Magic_Setka_4 && OrderType()==Type  && OrderCloseTime()==0)) 
    { 
    if(OrderType()==OP_BUY)  
    {
     if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue)) 
     {i++; continue;}
    }
    if(OrderType()==OP_SELL) 
    {
     if(OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red))
     {i++; continue;}
    } 
    }
   }
   }
   if(i==OrdersTotal()) res=true;
   return(res);
  }
//---------------------------------------------------------------------------------------------//
//Определение суммарного профита
//---------------------------------------------------------------------------------------------//
double SummProfit_4(int Type)
  {
  double Summ=0;
  RefreshRates();
  for (int i2=0;i2ht-4; i--)
 {
 if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderSymbol()==_Symbol && OrderMagicNumber () == Magic_Setka_4))
  //if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
  {
   if(OrderProfit()>0) break;
   n++;
  }
 }
 if(n>=3) r=1;
 return(r);
} 

Recommend