tracciando la H_line sul massimo più alto degli ultimi 36 massimi - pagina 3

 
cichichan:

qualche idea, cosa c'è di sbagliato... qualcuno?

Grazie

Una volta creato un oggetto . . .

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

. . . non puoi crearlo di nuovo, esiste già . . . invece controlla se esiste e se esiste non provare a crearlo di nuovo, semplicemente spostalo usando ObjectSet()

 

Ho usato un nome diverso per ogni candela in modo che non fosse un problema con l'oggetto.

L'ho riscritto in questo modo e ora funziona perfettamente:

imposta un livello di vendita, e se ottengo due chiusure sopra quel livello -> LevelSset=false -> inizia la ricerca del prossimo 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);
  }
 

Ciao, ho bisogno di aiuto.

non posso fare una condizione di scadenza temporale per il livello di prezzo. come ho detto prima, se il prezzo rimane sotto LSell o sopra LBuy per più di 96 candele, per respingere quel livello di prezzo.

Stavo cercando di usare if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset a false... ma sembra che non funzioni.... void CkExpLSell ()... sono sicuro che sto facendo qualcosa di sbagliato ma... non ho idea di cosa, quindi aiutatemi :)

//+------------------------------------------------------------------+
//|                                                      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;
   }  
}
 
bisogno di aiuto. grazie!
 
   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:

Ciao, ho bisogno di aiuto.

non posso fare una condizione di scadenza temporale per il livello di prezzo. come ho detto prima, se il prezzo rimane sotto LSell o sopra LBuy per più di 96 candele, per respingere quel livello di prezzo.

Stavo cercando di usare if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... ma sembra che non funzioni.... void CkExpLSell ()... sono sicuro che sto facendo qualcosa di sbagliato ma... non ho idea di cosa, quindi help pls :)

ObjectCreate("olive "+Time[0]

il nome della linea ti dice il momento in cui viene creata

ti ho già dato in questo topic come controllare usando il nome della linea il modo di controllare il tempo di scadenza

e non vedo che stai usando questo metodo!

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

Il tuo indicatore non può fare tradingfunctions !!!!!!!!........

Fai un EA se fai OrderSend

 
deVries:

il nome della linea ti dice il momento in cui è stata creata

vi ho già dato in questo topic come controllare usando il nome della linea il modo di controllare il tempo di scadenza

e non vedo che state usando questo metodo!


@ deVries ObjectGet(Name, OBJPROP_TIME1) è ancora meglio, nessun bisogno di codice inutile (StringSubstr() StrToTime())
 
qjol:
   int Bar96 = 96 * Period() * 60;
:
     if (Time[0] - Bar96 > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
Questo presuppone che non ci siano barre mancanti sul grafico, come M1 quando non ci sono tick in un minuto, o tutti i TF inferiori a quelli settimanali sul fine settimana. Non presumere, semplifica:
96 barre fa
// int Bar96 = 96 * Period() * 60;
:
     if (Time[96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
96 barre complete fa.
   int Bar96 = iBarShift(NULL,0, Time[0] - 96 * Period() * 60);
:
     if (Time[Bar96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
 
corretto, errore mio
 

Ciao ragazzi,

sul tester di strategia le cose sembrano ok. quindi ho messo l'ea su account demo di diverse piattaforme e ha funzionato (impostando i livelli di prezzo e facendo scambi come previsto) fino a quando non è apparso questo errore.

cambio il periodo di test nel tester di strategia e ho ricevuto lo stesso errore ... non importa se è un LevelBset o LevelSset, l'EA sta impostando il livello al prezzo corretto, quindi il livello del prezzo viene modificato a 0,0000.

non ho trovato l'errore fino ad ora, quindi per favore controlla il mio codice.

grazie per l'aiuto.

 //+------------------------------------------------------------------+
//|                                                      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);
                  }
             }
         }
      }

    }
}



Motivazione: