dibujando la línea H en el máximo de los últimos 36 máximos - página 3

 
cichichan:

algunas ideas, lo que está mal ... ¿alguien?

gracias

Una vez que creas un objeto....

ObjectCreate("tomato "+H,OBJ_ARROW,0,Time[high_bar],LSell+Point*20);

. . . no puedes volver a crearlo, ya existe . . . en su lugar comprueba si existe y si lo hace no intentes crearlo de nuevo, simplemente muévelo usando ObjectSet()

 

usé un nombre diferente para cada vela para que no hubiera problema con el objeto.

Lo reescribí así y ahora funciona perfectamente:

establece un nivel de venta, y si obtengo dos cierres por encima de ese nivel -> LevelSset=false -> comienza a buscar el siguiente LSell.

int start()
  {
//----
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

if (stoch>75 && LevelSset==false)
{
   LSell=High[iHighest(NULL,0,MODE_HIGH,34,2)];
   high_bar=iHighest(NULL,0,MODE_HIGH,34,2);

   if(Bid<LSell && High[0]<LSell && High[1]<LSell)
   {
   ObjectCreate("tomato "+Time[0],OBJ_ARROW,0,Time[high_bar],LSell+Point*20);
   ObjectSet("tomato "+Time[0],OBJPROP_ARROWCODE,242);
   ObjectSet("tomato "+Time[0],OBJPROP_COLOR,Tomato);
   LevelSset=true;
   Print("LevelSset on "+LSell);
   }
}
if(LevelSset==true)
   if(Close[2]>LSell && Close[1]>LSell)
   {
      LevelSset=false;
      Print (LSell+" expired");
   }
   
   
//----
   return(0);
  }
 

hola, necesito ayuda.

no puedo hacer una condición de expiración de tiempo para el nivel de precios. como mencioné antes, si el precio se mantiene por debajo de LSell o por encima de LBuy durante más de 96 velas, para descartar ese nivel de precios.

estaba intentando usar if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... pero parece que no funciona.... void CkExpLSell ()... estoy seguro de que estoy haciendo algo mal pero... no tengo ni idea de qué, así que ayuda pls :)

//+------------------------------------------------------------------+
//|                                                      3expert.mq4 |
//|                                                              ant |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ant"
#property link      ""
#property indicator_chart_window
#property indicator_buffers 1
#property  indicator_color1 Yellow

extern bool UseTrigger1=true;
extern bool UseTrigger2=true;

extern int Kperiod = 80;
extern int Dperiod = 30;
extern int Stochshift = 30;

extern int AddToSL=0;
extern int MinSL=50;
extern int MaxSL=100;
extern int TakeProfit=50;
extern int Slippage=0;
extern double lot=0.10;
int MagicNumber=777;


bool TriggerBuy1=false;
bool TriggerBuy2=false;
bool TriggerSell1=false;
bool TriggerSell2=false;
bool LevelBset=false;
bool LevelSset=false;
double LevelB,LevelS;
double ticketBuy,ticketSell;
double SL,TP;
double stoch;
double LBuy;
double LSell;
int high_bar,low_bar;
bool BarsOnChart;
bool AlternativeEntryB=false;
datetime AlternativeEntryBTime;
bool AlternativeEntryS=false;
datetime AlternativeEntrySTime;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

SellLevelSet();
CkExpLSell ();
BuyLevelSet();
CkExpLBuy ();
if (LevelSset==true || LevelBset==true)
{
   if (IsNewBar ())
   {
      CheckTrigger();
   }
}

//----
   return(0);
  }
//+------------------------------------------------------------------+

////////////////////////////IsNewCandle///////////////////////////////
bool IsNewBar ()
{
   if (Bars==BarsOnChart)
   return(false);
   BarsOnChart = Bars;
   return(true);
}

/////////////////////////////LSell Setup////////////////////////////////

