//+——————————————————————+

//| Oved EA                                                          |

                                                  |                                                             |

//+——————————————————————+ 

#include <stdlib.mqh>

#property link        “http://forexrobotprogramming.co.il/”

#property description “Eitan Zangi MT4 EA Developer”

#property description “[email protected]  050-529-4967”

#property description ”  “

#property description 

#property strict

//+——————————————————————+

//| Parameters                                                       |  

//+——————————————————————+

string   Ver = “Oved EA Ver. 1.09”;

 

extern string a01 = “——————— General Parameters ———————-“;//————————————————— 

 

extern double pBasicLot                =   0.1;    // Basic Lot 

extern int    pMN                      =   801;    // Magic Number

 

extern string a02 = “——————— Take Profit —————————–“;//————————————————— 

 

extern double pInit_TP                 =    30;    // Init Take Profit

extern double pGroup_TP                =    10;    // Group Profit G (Pips)

 

extern string a03 = “——————— Factors Z & V —————————“;//————————————————— 

 

extern double pFactor_Z                =     4;    // Factor Z 

extern double pFactor_V                =     2;    // Factor V

 

extern string a05 = “——————— Trigger & Pullback ——————————–“;//————————————————— 

 

extern bool   pUseTrigger_a_PB         = false;    // Use Trigger & Pullback 

extern double pTrigger                 =   100;    // Trigger

extern double pPullback                =    10;    // Pullback

 

extern string a06 = “——————— Loop System —————————–“;//————————————————— 

 

extern bool   pUseLoopSystem           = false;    // Use Loop System

extern int    pLoop_1_Times            =     3;    // Loop 1 Times

extern int    pLoop_2_Times            =     2;    // Loop 2 Times

 

extern string a99 = “—————————————————————“;//—————————————————

 

int      Slippage  = 30;

int      B_Type    = 0;

int      S_Type    = 1;

int      N_Type    = 9;

 

int      Status_Init  = 1;

int      Status_2B    = 2;

int      Status_2S    = 3;

int      Status_BBS   = 4;

int      Status_SSB   = 5;

int      Status_4_Ord = 6;

 

int      Trigger_1    = 1;

int      Trigger_2    = 2;

int      Null         = 9;

 

int      LoopStep_1   = 1;

int      LoopStep_2   = 2;

 

int      Dir_Up       = 1;

int      Dir_Dn       = 2;

 

int      Ticket; 

int      OrdersCount;

int      LastErr;

int      P_Status;

int      Y_Trigger;

int      CurrLoopStep;

int      WR = 60;          // Window move to the right

int      Loop_1_Count;

int      Loop_2_Count;

int      PrevLastType;

 

datetime TimeBar_0;

datetime TimeCycleStart; 

 

double   SL;

double   TP;

double   MyPoint;

double   Spread;

double   Orders_PL; 

double   Pips;

double   B1_EP;

double   B2_EP;

double   S1_EP;

double   S2_EP;

double   Lot;

double   B_TP;

double   S_TP;

double   B_ZeroPrice;

double   S_ZeroPrice;

double   B_Group_TP;

double   S_Group_TP;

double   B_Lots;

double   S_Lots;

double   TotalPips;

double   PipValue;

double   TimeLastCycle;

double   Up_PL;

double   Up_Pips;

double   Up_B_Lot;

double   Up_S_Lot;

double   Dn_PL;

double   Dn_Pips;

double   Dn_B_Lot;

double   Dn_S_Lot;

 

bool     B_Trigger;

bool     S_Trigger;

bool     Status;

bool     ZeroPrice_OK;

bool     Open_2_Buy;

bool     Open_2_Sell;

bool     Y_Mode_On;

 

string   Str_TF;

string   Symbol_6;

string   MsgBuffer;

string   B_Comment; 

string   S_Comment; 

 

string   StrStep;

string   StepInit = “Init”; 

string   Step_Z   = “Step Z”;

string   Step_V   = “Step V”; 

string   Step_VZ  = “Step (V+Z) / 2”; 

string   Step_Y1   = “Trigger”;

string   Step_Y2   = “Pullback”;

string   Step_BB   = “2 Buy”;

string   Step_SS   = “2 Sell”;

string   Step_BBS  = “2 Buy, 1 Sell”;

string   Step_SSB  = “2 Sell, 1 Buy”;

 

int      TB_Ticket[5];

double   TB_EP    [5];

 

int      TB_B_ZP_Ticket[4];

int      TB_B_ZP_Type  [4];

 

int      TB_S_ZP_Ticket[4];

int      TB_S_ZP_Type  [4];

 

double   TB_Y_Price_T1[3];  // 1=Buy, 2=Sell

double   TB_Y_Price_T2[3];  // 1=Buy, 2=Sell

double   TB_Y_HH      [3];  // 1=Buy, 2=Sell

double   TB_Y_LL      [3];  // 1=Buy, 2=Sell

 

int      TB_CA_Ticket[5];   // Close Agent

//+——————————————————————+

//|  On Tick                                                      *T |

//+——————————————————————+

void OnTick()

   CA_Close();

   if   ((B_TP + S_TP) > 0) Init_TP_Hit();

 

   OrderManagement();

   NewBar();

 

   Group_TP_Hit();

   if   (OrdersCount == 0) CycleInit();

   

   if   ((B1_EP + S1_EP + B2_EP + S2_EP) > 0) EP_Hit();

   

   if   (pUseTrigger_a_PB)

   if   (B_Trigger == false)

    if   (S_Trigger == false) Mode_Y();    

   

//————————————- Open   

 

   if   (B_Trigger) B_Open(); 

   if   (S_Trigger) S_Open(); 

   

   if   (Open_2_Buy)

        {

        B_Open();

        if   (OrdersCount < 4) B_Open();

        } 

        

   if   (Open_2_Sell)

        {

        S_Open();   

        if   (OrdersCount < 4) S_Open();

        }                

   

   if   (IsVisualMode() || IsTesting() == false) EA_Info(); // Visual Mode or Live Mode        

//+——————————————————————+

//|  New Bar (OnTick)                                             *N |  

//+——————————————————————+

void NewBar()

{

   if    (Time[0] == TimeBar_0) return;   

   TimeBar_0 = Time[0];

       

   MsgBuffer = “”;                                                  

   Msg();

 

//————————————-

 

   UpdGroup_TP_M();            

}

//+——————————————————————+

//|  Cycle Init (OnTick)                                             |

//+——————————————————————+

void CycleInit()

