Author: Copyright 2019, Vagner Prado (OUROE v1.0)
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
0 Views
0 Downloads
0 Favorites
OUROE v1.0
ÿþ//+------------------------------------------------------------------+

//|                                                        OUROE Scalper Martingale v1.0|

//|                                           vagner-dpf@hotmail.com|

//+------------------------------------------------------------------+

#include <stdlib.mqh>

#import "stdlib.ex4"

#property copyright "Copyright 2019, Vagner Prado (OUROE v1.0)"

#property description "Email: vagner-dpf@hotmail.com"

#property version   "1.00"

#property strict

#import

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

enum Sinais

  {

   Buy=0, // Buy

   Sell=1 // Sell

  };



//+------------------------------------------------------------------+

//| Parametros de Entrada                                            |

//+------------------------------------------------------------------+





input string     EA="=== CONFIG. OUROE v1.0  ===";

extern double    Lot=0.01;                         // Lot

extern           Sinais Signal=Buy;

extern int       MagicNumber=555555;                    // Magic Numero

extern bool      CorBars=True;                     // Key Color Candles



bool   Key_Banco_Dados=True;

double Banco_Lot=0;

double Banco_TakeProfit=0;



double PipStep=300;

int    Takeprofit=300;

int    Stoploss=0;

int    Porcentagem=-10;



double Buy_Line=0;

double Sell_Line=0;



double Price_Atual_Buy=0;

double Price_Atual_Sell=0;

double Price_Penultima_Buy=0;

double Price_Penultima_Sell=0;



string  Coment="";

datetime sendOnce;

int Cont_Ordem_Buy=0;

int Cont_Ordem_Sell=0;



bool Nivel_Buy_01 = False;

bool Nivel_Buy_02 = False;

bool Nivel_Buy_03 = False;



bool Nivel_Sell_01 = False;

bool Nivel_Sell_02 = False;

bool Nivel_Sell_03 = False;



double Dist_Buy_02 = 0;

double Dist_Buy_03 = 0;

double Dist_Buy_03_02 = 0;

double Dist_Buy_03_01 = 0;



double Dist_Sell_02 = 0;

double Dist_Sell_03 = 0;

double Dist_Sell_03_02 = 0;

double Dist_Sell_03_01 = 0;





double Buy_Stop_Line_Stop=0;

double Sell_Stop_Line_Stop=0;

double Buy_Take_Profit_Line=0;

double Sell_Take_Profit_Line=0;



double Take_Preco_Buy=0;

double Take_Preco_Sell=0;



int Resultado_Close_Buy=0;

int Resultado_Close_Sell=0;



double Calc_Rebaixamento = 0;                      // Controle de Rebaixamento

double Cont_Rebaixamento = 0;                      // Controle de Rebaixamento

double Saldo_Atual=0;                              // Variavel que armazena o saldo atual

double  Equity=0;

int g_color_1128=ForestGreen;                      // Cor do calculo do equilibrio

double ContLucro= 0;





string Status="ON";

long account=AccountNumber();



double Lot_Atual_Buy=0;

double Lot_Atual_Sell=0;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---



   Banco_Dados();