void SellLevelSet()
{
if (stoch>75 && LevelSset==false)
{
   LSell=High[iHighest(NULL,0,MODE_HIGH,34,2)];
   high_bar=iHighest(NULL,0,MODE_HIGH,34,2);

   if(Bid<LSell && High[0]<LSell && High[1]<LSell)
   {
   ObjectCreate("tomato "+Time[0],OBJ_ARROW,0,Time[high_bar],LSell+Point*20);
   ObjectSet("tomato "+Time[0],OBJPROP_ARROWCODE,242);
   ObjectSet("tomato "+Time[0],OBJPROP_COLOR,Tomato);
   LevelSset=true;
   Print("LevelSset on "+DoubleToStr(LSell,5));
   }
}
}

///////////////////////////////LSellCheckExp/////////////////////////////////
void CkExpLSell ()
{
if(LevelSset==true)
 {
   if(Close[2]>LSell && Close[1]>LSell)                    //LSell expires after two bars close over
      {
      LevelSset=false;
      Print (DoubleToStr(LSell,5)+" expired - close");
      }
   if(Time[high_bar]<Time[96])                           //LSell expires after 96 bars
      {
      LevelSset=false;
      Print (DoubleToStr(LSell,5)+" expired - time");
      }
   
  }
 }
 /////////////////////////////LBuy Setup////////////////////////////////

void BuyLevelSet()
{
if (stoch<25 && LevelBset==false)
{
   LBuy=Low[iLowest(NULL,0,MODE_HIGH,34,2)];
   low_bar=iLowest(NULL,0,MODE_HIGH,34,2);

   if(Bid>LBuy && Low[0]>LBuy && Low[1]>LBuy)
   {
   ObjectCreate("olive "+Time[0],OBJ_ARROW,0,Time[low_bar],LBuy-Point*20);
   ObjectSet("olive "+Time[0],OBJPROP_ARROWCODE,241);
   ObjectSet("olive "+Time[0],OBJPROP_COLOR,Olive);
   LevelBset=true;
   Print("LevelBset on "+DoubleToStr(LBuy,5));
   }
}
}
///////////////////////////////LBuyCheckExp/////////////////////////////////
void CkExpLBuy ()
{
if(LevelBset==true)
 {
   if(Close[2]<LBuy && Close[1]<LBuy)
      {
      LevelBset=false;
      Print (DoubleToStr(LBuy,5)+" expired - close");
      }
  }
 }
 
 
//////////////////////CHECK TRIGGER/////////////////////
void CheckTrigger()
{

   //Trigger1
   if (UseTrigger1)
   {
      if  (Low[2]>LBuy && Low[1]<LBuy && Close[1]>LBuy)
         {
         TriggerBuy1=true;
         Alert("Tbuy1 ON");  
         }
      else
         TriggerBuy1=false;
   
      if  (High[2]<LSell && High[1]>LSell &&  Close[1]<LSell)
         {
         TriggerSell1=true;
         Alert("TSeLL1 ON");
         }
      else
         TriggerSell1=false;
   } 
   else 
   {
      TriggerBuy1=false;  
      TriggerSell1=false;  
   }
   //Trigger2 
   if (UseTrigger2)
   {  
      if  (Low[3]>LBuy  && Low[2]<LBuy && Close[2]<LBuy && Close[1]>LBuy)
  {
      TriggerBuy2=true;
      Alert("Tbuy2 ON");
  }
      else
      TriggerBuy2=false;  
   
      if  (High[3]<LSell && High[2]>LSell && Close[2]>LSell && Close[1]<LSell)

      TriggerSell2=true;
      else
      TriggerSell2=false;     
   }
   else 
   {
   TriggerBuy2=false;  
   TriggerSell2=false;  
   }
   
   CheckOpen();
}

//////////////////////////////////CheckOpen///////////////////////////////////