{

   B_Trigger = true;

   S_Trigger = true; 

 

   for   (int i = 1; i <= 4; i++)

         {

         TB_Ticket[i] = 0;

         TB_EP    [i] = 0;         

         }  

 

   MsgBuffer = “[New Cycle]”;

   Msg();

   

   P_Status = Status_Init;

   B_TP = Ask + (pInit_TP * MyPoint); 

   S_TP = Bid – (pInit_TP * MyPoint); 

   

   OrdersCount = 0; 

   B_Group_TP  = 0;

   S_Group_TP  = 0;

   

   ObjectDelete(“B_Group_TP”);

   ObjectDelete(“S_Group_TP”);       

   

   B1_EP = 0;

   S1_EP = 0; 

   B2_EP = 0;

   S2_EP = 0;

   

   Y_Trigger = Null;

   Y_Mode_On = false;

   

   StrStep = StepInit; 

   

//————————————- Loop system

 

   CurrLoopStep = LoopStep_1;

   Loop_1_Count = 0;

   Loop_2_Count = 0;  

   PrevLastType = N_Type; 

   

//————————————- Cycle time

 

   if   (TimeCycleStart > 0)

        {

        TimeLastCycle = (TimeCurrent() – TimeCycleStart) / 3600;     // Cycle time in hours 

        

        MsgBuffer = “[Time Last Cycle] ” + DoubleToStr(TimeLastCycle, 1) + ” hours”;    

        Msg();

        }

          

   TimeCycleStart = TimeCurrent();

   

//————————————-    

   

   for   (int i = 1; i <= 3; i++)         // reset 

         {

         TB_B_ZP_Ticket[i] = 0;

         TB_B_ZP_Type  [i] = N_Type;

 

         TB_S_ZP_Ticket[i] = 0;

         TB_S_ZP_Type  [i] = N_Type;

         } 

         

   for   (int i = 1; i <= 2; i++)         // reset 

         {         

         TB_Y_Price_T1[i] = 0;

         TB_Y_Price_T2[i] = 0;

         TB_Y_HH      [i] = 0;

         TB_Y_LL      [i] = 0;

         }                 

//+——————————————————————+

//|  Group TP Hit (OnTick)                                           |

//+——————————————————————+

void Group_TP_Hit()

{

   if   (B_Group_TP > 0)

    if   (Bid >= B_Group_TP) 

         {

         MsgBuffer = “[Group Profit at Up Direction] Profit: ” + DoubleToStr(Up_PL, 2) + “$”;        

         Msg();

         

         Group_TP_Close(B_Type);

         }

         

//————————————-                        

         

   if   (S_Group_TP > 0)

    if   (Bid <= S_Group_TP) 

         {

         MsgBuffer = “[Group Profit at Down Direction] Profit: ” + DoubleToStr(Dn_PL, 2) + “$”;    

         Msg();               

              

         Group_TP_Close(S_Type);

         }

}

//+——————————————————————+

//|  Group TP Close (Group_TP_Hit)                                   |

//+——————————————————————+

void Group_TP_Close(int cTP_Type)

{

//————————————- 2 or 3 orders     

 

   if   (OrdersCount == 2 || OrdersCount == 3) 

        {

        Close_M();

        return;

        }

        

//===================================== Group close Up direction        

   

   if   (cTP_Type == B_Type)

        {

        CA_Insert(TB_B_ZP_Ticket[1]);

        CA_Insert(TB_B_ZP_Ticket[2]);

        CA_Insert(TB_B_ZP_Ticket[3]);

        

        CloseAndReset(); 

               

        if   (pUseLoopSystem) Up_LoopSystem();

        else

             {

             S_Trigger = true;            // Open Sell      

             P_Status  = Status_2S;       // The status is 2 Sell orders

             StrStep   = Step_SS;               

             }                            

        } 

        

//===================================== Group close Dn direction           

 

   if   (cTP_Type == S_Type)

        {

        CA_Insert(TB_S_ZP_Ticket[1]);

        CA_Insert(TB_S_ZP_Ticket[2]);

        CA_Insert(TB_S_ZP_Ticket[3]);

        

        CloseAndReset();  

              

        if   (pUseLoopSystem) Dn_LoopSystem(); 

        else

             {

             B_Trigger = true;            // Open Buy

             P_Status  = Status_2B;       // The status is 2 Buy orders

             StrStep   = Step_BB;               

             }                         

        } 

}

//+——————————————————————+

//|  Close & Reset (Group_TP_Close)                                  |

//+——————————————————————+

void CloseAndReset()                                        

{        

   CA_Close();

   Upd_TB_AfterClose();   

   

   ObjectDelete(“B_Group_TP”);    

   ObjectDelete(“S_Group_TP”); 

   

   B_Group_TP = 0;

   S_Group_TP = 0;

   

   Y_Trigger = Null;

   Y_Mode_On = false; 

   

   for   (int i = 1; i <= 3; i++)         // reset 

         {

         TB_B_ZP_Ticket[i] = 0;

         TB_B_ZP_Type  [i] = N_Type;

 

         TB_S_ZP_Ticket[i] = 0;

         TB_S_ZP_Type  [i] = N_Type;

         } 

         

   for   (int i = 1; i <= 2; i++)         // reset 

         {         

         TB_Y_Price_T1[i] = 0;

         TB_Y_Price_T2[i] = 0;

         TB_Y_HH      [i] = 0;

         TB_Y_LL      [i] = 0;

         }                                                                             

}

//+——————————————————————+

//|  Up Loop System (Group_TP_Close)                                 |

//+——————————————————————+

void Up_LoopSystem()                                     // TP is Up direction… Last order is Sell                    

{

//————————————- last order type Vs Prev order type

  

   if   (CurrLoopStep == LoopStep_1)                     // Curr loop step is 1

        {

        if   (PrevLastType == S_Type) Loop_1_Count++;    // The same last order type 

        else                          Loop_1_Count = 1;  // Different last order type… start from 1 

        } 

        

   if   (CurrLoopStep == LoopStep_2)                     // Curr loop step is 2

    if   (PrevLastType != S_Type) Loop_2_Count++;        // Different last order type… Add to counter

 

   PrevLastType = S_Type;                              

 

//————————————- Curr loop step is 1             

        

   if   (CurrLoopStep == LoopStep_1)      // Curr loop step is 1

        {

        if   (Loop_1_Count <= pLoop_1_Times)  // No Loop 1 limit 

             {

             S_Trigger = true;            // Open Sell        

             P_Status  = Status_2S;       // The status is 2 Sell orders

             StrStep   = Step_SS; 

             

             return;              

             }                        

               

        if   (Loop_1_Count > pLoop_1_Times) // Loop 1 limit… Indicate that direction now is Buy

             {

             CurrLoopStep = LoopStep_2;   // Change to loop step 2

             Loop_2_Count = 1;  

                             

             Open_2_Buy = true;

             P_Status   = Status_BBS;     // The status is 2 Buy & 1 Sell

             StrStep    = Step_BBS;               

             

             return;

             }

        }

             

//————————————- Curr loop step is 2 

 

   if   (CurrLoopStep == LoopStep_2)      // Curr loop step is 2

        {

        if   (Loop_2_Count <= pLoop_2_Times)  // No Loop 2 limit

             {

             Open_2_Buy = true;           // Keep on opening 2 Buy

             P_Status   = Status_BBS;     // The status is 2 Buy & 1 Sell

             StrStep    = Step_BBS;    

             

             return;

             }                                  

 

     if   (Loop_2_Count > pLoop_2_Times)    // Loop 2 limit… Direction changed to Sell 

          {    

          CurrLoopStep = LoopStep_1;      // Change to loop step 1

          Loop_1_Count = 1;              

                  

          S_Trigger  = true;              // Open Sell       

          P_Status   = Status_2S;         // The status is 2 Sell orders

          StrStep    = Step_SS;               

          }

     }                             

}

//+——————————————————————+

//|  Dn Loop System (Group_TP_Close)                                 |

//+——————————————————————+

void Dn_LoopSystem()                                     // TP is Dn direction… Last order is Buy       

//————————————- last order type Vs Prev order type

  

   if   (CurrLoopStep == LoopStep_1)                     // Curr loop step is 1

        {

        if   (PrevLastType == B_Type) Loop_1_Count++;    // The same last order type 

        else                          Loop_1_Count = 1;  // Different last order type… start from 1 

        } 

        

   if   (CurrLoopStep == LoopStep_2)                     // Curr loop step is 2

    if   (PrevLastType != B_Type) Loop_2_Count++;        // Different last order type… Add to counter

 

   PrevLastType = B_Type;  

    

//————————————- Curr loop step is 1             

        

   if   (CurrLoopStep == LoopStep_1)      // Curr loop step is 1

        {

        if   (Loop_1_Count <= pLoop_1_Times)      // No Loop 1 limit 

             {

             B_Trigger = true;            // Open Buy

             P_Status  = Status_2B;       // The status is 2 Buy orders

             StrStep   = Step_BB;  

             

             return;            

             }                        

               

        if   (Loop_1_Count > pLoop_1_Times) // Loop 1 limit… Indicate that direction now is Sell

             {

             CurrLoopStep = LoopStep_2;   // Change to loop step 2

             Loop_2_Count = 1;

                

             Open_2_Sell = true;

             P_Status    = Status_SSB;    // The status is 2 Sell & 1 Buy

             StrStep     = Step_SSB;              

             

             return;

             }

        }

             

//————————————- Curr loop step is 2 

 

   if   (CurrLoopStep == LoopStep_2)      // Curr loop step is 2

        {

        if   (Loop_2_Count <= pLoop_2_Times)  // No Loop 2 limit

             {

             Open_2_Sell = true;

             P_Status    = Status_SSB;    // The status is 2 Sell & 1 Buy

             StrStep     = Step_SSB;     

             

             return;

             }                                  

 

     if   (Loop_2_Count > pLoop_2_Times)    // Loop 2 limit… Direction changed to Sell 

          {    

          CurrLoopStep = LoopStep_1;      // Change to loop step 1

          Loop_1_Count = 1;              

                  

          B_Trigger = true;               // Open Buy

          P_Status  = Status_2B;          // The status is 2 Buy orders

          StrStep   = Step_BB;            

          }

     }                             

}

