過去36回の最高値の上にH_線を引く。 - ページ 3

 
cichichan:

何が問題なのか、どなたか教えてください。

ありがとうございます

一度オブジェクトを作成したら、もう作成することはできません。

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

その代わりに、オブジェクトが存在するかどうかを確認 し、存在する場合は再度作成しようとせず、ObjectSet()を使用して移動させるだけでよいのです。

 

私はそれぞれのキャンドルに異なる名前を使いましたので、オブジェクトには問題ありませんでした。

このように書き直すと、完璧に動作するようになりました。

売りレベルを設定し、そのレベルを終値で2回超えると→LevelSset=false→次の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);
  }
 

こんにちは、少し助けてください。

ローソク足が96本以上LSell以下かLBuy以上の場合、その価格帯の取引を停止するように設定したのですが、その条件設定がうまくいきません。

ということで、if(Time[high_bar]<Time[96]) && LevelSset=true ... LevelSsetをfalseに設定... を使おうとしましたが、どうもうまくいかない。void CkExpLSell ()... 何か間違ったことをしていると思うのですが、、、見当もつかないので助けて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;
   }  
}
 
ありがとうございました。
 
   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:

こんにちは、少し助けてください。

ローソク足が96本以上LSell以下かLBuy以上の場合、その価格帯の取引を停止するように設定したのですが、その条件 設定がうまくいきません。

ということで、if(Time[high_bar]<Time[96]) && LevelSset=true... LevelSsetをfalseにセット...というのを試してみましたが、どうもうまくいかない。void CkExpLSell ()... 何か間違ったことをしているとは思うのですが・・・見当もつかないので助けてpls.)

ObjectCreate("olive "+Time[0]

行の名前は、それが作成された瞬間を教えてくれます。

このトピックで、行の名前を使って時間切れをチェック する方法をすでにお伝えしました。

その方法を使っているようには見えません。

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

あなたのインジケータはTradingfunctionsができません。

OrderSendを使うならEAを作れ。

 
deVries:

行の名前は、それが作成された瞬間を教えてくれます。

私はこのトピックで、行の名前を使って時間切れをチェックする方法をすでに教えました。

その方法を使っているようには見えませんね。


デブリース ObjectGet(Name, OBJPROP_TIME1) はもっと良い方法です。不要なコード (StringSubstr() StrToTime()) が不要になります。
 
qjol:
   int Bar96 = 96 * Period() * 60;
:
     if (Time[0] - Bar96 > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
これは、M1が1分間にティックがないときに持つような、チャート上に欠けたバーがないこと、または週明けにすべてのTFが週足未満であることを仮定しています。Don't Assume, simplify:
96小節前
// int Bar96 = 96 * Period() * 60;
:
     if (Time[96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
96本前の完全なバー
   int Bar96 = iBarShift(NULL,0, Time[0] - 96 * Period() * 60);
:
     if (Time[Bar96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
 
あやまりました
 

こんにちは、みんな、

ストラテジーテスターでは問題ないように見えます。次に、EAをさまざまなプラットフォームのデモアカウントに配置し、このエラーが表示されるまで機能しました(価格レベルを設定し、期待どおりに取引を行います)。

ストラテジーテスターでテスト期間を変更しましたが、同じエラーが発生しました...それがLevelBsetであるかLevelSsetであるかは関係ありません。EAが正しい価格でレベルを設定している場合、価格レベルは0.0000に変更されます。

今まで間違いを見つけられなかったので、コードを確認してください。

ご協力ありがとうございました。

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

    }
}