void CheckOpen()
{
if (TriggerBuy1) 
   {
      SL=Low[1]-AddToSL*Point;
      if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point>=MinSL)
      {
         Print("Trigger1: SL" +DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ " pips");
         OpenTrade(1,"Trigger1");
      }
 
      if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point<MinSL)
         {
         SL=Open[0]-MinSL*Point;
         Print("Trigger1: SL minimum"+ DoubleToStr(MinSL,0)+  "pips, SL="+DoubleToStr(SL,5));
         OpenTrade(1,"Trigger1");
         }
      if ( (Open[0]-SL)/Point>MaxSL)
      {
       
         Print("Trigger1: SL  not taken because difference is ",DoubleToStr((Open[0]-SL)/Point,0));
         AlternativeEntryB=true;
         AlternativeEntryBTime=Time[0];
       
      }
   }
   if (TriggerSell1) 
   {
      SL=High[1]+AddToSL*Point;
      SL=SL+MathAbs(Ask-Bid);
      if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point>=MinSL)
      {
         Print("Trigger1: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
         OpenTrade(2,"Trigger1");
      }
       
      if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point<MinSL)
      {
         SL=Open[0]+MinSL*Point+MathAbs(Ask-Bid);
         Print("Trigger1: SL minimum"+ DoubleToStr(MinSL,0)+  "pips, SL="+DoubleToStr(SL,5));
         OpenTrade(2,"Trigger1");
      }
      if ( (SL-Open[0])/Point<=MaxSL)
      {
         
         Print("Trigger1: SL  not taken because difference is ",DoubleToStr((SL-Open[0])/Point,0));
         AlternativeEntryS=true;
         AlternativeEntrySTime=Time[0];
  
      }
   }
   

   if (TriggerBuy2) 
   {
      SL=Low[iLowest(NULL,0,MODE_LOW,3,1)]-AddToSL*Point;
      if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point>=MinSL)
      {
         Print("Trigger2: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
         OpenTrade(1,"Trigger2");
      }
 
      if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point<MinSL)
         {
         SL=Open[0]-MinSL*Point;
         Print("Trigger2: SL minimum"+ DoubleToStr(MinSL,0)+ " pips, SL="+DoubleToStr(SL,5));
         OpenTrade(1,"Trigger2");
         }
      if ( (Open[0]-SL)/Point>MaxSL)
      {
       
         Print("Trigger2: SL  not taken because difference is ",DoubleToStr((Open[0]-SL)/Point,0));
         AlternativeEntryB=true;
         AlternativeEntryBTime=Time[0];
       
      }
   }
   if (TriggerSell2) 
   {
      SL=High[iHighest(NULL,0,MODE_HIGH,3,1)]+AddToSL*Point;
      SL=SL+MathAbs(Ask-Bid);
      if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point>=MinSL)
      {
         Print("Trigger2: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
         OpenTrade(2,"Trigger2");
      }
       
      if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point<MinSL)
      {
         SL=Open[0]+MinSL*Point+MathAbs(Ask-Bid);
         Print("Trigger2: SL minimum"+ DoubleToStr(MinSL,0)+  "pips, SL="+DoubleToStr(SL,5));
         OpenTrade(2,"Trigger2");
      }
      if ( (SL-Open[0])/Point<=MaxSL)
      {
         
         Print("Trigger2: SL  not taken because difference is ",DoubleToStr((SL-Open[0])/Point,0));
         AlternativeEntryS=true;
         AlternativeEntrySTime=Time[0];
  
      }
   }
}

//////////////////////////////////////////Open Trade//////////////////////////////////////////////

void OpenTrade(int dir,string trigger)
{
ticketBuy=0;
ticketSell=0;
   if (dir==1)
   {
      Print(trigger, " - Opening BUY");
      TP=Ask+TakeProfit*Point;
      ticketBuy=OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,SL,TP,trigger,MagicNumber,0,Blue);
   }  
   if (dir==2)
   {
      Print(trigger, " - Opening SELL");
      TP=Bid-TakeProfit*Point;
      ticketSell=OrderSend(Symbol(),OP_SELL,lot,Bid,Slippage,SL,TP,trigger,MagicNumber,0,Red);
   }   
   
   if (ticketBuy>0)
   {
      Print("Deleting - Buy Level", DoubleToStr(LBuy,5));
      LevelBset=false;
   }  
   
   if (ticketSell>0)
   {
      Print("Deleting - Sell Level", DoubleToStr(LSell,5));
      LevelSset=false;
   }  
}
 