//+——————————————————————+

//|  Update TB After Close (CloseAndReset)                           |

//+——————————————————————+

void Upd_TB_AfterClose()

{

   for   (int i = 1; i <= 4; i++)         // reset TP

         {

         TB_Ticket[i] = 0;

         TB_EP    [i] = 0;         

         } 

         

//————————————- Load last order (If exist) to TB

 

   for   (int i = 0; i < OrdersTotal(); i++) 

         {

         Status = (OrderSelect(i, SELECT_BY_POS, MODE_TRADES));

         if    (OrderSymbol() == Symbol() && OrderMagicNumber() == pMN)   

               {

               Ticket = OrderTicket();

               Upd_TB();                                                                                                  

               }                                                                                                                                   

         }         

}

//+——————————————————————+

//|  EP Hit (OnTick)                                                 |

//+——————————————————————+

void EP_Hit()

{

   if   (B1_EP > 0)

    if   (Ask > B1_EP)

         {      

         B_Trigger = True;

         B1_EP     = 0;

         

         StrStep = Step_Z;

         if   (CurrLoopStep == LoopStep_2) StrStep = Step_VZ;      // Curr loop step is 2          

         

         return;                 // To prevent 2 triggers on the same tick… only one order will open

         }

         

   if   (B2_EP > 0)

    if   (Ask > B2_EP)

         {         

         B_Trigger = True;

         B2_EP     = 0;

         

         StrStep = Step_V;                 

         }         

         

//————————————-         

         

   if   (S1_EP > 0)

    if   (Bid < S1_EP)

         {

         S_Trigger = True;        

         S1_EP     = 0;

       

         StrStep   = Step_Z;

         if   (CurrLoopStep == LoopStep_2) StrStep = Step_VZ;      // Curr loop step is 2         

 

         return;                 // To prevent 2 triggers on the same tick… only one order will open         

         } 

         

   if   (S2_EP > 0)

    if   (Bid < S2_EP)

         {          

         S_Trigger = True;       

         S2_EP     = 0; 

 

         StrStep   = Step_V;                          

         }                  

}

//+——————————————————————+

//|  Buy Open (OnTick)                                            *B |   

//+——————————————————————+

void B_Open()

{

   Ticket = OrderSend(Symbol(), B_Type, Lot, Ask, Slippage, 0, 0, B_Comment, pMN, 0, LimeGreen);  

   if    (Ticket > 0)                                                 

         {

         B_Trigger = false;

         AfterOpen_M(B_Type);                                   

         }

   else                                                              

         {                                                              

         int cLastErr = GetLastError();                                                    

         Print(“*** Error while opening Buy: “, ErrorDescription(cLastErr), ” ***”);   

         RefreshRates();                                                              

         } 

}

//+——————————————————————+

//|  Sell Open (OnTick)                                              |   

//+——————————————————————+

void S_Open()