//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---



  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {



   if(MT4_ON_OFF()==false)

      return;





   Info();

   System_Calc();

   System_Close();

   LucroOrder();



// ---------------------------------------------------------------------------------------------------

// Buy System------------------------------------------------------------------------------------------

// ---------------------------------------------------------------------------------------------------

   if(Nivel_Buy_01==True && Signal==Buy && TotalOrdersCountBuy()==0)

     {



      Takeprofit=Banco_TakeProfit;

      Lot=Banco_Lot;



      Cont_Ordem_Buy=0;

      Buy_Line=0;

      Cont_Ordem_Buy=0;



      Cont_Ordem_Buy+=1;

      Coment="OUROE BUY "+Cont_Ordem_Buy;

      Buy_Order();



     }

   if(Nivel_Buy_02==True && Signal==Buy && Dist_Buy_02>Close[0] && Dist_Buy_02!=0)

     {



      Takeprofit=Banco_TakeProfit;



      if(Lot_Atual_Buy>Lot)

        {



         Lot=Lot_Atual_Buy+Lot_Atual_Buy;



           }else{



         Lot=Lot+(Lot*1);



        }



      if(TotalOrdersCountBuy()>0 && Cont_Ordem_Buy==0)

        {



         Cont_Ordem_Buy+=TotalOrdersCountBuy()+1;



           }else{



         Cont_Ordem_Buy+=1;



        }



      Coment="OUROE BUY "+Cont_Ordem_Buy;

      Buy_Order();



     }



   if(Nivel_Buy_03==True && Signal==Buy && Dist_Buy_03>Close[0] && Dist_Buy_03!=0)

     {



      if(Lot_Atual_Buy>Lot)

        {



         Lot=Lot_Atual_Buy+Lot_Atual_Buy;



           }else{



         Lot=Lot+(Lot*1);



        }



      if(TotalOrdersCountBuy()>0 && Cont_Ordem_Buy==0)

        {



         Cont_Ordem_Buy+=TotalOrdersCountBuy()+1;



           }else{



         Cont_Ordem_Buy+=1;



        }



      Coment="OUROE BUY "+Cont_Ordem_Buy;

      Buy_Order();



     }



// ---------------------------------------------------------------------------------------------------

// Sell System------------------------------------------------------------------------------------------

// ---------------------------------------------------------------------------------------------------

   if(Nivel_Sell_01==True && Signal==Sell && TotalOrdersCountSell()==0)

     {



      Takeprofit=Banco_TakeProfit;

      Lot=Banco_Lot;



      Cont_Ordem_Sell=0;

      Sell_Line=0;



      Cont_Ordem_Sell+=1;

      Coment="OUROE SELL "+Cont_Ordem_Sell;

      Sell_Order();



     }



   if(Nivel_Sell_02==True && Signal==Sell && Dist_Sell_02<Close[0] && Dist_Sell_02!=0)

     {



      Takeprofit=Banco_TakeProfit;



      if(Lot_Atual_Sell>Lot)

        {



         Lot=Lot_Atual_Sell+Lot_Atual_Sell;



           }else{



         Lot=Lot+(Lot*1);



        }



      if(TotalOrdersCountSell()>0 && Cont_Ordem_Sell==0)

        {



         Cont_Ordem_Sell+=TotalOrdersCountSell()+1;



           }else{



         Cont_Ordem_Sell+=1;



        }



      Coment="OUROE SELL "+Cont_Ordem_Sell;

      Sell_Order();



     }



   if(Nivel_Sell_03==True && Signal==Sell && Dist_Sell_03<Close[0] && Dist_Sell_03!=0)

     {



      if(Lot_Atual_Sell>Lot)

        {



         Lot=Lot_Atual_Sell+Lot_Atual_Sell;



           }else{



         Lot=Lot+(Lot*1);



        }



      if(TotalOrdersCountSell()>0 && Cont_Ordem_Sell==0)

        {



         Cont_Ordem_Sell+=TotalOrdersCountSell()+1;



           }else{



         Cont_Ordem_Sell+=1;



        }



      Coment="OUROE SELL "+Cont_Ordem_Sell;

      Sell_Order();



     }



// ---------------------------------------------------------------------------------------------------

// Sytem Verificador------------------------------------------------------------------------------------

// ---------------------------------------------------------------------------------------------------





   if(Signal==Buy)

     {



      if(TotalOrdersCountBuy()==1)

        {



         Dist_Buy_02=Sytem_Price_Atual_Buy()-(PipStep*Point);



        }



      if(TotalOrdersCountBuy()>1)

        {



         Dist_Buy_03_02 = Sytem_Price_Penultima_Buy()- Sytem_Price_Atual_Buy();

         Dist_Buy_03_01 = (Dist_Buy_03_02/2)+Dist_Buy_03_02;

         Dist_Buy_03=Sytem_Price_Atual_Buy()-Dist_Buy_03_01;

         Buy_Line=Dist_Buy_03;



         if(Takeprofit!=0 && TotalOrdersCountBuy()>2)

           {



            Take_Preco_Buy=Sytem_Price_Penultima_Buy()-(Dist_Buy_03_02*Porcentagem/100);

            Buy_Take_Profit_Line=Take_Preco_Buy;



           }



        }



      if(Takeprofit!=0 && (TotalOrdersCountBuy()==1 || TotalOrdersCountBuy()==2))

        {



         Buy_Take_Profit_Line=Sytem_Price_Atual_Buy()+(Takeprofit*Point);



        }



     }



   if(Signal==Sell)

     {



      if(TotalOrdersCountSell()==1)

        {



         Dist_Sell_02=Sytem_Price_Atual_Sell()+(PipStep*Point);



        }



      if(TotalOrdersCountSell()>1)

        {

         Dist_Sell_03_02 =  Sytem_Price_Atual_Sell() - Sytem_Price_Penultima_Sell();

         Dist_Sell_03_01 = (Dist_Sell_03_02/2)+Dist_Sell_03_02;

         Dist_Sell_03=Sytem_Price_Atual_Sell()+Dist_Sell_03_01;

         Sell_Line=Dist_Sell_03;



         if(Takeprofit!=0 && TotalOrdersCountSell()>2)

           {



            Take_Preco_Sell=Sytem_Price_Penultima_Sell()+(Dist_Sell_03_02*Porcentagem/100);

            Sell_Take_Profit_Line=Take_Preco_Sell;



           }



        }



      if(Takeprofit!=0 && (TotalOrdersCountSell()==1 || TotalOrdersCountSell()==2))

        {



         Sell_Take_Profit_Line=Sytem_Price_Atual_Sell()-(Takeprofit*Point);



        }



     }



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void System_Close()

  {



// Take Profit



   if(Takeprofit!=0)

     {



      if(Close[0]>Buy_Take_Profit_Line && Buy_Take_Profit_Line!=0)

        {



         Close_Buy();

         Buy_Take_Profit_Line=0;

         Buy_Stop_Line_Stop=0;



        }



      if(Close[0]<Sell_Take_Profit_Line && Sell_Take_Profit_Line!=0)

        {



         Close_Sell();

         //      Close_Buy();

         Sell_Take_Profit_Line=0;

         Sell_Stop_Line_Stop=0;



        }



     }



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void System_Calc()

  {



   if(TotalOrdersCount()==0)

     {



      Sell_Line=0;

      Cont_Ordem_Buy=0;

      Buy_Line=0;

      Cont_Ordem_Sell= 0;

      Cont_Ordem_Buy = 0;

      Sell_Take_Profit_Line= 0;

      Buy_Take_Profit_Line = 0;

      Dist_Sell_03 = 0;

      Dist_Sell_02 = 0;

      Dist_Buy_03 = 0;

      Dist_Buy_02 = 0;

      Take_Preco_Sell= 0;

      Take_Preco_Buy = 0;



     }



   if(TotalOrdersCountBuy()==0)

     {



      Buy_Line=0;

      Cont_Ordem_Buy=0;

      Buy_Take_Profit_Line=0;

      Dist_Buy_03 = 0;

      Dist_Buy_02 = 0;

      Take_Preco_Buy=0;



     }



   if(TotalOrdersCount()==0)

     {



      Sell_Line=0;

      Cont_Ordem_Sell=0;

      Sell_Take_Profit_Line=0;

      Dist_Sell_03 = 0;

      Dist_Sell_02 = 0;

      Take_Preco_Sell=0;



     }



//+------------------------------------------------------------------+

//|  Libera Sinal Buy                                                |

//+------------------------------------------------------------------+



   if(TotalOrdersCountBuy()==0 && Signal==Buy)

     {



      Nivel_Buy_01 = True;

      Nivel_Buy_02 = False;

      Nivel_Buy_03 = False;









     }

   else

     {



      if(TotalOrdersCountBuy()==1 && Signal==Buy)

        {



         Nivel_Buy_01=False;

         Nivel_Buy_02 = True;

         Nivel_Buy_03 = False;



        }

      else

        {



         if(TotalOrdersCountBuy()>1 && Signal==Buy)

           {



            Nivel_Buy_01=False;

            Nivel_Buy_02 = False;

            Nivel_Buy_03 = True;



           }

         else

           {



            Nivel_Buy_01=False;

            Nivel_Buy_02 = False;

            Nivel_Buy_03 = False;



           }



        }



     }



//+------------------------------------------------------------------+

//|  Libera Sinal Sell                                               |

//+------------------------------------------------------------------+

   if(TotalOrdersCountSell()==0 && Signal==Sell)

     {



      Nivel_Sell_01 = True;

      Nivel_Sell_02 = False;

      Nivel_Sell_03 = False;







     }

   else

     {



      if(TotalOrdersCountSell()==1 && Signal==Sell)

        {



         Nivel_Sell_01=False;

         Nivel_Sell_02 = True;

         Nivel_Sell_03 = False;





        }

      else

        {



         if(TotalOrdersCountSell()>1 && Signal==Sell)

           {



            Nivel_Sell_01=False;

            Nivel_Sell_02 = False;

            Nivel_Sell_03 = True;



           }

         else

           {



            Nivel_Sell_01=False;

            Nivel_Sell_02 = False;

            Nivel_Sell_03 = False;





           }



        }



     }



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void Info()

  {



   int Spread_Value=MarketInfo(Symbol(),MODE_SPREAD);



   Comment("OUROE v1.0"

           +"\n"

           +"_________________________________________"

           +"\n"

           +"Status : ",Status

           +"\n"

           +"Spread: ",Spread_Value

           +"\n"

           +"Moeda: ",Symbol()

           +"\n"

           +"ID Account: ",account

           +"\n"

           +"_________________________________________"

           +"\n"

           +"Total Ordens Buy: ",TotalOrdersCountBuy()

           +"\n"

           +"Total Ordens Sell: ",TotalOrdersCountSell()

           +"\n"



           );



   if(CorBars==True)

     {



      ChartSetInteger(0,CHART_MODE,0,CHART_CANDLES);

      ChartSetInteger(0,CHART_SHOW_GRID,0,0);



      ChartSetInteger(0,CHART_COLOR_CHART_DOWN,clrRed);

      ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,clrRed);

      ChartSetInteger(0,CHART_COLOR_CHART_UP,clrBlue);

      ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,clrBlue);



      CorBars=False;



     }



   if(Buy_Line>0)

     {



      ObjectDelete("Buy_Line");

      ObjectCreate("Buy_Line",OBJ_HLINE,0,0,Buy_Line);

      ObjectSet("Buy_Line",OBJPROP_COLOR,Yellow);

      ObjectSet("Buy_Line",OBJPROP_WIDTH,1);

      ObjectSet("Buy_Line",OBJPROP_RAY,False);

      ObjectSet("Buy_Line",OBJPROP_STYLE,STYLE_SOLID);



     }

   else

     {



      ObjectDelete("Buy_Line");



     }



   if(Sell_Line>0)

     {



      ObjectDelete("Sell_Line");

      ObjectCreate("Sell_Line",OBJ_HLINE,0,0,Sell_Line);

      ObjectSet("Sell_Line",OBJPROP_COLOR,Yellow);

      ObjectSet("Sell_Line",OBJPROP_WIDTH,1);

      ObjectSet("Sell_Line",OBJPROP_RAY,False);

      ObjectSet("Sell_Line",OBJPROP_STYLE,STYLE_SOLID);



     }

   else

     {



      ObjectDelete("Sell_Line");



     }



   if(Stoploss!=0 && (Buy_Stop_Line_Stop>0 || Sell_Stop_Line_Stop>0))

     {



      ObjectDelete("Buy_Stop_Line");

      ObjectCreate("Buy_Stop_Line",OBJ_HLINE,0,0,Buy_Stop_Line_Stop);

      ObjectSet("Buy_Stop_Line",OBJPROP_COLOR,Red);

      ObjectSet("Buy_Stop_Line",OBJPROP_WIDTH,1);

      ObjectSet("Buy_Stop_Line",OBJPROP_RAY,False);

      ObjectSet("Buy_Stop_Line",OBJPROP_STYLE,STYLE_SOLID);



      ObjectDelete("Sell_Stop_Line");

      ObjectCreate("Sell_Stop_Line",OBJ_HLINE,0,0,Sell_Stop_Line_Stop);

      ObjectSet("Sell_Stop_Line",OBJPROP_COLOR,Red);

      ObjectSet("Sell_Stop_Line",OBJPROP_WIDTH,1);

      ObjectSet("Sell_Stop_Line",OBJPROP_RAY,False);

      ObjectSet("Sell_Stop_Line",OBJPROP_STYLE,STYLE_SOLID);



     }

   else

     {



      ObjectDelete("Buy_Stop_Line");

      ObjectDelete("Sell_Stop_Line");



     }



   if(Takeprofit!=0 && (Buy_Take_Profit_Line>0 || Sell_Take_Profit_Line>0))

     {



      ObjectDelete("Buy_Stop");

      ObjectCreate("Buy_Stop",OBJ_HLINE,0,0,Buy_Take_Profit_Line);

      ObjectSet("Buy_Stop",OBJPROP_COLOR,Blue);

      ObjectSet("Buy_Stop",OBJPROP_WIDTH,1);

      ObjectSet("Buy_Stop",OBJPROP_RAY,False);

      ObjectSet("Buy_Stop",OBJPROP_STYLE,STYLE_SOLID);



      ObjectDelete("Sell_Stop");

      ObjectCreate("Sell_Stop",OBJ_HLINE,0,0,Sell_Take_Profit_Line);

      ObjectSet("Sell_Stop",OBJPROP_COLOR,Blue);

      ObjectSet("Sell_Stop",OBJPROP_WIDTH,1);

      ObjectSet("Sell_Stop",OBJPROP_RAY,False);

      ObjectSet("Sell_Stop",OBJPROP_STYLE,STYLE_SOLID);



     }

   else

     {



      ObjectDelete("Buy_Stop");

      ObjectDelete("Sell_Stop");



     }



   Saldo_Atual=NormalizeDouble(AccountBalance(),2);

   Equity=NormalizeDouble(AccountEquity(),2);



   if(Equity>=5.0 *(Saldo_Atual/6.0))

      g_color_1128=DodgerBlue;

   if(Equity>=4.0 *(Saldo_Atual/6.0) && Equity<5.0 *(Saldo_Atual/6.0))

      g_color_1128=DeepSkyBlue;

   if(Equity>=3.0 *(Saldo_Atual/6.0) && Equity<4.0 *(Saldo_Atual/6.0))

      g_color_1128=Gold;

   if(Equity>=2.0 *(Saldo_Atual/6.0) && Equity<3.0 *(Saldo_Atual/6.0))

      g_color_1128=OrangeRed;

   if(Equity>=Saldo_Atual/6.0 && Equity<2.0 *(Saldo_Atual/6.0))

      g_color_1128=Crimson;

   if(Equity<Saldo_Atual/5.0)

      g_color_1128=Red;



   Calc_Rebaixamento=Equity-Saldo_Atual;   // Calc_Rebaixamento = EQUILIBRIO - Saldo_Atual



   if(Calc_Rebaixamento<Cont_Rebaixamento)

     {

      // Calc_Rebaixamento < Cont_Rebaixamento



      Cont_Rebaixamento=Calc_Rebaixamento;



     }



   ObjectDelete("Rebaixamento");

   ObjectCreate("Rebaixamento",OBJ_LABEL,0,0,1.0);

   ObjectSet("Rebaixamento",OBJPROP_CORNER,3);

   ObjectSet("Rebaixamento",OBJPROP_XDISTANCE,450);

   ObjectSet("Rebaixamento",OBJPROP_YDISTANCE,11);

   ObjectSetText("Rebaixamento","Max. Rebaixamento:  "+DoubleToStr(Cont_Rebaixamento,2)+"",16,"Times New Roman",Red);



   ObjectDelete("Lable");

   ObjectCreate("Lable",OBJ_LABEL,0,0,1.0);

   ObjectSet("Lable",OBJPROP_CORNER,3);

   ObjectSet("Lable",OBJPROP_XDISTANCE,153);

   ObjectSet("Lable",OBJPROP_YDISTANCE,11);

   double SaldoAtual=AccountBalance();

   ObjectSetText("Lable","Saldo Atual:  "+DoubleToStr(SaldoAtual,2)+"",16,"Times New Roman",DodgerBlue);



   ObjectDelete("Lable_Buy");

   ObjectCreate("Lable2_Buy",OBJ_LABEL,0,0,1.0);

   ObjectSet("Lable2_Buy",OBJPROP_CORNER,3);

   ObjectSet("Lable2_Buy",OBJPROP_XDISTANCE,153);

   ObjectSet("Lable2_Buy",OBJPROP_YDISTANCE,31);

   ObjectSetText("Lable2_Buy","(Lucro/Perca):  "+DoubleToStr(ContLucro,2)+"",16,"Times New Roman",DodgerBlue);



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int TotalOrdersCount()

  {

//Contador  de Ordens



   int result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



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

        {



         if(OrderType()==OP_BUY || OP_SELL)

            result++;



        }



     }

   return (result);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int TotalOrdersCountSell() //Contador  de Ordens

  {



   int result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



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

        {

         if(OrderType()==OP_SELL)

            result++;



        }



     }

   return (result);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int TotalOrdersCountBuy() //Contador  de Ordens

  {



   int result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



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

        {

         if(OrderType()==OP_BUY)

            result++;



        }



     }

   return (result);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void Buy_Order()

  {



   int result=0;



   result=OrderSend(Symbol(),OP_BUY,Lot,Ask,0,0,0,Coment,MagicNumber,0,Blue);



   return;



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void Sell_Order()

  {



   int result=0;



   result=OrderSend(Symbol(),OP_SELL,Lot,Bid,0,0,0,Coment,MagicNumber,0,Red);



   return;



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double Sytem_Price_Atual_Buy()

  {



   double result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)

        {



         result=OrderOpenPrice();

         Lot_Atual_Buy=OrderLots();



        }



     }

   return (result);



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double Sytem_Price_Atual_Sell()

  {



   double result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)

        {



         result=OrderOpenPrice();

         Lot_Atual_Sell=OrderLots();



        }



     }

   return (result);



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double Sytem_Price_Penultima_Sell()

  {



   if(TotalOrdersCountSell()>0 && Cont_Ordem_Sell==0)

     {



      Cont_Ordem_Sell+=TotalOrdersCountSell();



     }



   double result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderComment()=="OUROE SELL "+(Cont_Ordem_Sell-1))

        {

         if(OrderType()==OP_SELL)



            result=OrderOpenPrice();



        }



     }

   return (result);



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double Sytem_Price_Penultima_Buy()

  {



   if(TotalOrdersCountBuy()>0 && Cont_Ordem_Buy==0)

     {



      Cont_Ordem_Buy+=TotalOrdersCountBuy();



     }



   double result=0;



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

     {



      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);



      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderComment()=="OUROE BUY "+(Cont_Ordem_Buy-1))

        {

         if(OrderType()==OP_BUY)



            result=OrderOpenPrice();



        }



     }

   return (result);



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void Banco_Dados()

  {



   if(Key_Banco_Dados==True)

     {



      Banco_Lot=Lot;

      Banco_TakeProfit=Takeprofit;



      Key_Banco_Dados=False;



     }



  }