necesito ayuda. ¡gracias!
 
   int Bar96 = 96 * Period() * 60;
   string Name;
   double SetBar;
   for(i = 0; i < ObjectsTotal(); i++)
      {
      Name=ObjectName(i);
      SetBar = ObjectGet(Name, OBJPROP_TIME1);
      if (Time[0] - Bar96 > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
         {
         LevelSset = false;
         }
      }
 
cichichan:

hola, necesito ayuda.

no puedo hacer una condición de expiración de tiempo para el nivel de precios. como mencioné antes, si el precio se mantiene por debajo de LSell o por encima de LBuy durante más de 96 velas, para descartar ese nivel de precios.

estaba tratando de usar if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... pero parece que no está funcionando.... void CkExpLSell ()... estoy seguro de que estoy haciendo algo mal pero... no tengo idea de qué, así que ayuda pls :)

ObjectCreate("olive "+Time[0]

el nombre de la línea te está diciendo el momento en que se crea

ya te he dado en este tema como comprobar usando el nombre de la línea la forma de comprobar el tiempo de expiración

¡y no veo que estés usando ese método!

#property copyright "ant"
#property link      ""
#property indicator_chart_window
#property indicator_buffers 1
#property  indicator_color1 Yellow

Su indicador no puede hacer tradingfunctions !!!!!!!!........

Haz un EA si haces OrderSend

 
deVries:

el nombre de la línea le indica el momento en que se creó

ya te he dado en este tema como comprobar usando el nombre de la línea la forma de comprobar el tiempo de expiración

y no veo que estés usando ese método.


@ deVries ObjectGet(Name, OBJPROP_TIME1) es aún mejor, no hay necesidad de código innecesario (StringSubstr() StrToTime())
 
qjol:
   int Bar96 = 96 * Period() * 60;
:
     if (Time[0] - Bar96 > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
Esto supone que no hay barras perdidas en el gráfico, como tiene M1 cuando no hay ticks en un minuto, o todos los TFs menos que semanales sobre el fin de semana. No suponga, simplifique:
Hace 96 bares
// int Bar96 = 96 * Period() * 60;
:
     if (Time[96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
Hace 96 barras completas.
   int Bar96 = iBarShift(NULL,0, Time[0] - 96 * Period() * 60);
:
     if (Time[Bar96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
 
correcto, mi error
 

Hola tios,

en el probador de estrategias las cosas se ven bien. luego puse el ea en cuentas de demostración de diferentes plataformas y funcionó (estableciendo niveles de precios y haciendo transacciones como se esperaba) hasta que apareció este error.

cambié el período de prueba en el probador de estrategias y obtuve el mismo error... no importa si es un LevelBset o un LevelSset, el ea está configurando el nivel al precio correcto, luego el nivel de precio se modifica a 0.0000.

No encontré el error hasta ahora, así que por favor revisa mi código.

gracias por su ayuda.

 //+------------------------------------------------------------------+
//|                                                      3expert.mq4 |
//|                                                              ant |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ant"
#property link        ""


extern bool UseTrigger1= true ;
extern bool UseTrigger2= true ;

extern int Kperiod = 80 ;
extern int Dperiod = 30 ;
extern int Stochshift = 30 ;

extern int AddToSL= 0 ;
extern int MinSL= 50 ;
extern int MaxSL= 100 ;
extern int TakeProfit= 50 ;
extern int Slippage= 0 ;
extern double lot= 1 ;
int MagicNumber= 777 ;

/*extern int Startday=1;
extern int Starthour=0;
extern int Startminute=30;
extern int Endday=5;
extern int Endhour=20;
extern int Closehour=20;
bool Weekend=false;*/

bool TriggerBuy1= false ;
bool TriggerBuy2= false ;
bool TriggerSell1= false ;
bool TriggerSell2= false ;
bool LevelBset= false ;
bool LevelSset= false ;
double LevelB,LevelS;
double ticketBuy,ticketSell;
double SL,TP;
double stoch;
double LBuy;
double LSell;
int high_bar,low_bar;
bool AlternativeEntryB= false ;
datetime AlternativeEntryBTime;
bool AlternativeEntryS= false ;
datetime AlternativeEntrySTime;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
//if (TradingHours())
if (WeClose())
 return ( 0 );

stoch= iStochastic ( NULL , 0 ,Kperiod,Dperiod,Stochshift, MODE_SMA , 1 , MODE_MAIN , 0 );
SellLevelSet();
BuyLevelSet();

if ( OrdersTotal ()== 0 )
{
CheckRecoveryTrade();
CheckAlternativeEntry();
}

if (LevelSset== true || LevelBset== true )
{
   if (IsNewBar ())
   {
      CkExpLSell ();
      CkExpLBuy ();
      CkExpTime();
      CheckTrigger();
   }
}

//----
   return ( 0 );
  }
//+------------------------------------------------------------------+

////////////////////////////TradingHours//////////////////////////////
bool WeClose ()
{
if ( DayOfWeek ()== 0 || DayOfWeek ()== 6 )
  { LevelSset= false ;
   del242();
   LevelBset= false ;
   del241();
   return ( true );
   }
else
   { return ( false );}
}
////////////////////////////IsNewCandle///////////////////////////////
bool IsNewBar ()
{
   int BarsOnChart;
   if ( Bars ==BarsOnChart)
   return ( false );
   BarsOnChart = Bars ;
   return ( true );
}

/////////////////////////////LSell Setup////////////////////////////////

void SellLevelSet()
{
if (stoch> 75 && LevelSset== false )
{
   LSell= High [ iHighest ( NULL , 0 , MODE_HIGH , 34 , 2 )];
   high_bar= iHighest ( NULL , 0 , MODE_HIGH , 34 , 2 );

   if ( Bid <LSell && High [ 0 ]<LSell && High [ 1 ]<LSell)
   {
       if ( Time [high_bar]> TimeCurrent ()- 10800 )
         {
             ObjectCreate ( "tomato " + Time [high_bar], OBJ_ARROW , 0 , Time [high_bar],LSell+ Point * 20 );
             ObjectSet ( "tomato " + Time [high_bar], OBJPROP_ARROWCODE , 242 );
             ObjectSet ( "tomato " + Time [high_bar], OBJPROP_COLOR ,Tomato);
            LevelSset= true ;
             Print ( "LevelSset on " + DoubleToStr (LSell, 5 ));
          }
   }
}
}


///////////////////////////////Object Delete////////////////////////////////
void del242 ()
{
   string Name;
   double SetBar;
   for ( int i = 0 ; i < ObjectsTotal (); i++)
         {
            Name= ObjectName (i);
            SetBar = ObjectGet (Name, OBJPROP_TIME1 );
             if ( ObjectGet (Name, OBJPROP_ARROWCODE ) == 242 )
               {
               ObjectDelete (Name);
               }
         }
}

void del241 ()
{
   string Name;
   double SetBar;
   for ( int i = 0 ; i < ObjectsTotal (); i++)
         {
            Name= ObjectName (i);
            SetBar = ObjectGet (Name, OBJPROP_TIME1 );
             if ( ObjectGet (Name, OBJPROP_ARROWCODE ) == 241 )
               {
               ObjectDelete (Name);
               }
         }
}

///////////////////////////////LSellCheckExp/////////////////////////////////
void CkExpLSell ()
{

   if ( Close [ 2 ]>LSell && Close [ 1 ]>LSell)                     //LSell expires after two bars close over
      {
         LevelSset= false ;
         Print ( DoubleToStr (LSell, 5 )+ " expired - close" );
         del242 ();
      }
 }
 
 ////////////////////////////////96BarExp//////////////////////////////
void CkExpTime ()   
  {  
     int Bar96 = iBarShift ( NULL , 0 , Time [ 0 ]- 96 * Period ()* 60 );
   string Name;
   double SetBar;
   for ( int i = 0 ; i < ObjectsTotal (); i++)
      {
      Name= ObjectName (i);
      SetBar = ObjectGet (Name, OBJPROP_TIME1 );
       if ( Time [Bar96] > SetBar && ObjectGet (Name, OBJPROP_ARROWCODE ) == 242 )
         {
         LevelSset = false ;
         Print ( DoubleToStr (LSell, 5 )+ " expired - time" );
         ObjectDelete (Name);
         }
         
       if ( Time [Bar96] > SetBar && ObjectGet (Name, OBJPROP_ARROWCODE ) == 241 )
         {
         LevelBset = false ;
         Print ( DoubleToStr (LBuy, 5 )+ " expired - time" );
         ObjectDelete (Name);
         }
  
      }
 }

 
 /////////////////////////////LBuy Setup////////////////////////////////

void BuyLevelSet()
{
if (stoch< 25 && LevelBset== false )
{
   LBuy= Low [ iLowest ( NULL , 0 , MODE_LOW , 34 , 2 )];
   low_bar= iLowest ( NULL , 0 , MODE_LOW , 34 , 2 );

   if ( Bid >LBuy && Low [ 0 ]>LBuy && Low [ 1 ]>LBuy)
   {
       if ( Time [low_bar]> TimeCurrent ()- 10800 )
      {
         ObjectCreate ( "olive " + Time [low_bar], OBJ_ARROW , 0 , Time [low_bar],LBuy- Point * 20 );
         ObjectSet ( "olive " + Time [low_bar], OBJPROP_ARROWCODE , 241 );
         ObjectSet ( "olive " + Time [low_bar], OBJPROP_COLOR ,Olive);
        LevelBset= true ;
         Print ( "LevelBset on " + DoubleToStr (LBuy, 5 ));
      }
   }
}
}
///////////////////////////////LBuyCheckExp/////////////////////////////////
void CkExpLBuy ()
{

   if ( Close [ 2 ]<LBuy && Close [ 1 ]<LBuy)
      {
      LevelBset= false ;
       Print ( DoubleToStr (LBuy, 5 )+ " expired - close" );
      del241();
      }

 }
 
 
//////////////////////CHECK TRIGGER/////////////////////
void CheckTrigger()
{

   //Trigger1
   if (UseTrigger1)
   {
       if   ( Low [ 2 ]>LBuy && Low [ 1 ]<LBuy && Close [ 1 ]>LBuy)
         {
            TriggerBuy1= true ;
             Print ( "Tbuy1 ON" );
            del241();  
         }
       else
         TriggerBuy1= false ;
   
       if   ( High [ 2 ]<LSell && High [ 1 ]>LSell &&   Close [ 1 ]<LSell)
         {
            TriggerSell1= true ;
             Print ( "TSeLL1 ON" );
            del242();
         }
       else
         TriggerSell1= false ;
   } 
   else 
   {
      TriggerBuy1= false ;  
      TriggerSell1= false ;  
   }
   //Trigger2 
   if (UseTrigger2)
   {  
       if   ( Low [ 3 ]>LBuy  && Low [ 2 ]<LBuy && Close [ 2 ]<LBuy && Close [ 1 ]>LBuy)
         {
            TriggerBuy2= true ;
             Print ( "Tbuy2 ON" );
            del241();
         }
       else
      TriggerBuy2= false ;  
   
       if   ( High [ 3 ]<LSell && High [ 2 ]>LSell && Close [ 2 ]>LSell && Close [ 1 ]<LSell)
         {
            TriggerSell2= true ;
             Print ( "TSeLL2 ON" );
            del242();
         }
       else
      TriggerSell2= false ;     
   }
   else 
   {
   TriggerBuy2= false ;  
   TriggerSell2= false ;  
   }
   
   CheckOpen();
}

//////////////////////////////////CheckOpen///////////////////////////////////

void CheckOpen()
{
if (TriggerBuy1) 
   {
      SL= Low [ 1 ]-AddToSL* Point ;
       if ( ( Ask -SL)/ Point <=MaxSL && ( Ask -SL)/ Point >=MinSL)
      {
         Print ( "Trigger1: SL" + DoubleToStr (SL, 0 )+ "under" + DoubleToStr (MaxSL, 0 )+ " pips" );
         OpenTrade( 1 , "Trigger1" );
      }
 
       if ( ( Ask -SL)/ Point <=MaxSL && ( Ask -SL)/ Point <MinSL)
         {
         SL= Ask -MinSL* Point ;
         Print ( "Trigger1: SL minimum " + DoubleToStr (MinSL, 0 )+   " pips, SL=" + DoubleToStr (SL, 5 ));
         OpenTrade( 1 , "Trigger1" );
         }
       if ( ( Ask -SL)/ Point >MaxSL)
      {
       
         Print ( "Trigger1: SL  not taken because difference is " , DoubleToStr (( Open [ 0 ]-SL)/ Point , 0 ));
         AlternativeEntryB= true ;
         AlternativeEntryBTime= Time [ 0 ];
       
      }
   }
   if (TriggerSell1) 
   {
      SL= High [ 1 ]+AddToSL* Point ;
      SL=SL+ MathAbs ( Ask - Bid );
       if ( (SL- Open [ 0 ])/ Point <=MaxSL && (SL- Open [ 0 ])/ Point >=MinSL)
      {
         Print ( "Trigger1: SL" + DoubleToStr (SL, 0 )+ "under" + DoubleToStr (MaxSL, 0 )+ "pips" );
         OpenTrade( 2 , "Trigger1" );
      }
       
       if ( (SL- Open [ 0 ])/ Point <=MaxSL && (SL- Open [ 0 ])/ Point <MinSL)
      {
         SL= Open [ 0 ]+MinSL* Point ;
         Print ( "Trigger1: SL minimum" + DoubleToStr (MinSL, 0 )+   "pips, SL=" + DoubleToStr (SL, 5 ));
         OpenTrade( 2 , "Trigger1" );
      }
       if ( (SL- Open [ 0 ])/ Point >MaxSL)
      {
         
         Print ( "Trigger1: SL  not taken because difference is " , DoubleToStr ((SL- Open [ 0 ])/ Point , 0 ));
         AlternativeEntryS= true ;
         AlternativeEntrySTime= Time [ 0 ];
  
      }
   }
   

   if (TriggerBuy2) 
   {
      SL= Low [ iLowest ( NULL , 0 , MODE_LOW , 3 , 1 )]-AddToSL* Point ;
       if ( ( Ask -SL)/ Point <=MaxSL && ( Ask -SL)/ Point >=MinSL)
      {
         Print ( "Trigger2: SL" + DoubleToStr (SL, 0 )+ "under" + DoubleToStr (MaxSL, 0 )+ "pips" );
         OpenTrade( 1 , "Trigger2" );
      }
 
       if ( ( Ask -SL)/ Point <=MaxSL && ( Ask -SL)/ Point <MinSL)
         {
         SL= Open [ 0 ]+ MathAbs ( Ask - Bid )-MinSL* Point ;
         Print ( "Trigger2: SL minimum " + DoubleToStr (MinSL, 0 )+ " pips, SL=" + DoubleToStr (SL, 5 ));
         OpenTrade( 1 , "Trigger2" );
         }
       if ( ( Ask -SL)/ Point >MaxSL)
      {
       
         Print ( "Trigger2: SL  not taken because difference is " , DoubleToStr (( Open [ 0 ]-SL)/ Point , 0 ));
         AlternativeEntryB= true ;
         AlternativeEntryBTime= Time [ 0 ];
       
      }
   }
   if (TriggerSell2) 
   {
      SL= High [ iHighest ( NULL , 0 , MODE_HIGH , 3 , 1 )]+AddToSL* Point ;
      SL=SL+ MathAbs ( Ask - Bid );
       if ( (SL- Open [ 0 ])/ Point <=MaxSL && (SL- Open [ 0 ])/ Point >=MinSL)
      {
         Print ( "Trigger2: SL" + DoubleToStr (SL, 0 )+ "under" + DoubleToStr (MaxSL, 0 )+ "pips" );
         OpenTrade( 2 , "Trigger2" );
      }
       
       if ( (SL- Open [ 0 ])/ Point <=MaxSL && (SL- Open [ 0 ])/ Point <MinSL)
      {
         SL= Open [ 0 ]+MinSL* Point ;
         Print ( "Trigger2: SL minimum" + DoubleToStr (MinSL, 0 )+   "pips, SL=" + DoubleToStr (SL, 5 ));
         OpenTrade( 2 , "Trigger2" );
      }
       if ( (SL- Open [ 0 ])/ Point >MaxSL)
      {
         
         Print ( "Trigger2: SL  not taken because difference is " , DoubleToStr ((SL- Open [ 0 ])/ Point , 0 ));
         AlternativeEntryS= true ;
         AlternativeEntrySTime= Time [ 0 ];
  
      }
   }
}

//////////////////////////////////////////Open Trade//////////////////////////////////////////////

void OpenTrade( int dir, string trigger)
{
ticketBuy= 0 ;
ticketSell= 0 ;
if ( OrdersTotal ()== 0 )
   {
   if (dir== 1 )
      {
       Print (trigger, " - Opening BUY" );
      TP= Ask +TakeProfit* Point ;
      ticketBuy= OrderSend ( Symbol (), OP_BUY ,lot, Ask ,Slippage,SL,TP,trigger,MagicNumber, 0 ,Blue);
      }  
   if (dir== 2 )
      {
       Print (trigger, " - Opening SELL" );
      TP= Bid -TakeProfit* Point ;
      ticketSell= OrderSend ( Symbol (), OP_SELL ,lot, Bid ,Slippage,SL,TP,trigger,MagicNumber, 0 ,Red);
      }   
   
   if (ticketBuy> 0 )
      {
       Print ( "Deleting - Buy Level" , DoubleToStr (LBuy, 5 ));
      LevelBset= false ;
      }  
   
   if (ticketSell> 0 )
      {
       Print ( "Deleting - Sell Level" , DoubleToStr (LSell, 5 ));
      LevelSset= false ;
      }
   }  
}

///////////////////////////CHECK ALTERNATIVE ENTRY////////////////////////////
void CheckAlternativeEntry()
{
   if (AlternativeEntryB)
   {
       if ( Time [ 0 ]-AlternativeEntryBTime>= Time [ 0 ]- Time [ 17 ]) 
      {
         AlternativeEntryB= false ;
         del241();
      }
   }
   if (AlternativeEntryS)
   {
       if ( Time [ 0 ]-AlternativeEntrySTime>= Time [ 0 ]- Time [ 17 ]) 
      {
         AlternativeEntryS= false ;
         del242();
      }   
      
   }
   
   if (AlternativeEntryB)
   {
       if (   ( Ask -SL) / Point <= 70 )
         {
           Print ( "Trigger: SL under 7 pips" );
          OpenTrade( 1 , "Trigger" ); 
          AlternativeEntryB= false ;
         }
   }
   
   if (AlternativeEntryS)
   {
         if (  (SL- Bid ) / Point <= 70 )
         {
           Print ( "Trigger: SL under 7 pips" );
           OpenTrade( 2 , "Trigger" );
           AlternativeEntryS= false ;
         }  
   }
       
}

////////////////////////////CHECK RECOVERY TRADE/////////////////////
void CheckRecoveryTrade()
{
     OrderSelect ( OrdersHistoryTotal ()- 1 , SELECT_BY_POS , MODE_HISTORY );
     double Loss= MathAbs ( OrderOpenPrice ()- OrderClosePrice ());
    
     if ( OrderStopLoss ()== OrderClosePrice ())
    {
       if ( OrderCloseTime ()< Time [ 0 ] && OrderCloseTime ()>= Time [ 1 ])
      {
         if ( OrderType ()== OP_BUY )
         {
             if ( Close [ 1 ]> OrderStopLoss ()) 
             {
               SL= Low [ 1 ]-AddToSL* Point ;
               if (( Ask -SL)/ Point <= 100 )
                  {
                   Print ( "Recovery BUY" );
                  TP= Ask +Loss;
                   OrderSend ( Symbol (), OP_BUY ,lot, Ask ,Slippage,SL,TP, "recovery" ,MagicNumber, 0 ,Olive);
                  }
                  
             }
         }
         if ( OrderType ()== OP_SELL )
         {
             if ( Close [ 1 ]< OrderStopLoss ()) 
             {
               SL= High [ 1 ]+AddToSL* Point ;
               SL=SL+ MathAbs ( Ask - Bid );
               if ( (SL- Open [ 0 ])/ Point <= 100 )                            
                  {
                   Print ( "Recovery SELL" );
                  TP= Bid -Loss;
                   OrderSend ( Symbol (), OP_SELL ,lot, Bid ,Slippage,SL,TP, "recovery" ,MagicNumber, 0 ,Pink);
                  }
             }
         }
      }

    }
}