{

   Ticket = OrderSend(Symbol(), S_Type, Lot, Bid, Slippage, 0, 0, S_Comment, pMN, 0, Red);  

   if    (Ticket > 0)                                                 

         {

         S_Trigger = false; 

         AfterOpen_M(S_Type);                                                              

         }

   else                                                                                                                                 

         {    

         int cLastErr = GetLastError();                                          

         Print(“*** Error while opening Sell: “, ErrorDescription(cLastErr), ” ***”);            

         RefreshRates();                                          

         }                      

//+——————————————————————+

//|  After Open Main (B_Open / S_Open)                               |

//+——————————————————————+

void AfterOpen_M(int cType)

{

   Upd_TB();

   

   if   (P_Status == Status_Init) return;

   

   RecountOrders();

   

//————————————- Loop step 2 & 3 Orders  

   

   if   (CurrLoopStep == LoopStep_2)               // Loop step 2 

    if  (OrdersCount == 3)  

        {

        Open_2_Buy  = false;

        Open_2_Sell = false;

          

        Set_L_Forth_EP();        

        Get_Group_TP();

        return;

        }      

   

//————————————- Y Mode   

   

   if   (Y_Mode_On)

        {

        if   (OrdersCount == 4) Get_Y_Group_TP();

        return;

        }

        

//————————————-

   

   if  (OrdersCount == 2) SetNext_EPs(); 

   

   Get_Group_TP();       

}

//+——————————————————————+

//|  Update TB (AfterOpen_M)                                         |

//+——————————————————————+

void Upd_TB()

{

   Status = OrderSelect(Ticket, SELECT_BY_TICKET);

 

   if   (OrderType() == B_Type)

        {

        if   (TB_Ticket[1] == 0) 

             {

             TB_Ticket[1] = Ticket; 

             TB_EP    [1] = OrderOpenPrice();

             } 

        else

             {

             TB_Ticket[3] = Ticket; 

             TB_EP    [3] = OrderOpenPrice();

             }                             

        }  

        

   if   (OrderType() == S_Type)

        {

        if   (TB_Ticket[2] == 0) 

             {

             TB_Ticket[2] = Ticket; 

             TB_EP    [2] = OrderOpenPrice();

             } 

        else

             {

             TB_Ticket[4] = Ticket; 

             TB_EP    [4] = OrderOpenPrice();

             }                             

        }     

//+——————————————————————+

//|  Get Group TP (AfterOpen_M)                                      |

//+——————————————————————+

void Get_Group_TP()

{

   Get_ZP();

   

//————————————- 4 Orders 2xB & 2xS   

   

   if   (P_Status == Status_4_Ord) 

        {

        if   (S_Group_TP > 0)                                     // S_Group_TP exist, set B_Group_TP 

             {

             B_Group_TP = B_ZeroPrice + (pGroup_TP * MyPoint);

             UpdGroup_TP_M();              

             

             B_DrawGroup_TP();             

             S_DrawGroup_TP();                                    // To change color from blue to green            

             }

             

        if   (B_Group_TP > 0)                                     // B_Group_TP exist, set S_Group_TP 

             {

             S_Group_TP = S_ZeroPrice – (pGroup_TP * MyPoint);

             UpdGroup_TP_M();             

             

             B_DrawGroup_TP();                                    // To change color from blue to green             

             S_DrawGroup_TP();

             }

             

        return;                               

        }

        

//————————————-        

 

   if   (B_Lots > S_Lots) 

        {

        B_Group_TP = B_ZeroPrice + (pGroup_TP * MyPoint);

        B_DrawGroup_TP();

        }

        

   if   (S_Lots > B_Lots) 

        {

        S_Group_TP = S_ZeroPrice – (pGroup_TP * MyPoint);

        S_DrawGroup_TP();       

        }                                    

//+——————————————————————+

//|  Get Zero Price (AfterOpen)                                      |

//+——————————————————————+

void Get_ZP()

{

   double cAve = 0;

   int    cI   = 0;

  

//————————————- 2 Orders BB    

 

   if   (P_Status == Status_2B) 

        {

        B_ZeroPrice = (TB_EP[1] + TB_EP[3]) / 2;

        

        TB_B_ZP_Ticket[1] = TB_Ticket[1];

        TB_B_ZP_Ticket[2] = TB_Ticket[3];

        TB_B_ZP_Ticket[3] = 0;

        } 

        

//————————————- 2 Orders SS         

    

   if   (P_Status == Status_2S) 

        {

        S_ZeroPrice = (TB_EP[2] + TB_EP[4]) / 2;

        

        TB_S_ZP_Ticket[1] = TB_Ticket[2];

        TB_S_ZP_Ticket[2] = TB_Ticket[4];

        TB_S_ZP_Ticket[3] = 0;

        }          

   

//————————————- Orders BBS TP is up  

   

   if   (P_Status == Status_BBS) 

        {

        if   (TB_Ticket[2] > 0) cI = 2;            // Sell Ticket

        else                    cI = 4;            // Sell Ticket        

 

        cAve = (TB_EP[1] + TB_EP[3]) / 2; 

        B_ZeroPrice = cAve + (cAve – TB_EP[cI]); 

        

        TB_B_ZP_Ticket[1] = TB_Ticket[1];

        TB_B_ZP_Ticket[2] = TB_Ticket[3];

        TB_B_ZP_Ticket[3] = TB_Ticket[cI];                     

        }

        

//————————————- Orders SSB TP is dn       

        

   if   (P_Status == Status_SSB) 

        {

        if   (TB_Ticket[1] > 0) cI = 1;            // Buy Ticket

        else                    cI = 3;            // Buy Ticket       

        

        cAve = (TB_EP[2] + TB_EP[4]) / 2; 

        S_ZeroPrice = cAve – (TB_EP[cI] – cAve);  

        

        TB_S_ZP_Ticket[1] = TB_Ticket[2];

        TB_S_ZP_Ticket[2] = TB_Ticket[4];

        TB_S_ZP_Ticket[3] = TB_Ticket[cI];             

        } 

        

//————————————- 4 Orders 2xB & 2xS   

   

   if   (P_Status == Status_4_Ord) 

        {

        if   (S_Group_TP > 0)                         // S_Group_TP exist, set B_Group_TP 

             {

             if   (TB_EP[2] > TB_EP[4]) cI = 2;       // Sell Ticket  

             else                       cI = 4;       // Sell Ticket             

        

             cAve = (TB_EP[1] + TB_EP[3]) / 2; 

             B_ZeroPrice = cAve + (cAve – TB_EP[cI]); 

             

             TB_B_ZP_Ticket[1] = TB_Ticket[1];

             TB_B_ZP_Ticket[2] = TB_Ticket[3];

             TB_B_ZP_Ticket[3] = TB_Ticket[cI];                

             }

             

        if   (B_Group_TP > 0)                         // B_Group_TP exist, set S_Group_TP 

             {

             if   (TB_EP[1] < TB_EP[3]) cI = 1;       // Buy Ticket  

             else                       cI = 3;       // Buy Ticket         

        

             cAve = (TB_EP[2] + TB_EP[4]) / 2; 

             S_ZeroPrice = cAve – (TB_EP[cI] – cAve);                              

             

             TB_S_ZP_Ticket[1] = TB_Ticket[2];

             TB_S_ZP_Ticket[2] = TB_Ticket[4];

             TB_S_ZP_Ticket[3] = TB_Ticket[cI];              

             }                              

        }                                                                                                                                    

}  

//+——————————————————————+

//|  Get Y Group TP (AfterOpen_M)                                      |

//+——————————————————————+

void Get_Y_Group_TP()

{

   double cAve = 0;

   int    cI   = 0;          

       

//————————————- TP Up Direction  

   

   if   (TB_EP[2] < TB_EP[4]) cI = 2;       // Sell Ticket, Find Sell order with lowest EP… Hi Loss  

   else                       cI = 4;       // Sell Ticket, Find Sell order with lowest EP… Hi Loss            

        

   cAve = (TB_EP[1] + TB_EP[3]) / 2; 

   B_ZeroPrice = cAve + (cAve – TB_EP[cI]); 

             

   B_Group_TP = B_ZeroPrice + (pGroup_TP * MyPoint);

   B_DrawGroup_TP();              

            

   TB_B_ZP_Ticket[1] = TB_Ticket[1];

   TB_B_ZP_Ticket[2] = TB_Ticket[3];

   TB_B_ZP_Ticket[3] = TB_Ticket[cI];

   

//————————————- TP Dn Direction    

   

   if   (TB_EP[1] > TB_EP[3]) cI = 1;       // Buy Ticket, Find Buy order with highest EP… Hi Loss  

   else                       cI = 3;       // Buy Ticket, Find Buy order with highest EP… Hi Loss  

        

   cAve = (TB_EP[2] + TB_EP[4]) / 2; 

   S_ZeroPrice = cAve – (TB_EP[cI] – cAve); 

   

   S_Group_TP = S_ZeroPrice – (pGroup_TP * MyPoint);

   S_DrawGroup_TP();   

                                          

   TB_S_ZP_Ticket[1] = TB_Ticket[2];

   TB_S_ZP_Ticket[2] = TB_Ticket[4];

   TB_S_ZP_Ticket[3] = TB_Ticket[cI];                                                                                                                                         

}     

//+——————————————————————+

//|  Set Next EPs (AfterOpen_M)                                      |

//+——————————————————————+

void SetNext_EPs()

{

   double cPips;

   double cB_Lowest;

   double cS_Highest;   

 

   if   (P_Status == Status_2B)

        {

        cB_Lowest = MathMin(TB_EP[1], TB_EP[3]); 

        

        if   (pFactor_Z > 0)

             {       

             cPips = MathAbs(TotalPips / pFactor_Z);

             S1_EP = cB_Lowest – (cPips * MyPoint); 

             } 

        

        if   (pFactor_V > 0)

             {         

             cPips = MathAbs(TotalPips / pFactor_V);

             S2_EP = cB_Lowest – (cPips * MyPoint);

             }  

        

//———————————– calculate B Y Price

 

        if   (pUseTrigger_a_PB)

         if   (pTrigger > 0 && pPullback > 0)         

              {

              cPips = MathAbs(TB_EP[1] – TB_EP[3]) / MyPoint;

              cPips = (pTrigger – cPips) / 2;        

              TB_Y_Price_T1[2] = cB_Lowest – (cPips        * MyPoint);  // Trigger for Sell orders… [2]

              TB_Y_Price_T2[2] = cB_Lowest + (pPullback * MyPoint);  // Trigger for Sell orders… [2] 

              }                        

        }       

        

//=====================================        

        

   if   (P_Status == Status_2S)

        {

        cS_Highest = MathMax(TB_EP[2], TB_EP[4]);

        

        if   (pFactor_Z > 0)

             {         

             cPips = MathAbs(TotalPips / pFactor_Z);

             B1_EP = cS_Highest + (cPips * MyPoint);

             }

 

        if   (pFactor_V > 0)

             { 

             cPips = MathAbs(TotalPips / pFactor_V);

             B2_EP = cS_Highest + (cPips * MyPoint);

             } 

   

//———————————– calculate S Y Price

        

        if   (pUseTrigger_a_PB)        

         if   (pTrigger > 0 && pPullback > 0)         

              {        

              cPips = MathAbs(TB_EP[2] – TB_EP[4]) / MyPoint;

              cPips = (pTrigger – cPips) / 2;        

              TB_Y_Price_T1[1] = cS_Highest + (cPips        * MyPoint); // Trigger for Buy orders… [1] 

              TB_Y_Price_T2[1] = cS_Highest – (pPullback * MyPoint); // Trigger for Buy orders… [1]         

              }                         

        }                                       

}

//+——————————————————————+

//|  Set Loop Forth EP (AfterOpen_M)                                 |

//+——————————————————————+

void Set_L_Forth_EP()

{

   int    cI;

   double cPips;

   double cFactor = (pFactor_Z + pFactor_V) / 2; 

   

   B2_EP = 0;

   S2_EP = 0;   

 

   if   (B_Lots > S_Lots)                                            // Two Buy orders with the same EP

        {

        if   (TB_Ticket[2] > 0) cI = 2;                              // Get the cI of Sell order

        else                    cI = 4;                              // Get the cI of Sell order         

 

        cPips = MathAbs(TB_EP[1] – TB_EP[cI]) / MyPoint;      

        cPips = (cPips / cFactor);

        S1_EP = TB_EP[1] – (cPips * MyPoint);                        // EP for forth order Sell 

        

//———————————– calculate Y Price for forth order Sell

 

        if   (pUseTrigger_a_PB)

         if   (pTrigger > 0 && pPullback > 0)         

              {     

              TB_Y_Price_T1[2] = TB_EP[1] – (pTrigger * MyPoint); // Trigger for Sell order… [2]

              TB_Y_Price_T2[2] = TB_EP[1] + (pPullback * MyPoint); // Trigger for Sell order… [2] 

              }                        

        }

        

//===================================== 

 

   if   (S_Lots > B_Lots)                                            // Two Sell orders with the same EP

        {

        if   (TB_Ticket[1] > 0) cI = 1;                              // Get the cI of Buy order

        else                    cI = 3;                              // Get the cI of Buy order         

 

        cPips = MathAbs(TB_EP[2] – TB_EP[cI]) / MyPoint;      

        cPips = (cPips / cFactor);

        B1_EP = TB_EP[2] + (cPips * MyPoint);                        // EP for forth order Buy 

        

//———————————– calculate Y Price for forth order Buy

 

        if   (pUseTrigger_a_PB)

         if   (pTrigger > 0 && pPullback > 0)         

              {     

              TB_Y_Price_T1[1] = TB_EP[2] + (pTrigger * MyPoint); // Trigger for Buy order… [1]

              TB_Y_Price_T2[1] = TB_EP[2] – (pPullback * MyPoint); // Trigger for buy order… [1] 

              }                        

        }                                                  

}

//+——————————————————————+

//|  B Draw Group TP (AfterOpen)                                     |

//+——————————————————————+

void B_DrawGroup_TP()

   color cLineColor; 

   

   if   (OrdersCount == 4) cLineColor = DodgerBlue;

   else                    cLineColor = LimeGreen; 

 

   ObjectDelete(“B_Group_TP”);      

 

   ObjectCreate(“B_Group_TP”, OBJ_HLINE, 0, Time[40], B_Group_TP);

   ObjectSet   (“B_Group_TP”, OBJPROP_STYLE, STYLE_SOLID);

   ObjectSet   (“B_Group_TP”, OBJPROP_COLOR, cLineColor); 

   ObjectSet   (“B_Group_TP”, OBJPROP_WIDTH, 2); 

   ObjectSet   (“B_Group_TP”, OBJPROP_RAY_RIGHT, false);                                        

//+——————————————————————+

//|  S Draw Group TP (AfterOpen)                                     |

//+——————————————————————+

void S_DrawGroup_TP()

{

   color cLineColor; 

   

   if   (OrdersCount == 4) cLineColor = DodgerBlue;

   else                    cLineColor = LimeGreen;  

 

   ObjectDelete(“S_Group_TP”);      

 

   ObjectCreate(“S_Group_TP”, OBJ_HLINE, 0, Time[40], S_Group_TP);

   ObjectSet   (“S_Group_TP”, OBJPROP_STYLE, STYLE_SOLID);

   ObjectSet   (“S_Group_TP”, OBJPROP_COLOR, cLineColor); 

   ObjectSet   (“S_Group_TP”, OBJPROP_WIDTH, 2); 

   ObjectSet   (“S_Group_TP”, OBJPROP_RAY_RIGHT, false);                                        

//+——————————————————————+

//|  Mode Y (OnTick)                                                 |

//+——————————————————————+

void Mode_Y()

{

   if   (OrdersCount == 1) return;

   if   (OrdersCount == 4) return;

   

//————————————- Buy

 

   if   (P_Status == Status_2S || P_Status == Status_SSB)     

        {

        if   (Y_Trigger == Null)

         if   (Bid >= TB_Y_Price_T1[1]) 

              {

              StrStep = Step_Y1;    

              Y_Trigger = Trigger_1;

              } 

        

        if   (Y_Trigger == Trigger_1)

         if   (Bid <= TB_Y_Price_T2[1]) 

              {

              StrStep    = Step_Y2;              

              Y_Trigger  = Trigger_2;

              TB_Y_LL[1] = Bid;

              }

              

        if   (Y_Trigger == Trigger_2)

             {

             if   (Bid < TB_Y_LL[1]) TB_Y_LL[1] = Bid;

             if   ((Bid – TB_Y_LL[1]) / MyPoint >= pPullback) 

                  {

                  MsgBuffer = “[Mode Y is On]”;

                  Msg();

                  

                  Y_Mode_On = true; 

                  

                  B1_EP = 0;

                  B2_EP = 0;                                              

 

                  if   (OrdersCount == 3) B_Trigger  = true;

                  else                    Open_2_Buy = true;

                  }                  

             }

        }   

 

//————————————- Sell

 

   if   (P_Status == Status_2B || P_Status == Status_BBS)   

        {

        if   (Y_Trigger == Null)

         if   (Bid <= TB_Y_Price_T1[2]) 

              {

              StrStep = Step_Y1;    

              Y_Trigger = Trigger_1;

              }          

        

        if   (Y_Trigger == Trigger_1)

         if   (Bid >= TB_Y_Price_T2[2]) 

              {

              StrStep    = Step_Y2;               

              Y_Trigger  = Trigger_2;  

              TB_Y_HH[2] = Bid;

              }               

              

        if   (Y_Trigger == Trigger_2)

             {

             if   (Bid > TB_Y_HH[2]) TB_Y_HH[2] = Bid;

 

             if   (((TB_Y_HH[2] – Bid) / MyPoint) >= pPullback) 

                  {

                  MsgBuffer = “[Mode Y is On]”;

                  Msg();                  

                  

                  Y_Mode_On = true;

                  

                  S1_EP = 0;

                  S2_EP = 0;                  

 

                  if   (OrdersCount == 3) S_Trigger   = true;

                  else                    Open_2_Sell = true;

                  }                  

             }

        }   

}

//+——————————————————————+

//|  Close Main                                                      |

//+——————————————————————+

void Close_M()

{

   for   (int i = OrdersTotal()-1; i >= 0 ;i–)

         {

         Status = (OrderSelect(i, SELECT_BY_POS, MODE_TRADES));

         if    (OrderSymbol() == Symbol() && OrderMagicNumber() == pMN)

                Status = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Black);                               

         }

         

   OrdersCount = 0;                

}

//+——————————————————————+

//|  Close Agent Insert ()                                           |   

//+——————————————————————+

void CA_Insert(int cTicket)

{

   for   (int i = 1; i <= 4; i++)                                        

          if   (TB_CA_Ticket[i] == 0)                                 

               {

               TB_CA_Ticket[i] = cTicket;                            

               break;                                               

               }                        

//+——————————————————————+

//|  Close Agent Close (OnTick)                                      |  

//+——————————————————————+

void CA_Close()

{

   for   (int i = 1; i <= 4; i++)                                       

    if   (TB_CA_Ticket[i] > 0)                                    

         {

         Status = OrderSelect(TB_CA_Ticket[i], SELECT_BY_TICKET);  

         if   (Status)                                               

              {              

              Status = OrderClose (TB_CA_Ticket[i], OrderLots(), OrderClosePrice(), Slippage, Black);  

             

              if   (Status) TB_CA_Ticket[i] = 0;                                           

              if   (!Status)                                        

                   {            

                   LastErr = GetLastError();                        

                   if   (LastErr == 4108) TB_CA_Ticket[i] = 0;  

                   }

              }

         }                                                    

}

//+——————————————————————+

//|  Update Group TP Main (NewBar)                                   |

//+——————————————————————+

void UpdGroup_TP_M()

{

   ZeroPrice_OK = false;

 

   if   (B_Group_TP > 0)

    for   (int i = 1; i <= 999999; i++) 

          {

          if   (ZeroPrice_OK) 

               {

               B_Group_TP = B_ZeroPrice + (pGroup_TP * MyPoint);

               B_DrawGroup_TP();               

               break;

               } 

          

          B_UpdGroup_TP();

          } 

          

//————————————-

 

   ZeroPrice_OK = false; 

   

   if   (S_Group_TP > 0)

    for   (int i = 1; i <= 999999; i++) 

          {

          if   (ZeroPrice_OK) 

               {

               S_Group_TP = S_ZeroPrice – (pGroup_TP * MyPoint);

               S_DrawGroup_TP();               

               break;

               } 

          

          S_UpdGroup_TP();

          }             

}

//+——————————————————————+

//|  B Update Group TP (UpdGroup_TP_M)                               |

//+——————————————————————+

void B_UpdGroup_TP()

{

   double cTotal_PL = 0;

   double cPips     = 0;

   double cExpProfit= 0;   

 

   for   (int i = 1; i <= 3; i++)

         {

         if   (TB_B_ZP_Ticket[i] == 0) continue;

          

         Status = OrderSelect(TB_B_ZP_Ticket[i], SELECT_BY_TICKET);

         

         cPips = (B_ZeroPrice – Bid) / MyPoint;           

         cExpProfit = (cPips * Lot * PipValue * 10);

         if   (OrderType() == S_Type) cExpProfit *= -1; 

         

         cTotal_PL += (OrderProfit() + OrderSwap() + OrderCommission() + cExpProfit);

         }

         

//————————————-

 

   if   (cTotal_PL < 0)

        {

        B_ZeroPrice += (1 * MyPoint);

        return;

        }

        

//————————————-        

   

   ZeroPrice_OK = true;

}

//+——————————————————————+

//|  S Update Group TP (UpdGroup_TP_M)                               |

//+——————————————————————+

void S_UpdGroup_TP()

{

   double cTotal_PL = 0;

   double cPips     = 0;

   double cExpProfit= 0;   

 

   for   (int i = 1; i <= 3; i++)

         {

         if   (TB_S_ZP_Ticket[i] == 0) continue;

          

         Status = OrderSelect(TB_S_ZP_Ticket[i], SELECT_BY_TICKET);

         

         cPips = (Bid – S_ZeroPrice) / MyPoint;           

         cExpProfit = (cPips * Lot * PipValue * 10);

         if   (OrderType() == B_Type) cExpProfit *= -1; 

         

         cTotal_PL += (OrderProfit() + OrderSwap() + OrderCommission() + cExpProfit);

         }

         

//————————————-

 

   if   (cTotal_PL < 0)

        {

        S_ZeroPrice -= (1 * MyPoint);

        return;

        }

        

//————————————-        

   

   ZeroPrice_OK = true;

}

//+——————————————————————+

//|  RecountOrders (AfterOpen)                                     |

//+——————————————————————+

void RecountOrders()

{    

   OrdersCount = 0;

   TotalPips   = 0; 

   B_Lots      = 0; 

   S_Lots      = 0; 

   

//————————————-         

 

   for   (int i = 0; i < OrdersTotal(); i++) 

         {

         Status = (OrderSelect(i, SELECT_BY_POS, MODE_TRADES));

         if    (OrderSymbol() == Symbol() && OrderMagicNumber() == pMN)   

               {

               OrdersCount++;

          

               CalPips();

               TotalPips += Pips;  

               

               if   (OrderType() == B_Type) B_Lots += OrderLots();

               if   (OrderType() == S_Type) S_Lots += OrderLots();                                                                                                                                

               }                                                                                                                                   

         } 

         

//————————————-

    

   if   (OrdersCount == 3)

        {

        if   (B_Lots > S_Lots) P_Status = Status_BBS;

        else                   P_Status = Status_SSB;

        } 

        

   if   (OrdersCount == 4)

        {

        Open_2_Buy  = false;

        Open_2_Sell = false;

        

        P_Status = Status_4_Ord;        

        }                                                                              

}

//+——————————————————————+

//|  Init TP Hit (OnTick)                                            |     

//+——————————————————————+

void Init_TP_Hit()

{

   if   (B_TP > 0)

    if   (Bid >= B_TP)

         {

         MsgBuffer = “[Buy – Init Take Profit] Close Order #” + DoubleToStr(TB_Ticket[1], 0);                                                 

         Msg();

         

         CA_Insert(TB_Ticket[1]);

         CA_Close();

          

         TB_Ticket[1] = 0;        // TB_Ticket[1] is closed

         TB_EP    [1] = 0;        // TB_Ticket[1] is closed

        

         S_Trigger = true;        // Buy closed in TP, last order type is sell… Open second sell

         Loop_1_Count++;

         PrevLastType = S_Type;

 

         B_TP      = 0;

         S_TP      = 0;         

 

         P_Status  = Status_2S;

         StrStep   = Step_SS;         

         }

 

//————————————-  

       

   if   (S_TP > 0)

    if   (Ask <= S_TP)

         {

         MsgBuffer = “[Sell – Init Take Profit] Close Order #” + DoubleToStr(TB_Ticket[2], 0);                                                 

         Msg();         

          

         CA_Insert(TB_Ticket[2]);

         CA_Close();         

         

         TB_Ticket[2] = 0;        // TB_Ticket[1] is closed

         TB_EP    [2] = 0;        // TB_Ticket[1] is closed

        

         B_Trigger = true;        // Sell closed in TP, last order type is buy… Open second buy

         Loop_1_Count++;

         PrevLastType = B_Type;         

         

         B_TP      = 0;

         S_TP      = 0;         

 

         P_Status  = Status_2B;

         StrStep   = Step_BB;         

         }                                                                                                

//+——————————————————————+

//|  Order Managenent (Start)                                     *M |

//+——————————————————————+

void OrderManagement()

{    

   OrdersCount  = 0;

   Orders_PL    = 0;

   Pips         = 0;

   B_Lots       = 0; 

   S_Lots       = 0;

   TotalPips    = 0; 

   

   Up_PL        = 0;

   Up_Pips      = 0;

   Up_B_Lot     = 0;

   Up_S_Lot     = 0; 

   

   Dn_PL        = 0;

   Dn_Pips      = 0;

   Dn_B_Lot     = 0;

   Dn_S_Lot     = 0;          

 

   for   (int i = 0; i < OrdersTotal(); i++) 

         {

         Status = (OrderSelect(i, SELECT_BY_POS, MODE_TRADES));

         if    (OrderSymbol() == Symbol() && OrderMagicNumber() == pMN)   

               {

               OrdersCount++;

 

               Orders_PL += OrderProfit() + OrderCommission() + OrderSwap();  

                          

               CalPips();

               TotalPips += Pips;

               

               if   (OrderType() == B_Type) B_Lots += OrderLots();

               if   (OrderType() == S_Type) S_Lots += OrderLots();

               

               CollectData();                                                                                                                  

               }                                                                                                                                   

         }                                  

//+——————————————————————+

//|  Collect Data (OrderManagement)                                  |     

//+——————————————————————+

void CollectData()

{

   for   (int i = 1; i <= 3; i++)

         {

         if   (OrderTicket() == TB_B_ZP_Ticket[i])

              {

              Up_PL        += (OrderProfit() + OrderSwap() + OrderCommission());

              Up_Pips      += Pips;

              if   (OrderType() == B_Type) Up_B_Lot += OrderLots(); 

              else                         Up_S_Lot += OrderLots(); 

              }

              

         if   (OrderTicket() == TB_S_ZP_Ticket[i])

              {

              Dn_PL        += (OrderProfit() + OrderSwap() + OrderCommission());

              Dn_Pips      += Pips;

              if   (OrderType() == B_Type) Dn_B_Lot += OrderLots(); 

              else                         Dn_S_Lot += OrderLots(); 

              }                   

         }                                                                                      

}        

//+——————————————————————+

//|  Calculate Pips (OrderManagement)                             *P |     

//+——————————————————————+

void CalPips()

{       

   if   (OrderType() == B_Type)                                       

         Pips = (Bid – OrderOpenPrice()) / MyPoint;                      

    

   if   (OrderType() == S_Type)                                          

         Pips = (OrderOpenPrice() – Ask) / MyPoint;                                             

//+——————————————————————+

//|  Msg                                                             |  

//+——————————————————————+

void Msg()

ObjectCreate (“Msg”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Msg”, MsgBuffer, 14, “Arial”, DodgerBlue);

   ObjectSet    (“Msg”, OBJPROP_CORNER, CORNER_LEFT_LOWER);

ObjectSet    (“Msg”, OBJPROP_YDISTANCE, 5);

ObjectSet    (“Msg”, OBJPROP_XDISTANCE, 5);

 

if   (MsgBuffer != “”) Print(“Msg >>>>> “, MsgBuffer);

}

//+——————————————————————+

//|   EA Info                                                     *A |  

//+——————————————————————+

void  EA_Info()

{  

   string cStrBuffer = “”;

 

   ObjectCreate (“Obj_01”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_01”, Symbol_6, 13, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_01”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_01”, OBJPROP_YDISTANCE, 8);

ObjectSet    (“Obj_01”, OBJPROP_XDISTANCE, 12 + WR);

 

//————————— TF  

   ObjectCreate (“Obj_02”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_02”, Str_TF, 8, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_02”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_02”, OBJPROP_YDISTANCE, 12);

ObjectSet    (“Obj_02”, OBJPROP_XDISTANCE, 90 + WR);

//————————— Equity

 

   cStrBuffer = “Equity        ” + DoubleToStr(AccountEquity(), 2);              

ObjectCreate (“Obj_03”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_03”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_03”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_03”, OBJPROP_YDISTANCE, 30);

ObjectSet    (“Obj_03”, OBJPROP_XDISTANCE, 12 + WR);

//————————— Balance

   cStrBuffer = “Balance     ” + DoubleToStr(AccountBalance(), 2);               

ObjectCreate (“Obj_04”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_04”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_04”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_04”, OBJPROP_YDISTANCE, 45);

ObjectSet    (“Obj_04”, OBJPROP_XDISTANCE, 12 + WR); 

//————————— Spread

   Spread = (Ask – Bid) / MyPoint;                                          

   cStrBuffer = “Spread       ” + DoubleToStr(Spread, 1); 

   

  ObjectCreate (“Obj_05”, OBJ_LABEL, 0, 0, 0);                              

ObjectSetText(“Obj_05”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_05”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_05”, OBJPROP_YDISTANCE, 60);

ObjectSet    (“Obj_05”, OBJPROP_XDISTANCE, 12 + WR);

//————————— Step  

                                           

   cStrBuffer = “Step           ” + StrStep; 

   

  ObjectCreate (“Obj_15”, OBJ_LABEL, 0, 0, 0);                              

ObjectSetText(“Obj_15”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_15”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_15”, OBJPROP_YDISTANCE, 80);

ObjectSet    (“Obj_15”, OBJPROP_XDISTANCE, 12 + WR);

//————————— Orders

 

cStrBuffer = “Orders        ” + DoubleToStr(OrdersCount, 0);                   

ObjectCreate (“Obj_06”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_06”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_06”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_06”, OBJPROP_YDISTANCE, 95);

ObjectSet    (“Obj_06”, OBJPROP_XDISTANCE, 12 + WR);

//————————— Buy Lots

 

cStrBuffer = “Buy Lots     ” + DoubleToStr(B_Lots, 2);                   

ObjectCreate (“Obj_07”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_07”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_07”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_07”, OBJPROP_YDISTANCE, 115);

ObjectSet    (“Obj_07”, OBJPROP_XDISTANCE, 12 + WR); 

//————————— Sell Lots

 

cStrBuffer = “Sell Lots     ” + DoubleToStr(S_Lots, 2);                   

ObjectCreate (“Obj_10”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_10”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_10”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_10”, OBJPROP_YDISTANCE, 130);

ObjectSet    (“Obj_10”, OBJPROP_XDISTANCE, 12 + WR);

//————————— PL & Pips

 

   int    cPL_Dir = N_Type;

   double cMid    = 0;

   string cStrDir = “PL            “;

   double cPL     = 0;     

   double cPips   = 0;  

   double cB_Lot  = 0;  

   double cS_Lot  = 0; 

      

   if   (B_Lots > S_Lots) cPL_Dir = B_Type;

   if   (S_Lots > B_Lots) cPL_Dir = S_Type; 

   

   if   (OrdersCount == 4)  

        {    

        cMid = B_Group_TP – ((B_Group_TP – S_Group_TP) / 2);

        

        if   (Bid > cMid) cPL_Dir = B_Type; 

        else              cPL_Dir = S_Type;

        }

        

   if   (cPL_Dir == B_Type)

        {

        cStrDir = “PL Up        “;

        cPL     = Up_PL;

        cPips   = Up_Pips;

        cB_Lot  = Up_B_Lot;

        cS_Lot  = Up_S_Lot;

        } 

        

   if   (cPL_Dir == S_Type)

        {

        cStrDir = “PL Down     “;

        cPL     = Dn_PL;

        cPips   = Dn_Pips;

        cB_Lot  = Dn_B_Lot;

        cS_Lot  = Dn_S_Lot;

        }                 

                          

cStrBuffer = cStrDir + DoubleToStr(cPL, 2) + ” / ” + DoubleToStr(cPips, 1) + ” Pips”;                  

ObjectCreate (“Obj_16”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_16”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_16”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_16”, OBJPROP_YDISTANCE, 150);

ObjectSet    (“Obj_16”, OBJPROP_XDISTANCE, 12 + WR);

//————————— Lots

 

cStrBuffer = “Lots          Buy[” + DoubleToStr(cB_Lot, 2) + “] Sell[” + DoubleToStr(cS_Lot, 2) + “]”;                

ObjectCreate (“Obj_17”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_17”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_17”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_17”, OBJPROP_YDISTANCE, 165);

ObjectSet    (“Obj_17”, OBJPROP_XDISTANCE, 12 + WR);

 

//————————— Total Pips

 

cStrBuffer = “Total Pips”;

ObjectCreate (“Obj_11”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_11”, cStrBuffer, 10, “Arial”, RoyalBlue);

  ObjectSet    (“Obj_11”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_11”, OBJPROP_YDISTANCE, 185);

ObjectSet    (“Obj_11”, OBJPROP_XDISTANCE, 12 + WR);

   color cColorPips = LimeGreen;  

   if   (OrdersCount > 0) cColorPips = Red;             

cStrBuffer = DoubleToStr(TotalPips, 1);

ObjectCreate (“Obj_12”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_12”, cStrBuffer, 10, “Arial”, RoyalBlue);

  ObjectSet    (“Obj_12”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_12”, OBJPROP_YDISTANCE, 185);

ObjectSet    (“Obj_12”, OBJPROP_XDISTANCE, 82 + WR);

 

//————————— Time Last Cycle

 

cStrBuffer = “Last Cycle  ” + DoubleToStr(TimeLastCycle, 1) + ” hours”;                   

ObjectCreate (“Obj_14”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_14”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_14”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_14”, OBJPROP_YDISTANCE, 200);

ObjectSet    (“Obj_14”, OBJPROP_XDISTANCE, 12 + WR);

//————————— Loop System

 

   string cStrLastType;

   

   cStrBuffer = “Loop          “;

   

   if   (pUseLoopSystem)

    if   (P_Status == Status_Init) cStrBuffer = “Loop          “;

    else

         {

         if   (PrevLastType == B_Type) cStrLastType = ” (Buy)”;

         else                          cStrLastType = ” (Sell)”;         

 

         if   (CurrLoopStep == LoopStep_1) 

               cStrBuffer = “Loop          ” 

                      + DoubleToStr(CurrLoopStep, 0) + ” / ” + DoubleToStr(Loop_1_Count, 0) + cStrLastType;   

                          

         if   (CurrLoopStep == LoopStep_2) 

               cStrBuffer = “Loop          ” 

                  + DoubleToStr(CurrLoopStep, 0) + ” / ” + DoubleToStr(Loop_2_Count, 0) + cStrLastType;

      }                                                            

                         

ObjectCreate (“Obj_13”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_13”, cStrBuffer, 10, “Arial”, RoyalBlue);

   ObjectSet    (“Obj_13”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_13”, OBJPROP_YDISTANCE, 220);

ObjectSet    (“Obj_13”, OBJPROP_XDISTANCE, 12 + WR);

 

//—————————

 

   cStrBuffer = DoubleToStr(Orders_PL, 2) + “$”;

   

   color cColor_PL = LimeGreen; 

if   (Orders_PL < 0) cColor_PL = Red;   

 

ObjectCreate (“Obj_08”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_08”, cStrBuffer, 16, “Arial”, cColor_PL);  

  ObjectSet    (“Obj_08”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_08”, OBJPROP_YDISTANCE, 260);

ObjectSet    (“Obj_08”, OBJPROP_XDISTANCE, 12 + WR); 

//—————————

 

   double cDD = (MathAbs(Orders_PL) * 100) / AccountBalance();

cStrBuffer = “DD ” + DoubleToStr(cDD, 1) + “%”;      

 

ObjectCreate (“Obj_18”, OBJ_LABEL, 0, 0, 0);

ObjectSetText(“Obj_18”, cStrBuffer, 10, “Arial”, RoyalBlue);  

  ObjectSet    (“Obj_18”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_18”, OBJPROP_YDISTANCE, 265);

ObjectSet    (“Obj_18”, OBJPROP_XDISTANCE, 130 + WR); 

//—————————

     

ObjectCreate (“Obj_09”, OBJ_LABEL, 0, 0, 0);                              

ObjectSetText(“Obj_09”, Ver, 8, “Arial”, RoyalBlue);

  ObjectSet    (“Obj_09”, OBJPROP_CORNER, 0);

ObjectSet    (“Obj_09”, OBJPROP_YDISTANCE, 285);

ObjectSet    (“Obj_09”, OBJPROP_XDISTANCE, 12 + WR);        

//+——————————————————————+

//|   Window (init)                                               *W |   

//+——————————————————————+

void  Window()

{

   ChartSetInteger(0, CHART_FOREGROUND,0, 0); 

 

   ObjectCreate    (0, “Win”, OBJ_RECTANGLE_LABEL, 0, 0, 0);  

   ObjectSetInteger(0, “Win”, OBJPROP_XDISTANCE, 5 + WR); 

   ObjectSetInteger(0, “Win”, OBJPROP_YDISTANCE, 3); 

   ObjectSetInteger(0, “Win”, OBJPROP_XSIZE, 220);      // Wideth

   ObjectSetInteger(0, “Win”, OBJPROP_YSIZE, 300);      // Length

   ObjectSetInteger(0, “Win”, OBJPROP_BGCOLOR, AliceBlue); 

   ObjectSetInteger(0, “Win”, OBJPROP_BORDER_TYPE, BORDER_RAISED); 

   ObjectSetInteger(0, “Win”, OBJPROP_CORNER, CORNER_LEFT_UPPER); 

}                          

//+——————————————————————+

//| Init                                                          *I |    

//+——————————————————————+

void init()

{

   string cCurrTime = TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); 

   Print(“********************** Oved EA Started at ” + cCurrTime + ” ************************”);  

   

   MyPoint  = MarketInfo(Symbol(), MODE_POINT) * 10; 

   Symbol_6 = StringSubstr(Symbol(), 0, 6);

   PipValue = MarketInfo(Symbol(),MODE_TICKVALUE);    

 

   TimeFrame();                            

   

   B_Comment = “Oved EA -B- ” + Symbol_6 + ” ” + Str_TF;                          

   S_Comment = “Oved EA -S- ” + Symbol_6 + ” ” + Str_TF; 

   

   Window();   

 

   TimeBar_0 = Time[0];                         // So it wont open in mid bar 

   Lot = pBasicLot;    

}         

//+——————————————————————+

//|  Time Frame                                                      |

//+——————————————————————+

void TimeFrame()

{

switch(Period()) 

      {

      case PERIOD_M1:  Str_TF = ” M1″;  break;   

      case PERIOD_M5:  Str_TF = ” M5″;  break;

      case PERIOD_M15: Str_TF = ” M15″; break;

      case PERIOD_M30: Str_TF = ” M30″; break;

      case PERIOD_H1:  Str_TF = ” H1″;  break;

      case PERIOD_H4:  Str_TF = ” H4″;  break;

      case PERIOD_D1:  Str_TF = ” D1″;  break;  

      case PERIOD_W1:  Str_TF = ” W1″;  break;        

      case PERIOD_MN1: Str_TF = ” MN”;  break;                                  

      }

}       

//+——————————————————————+

//|  Deinit                                                          |  

//+——————————————————————+

void deinit()

   for   (int i = 0; i < 10; i++)                                        

         { 

         ObjectDelete(“Obj_0” + IntegerToString(i, 1)); 

         ObjectDelete(“Obj_1” + IntegerToString(i, 1));                                                                           

         }

         

   ObjectDelete(“B_Group_TP”);  

   ObjectDelete(“S_Group_TP”);           

 

   ObjectDelete(“Msg”); 

   ObjectDelete(“Win”);                                                                                   

}             

//+——————————————————————+

//| End                                                           *E |

//+——————————————————————+ 



Scroll to Top