//+------------------------------------------------------------------+

//| Funcao que fecha ordens de Compra                                |

//+------------------------------------------------------------------+

void Close_Buy()

  {



   while(TotalOrdersCountBuy()>0)

     {



      int Total=OrdersTotal();

      for(int cnt=Total-1; cnt>=0;)

        {

         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

           {

            switch(OrderType())

              {



               case OP_BUY:

                  Resultado_Close_Buy=OrderClose(OrderTicket(),OrderLots(),MarketInfo("",MODE_BID),3,Violet);

                  break;

              }

           }

         cnt=cnt -1;

        }



     }



  }

//+------------------------------------------------------------------+

//|Funcao que fecha ordens de Venda                                  |

//+------------------------------------------------------------------+

void Close_Sell()

  {



   while(TotalOrdersCountSell()>0)

     {



      int Total=OrdersTotal();

      for(int cnt=Total-1; cnt>=0;)



        {

         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

           {

            switch(OrderType())

              {



               case OP_SELL:

                  Resultado_Close_Sell=OrderClose(OrderTicket(),OrderLots(),MarketInfo("",MODE_ASK),3,Violet);

                  break;

              }

           }

         cnt=cnt -1;

        }



     }



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void LucroOrder()

  {



   ContLucro= 0;

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

     {

      double Order=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

      if(OrderSymbol()==Symbol())

        {



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



        }

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

bool MT4_ON_OFF()

  {



   bool retorno=false;



   if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)==1)

     {



      retorno=true;



     }



   if(retorno==True)

     {



      Status="ON";



        }else{



      if(retorno==false)

        {



         Status="OFF";



        }



     }



   return(retorno);

  }



//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---