Ajuda em código!

 

Olá,

Alguém poderia me ajudar em um código.

Está ficando "lixo", marcações sem necessidade, porém não sei o porque.

Não sou programador estou fazendo esse código para me auxiliar nos trades estatísticos.


//--- indicator buffers
double         Compra123Buffer[];
double         Venda123Buffer[];
double         CompraDLBuffer[];
double         VendaDLBuffer[];
double         CompraIBBuffer[];
double         VendaIBBuffer[];

double         TakeProfitBuffer[];
double         StopBuffer[];

double         IMACDBuffer[];
double         IBandsBuffer[];

//--- list global variable
string name[]={"Setup 123","Setup Dave Landry","Setup Inside Bar"};
int MACD_handle;
int Bands_handle;
int MA8_handle;
int MA50_handle;
int MA80_handle;
int MA200_handle;
int iMACD_handle;

bool Risk;

//--- input parameters
input int   MACD_EMA_Rapida        =12;
input int   MACD_EMA_Lenta         =26;
input int   MACD_SMA               =9;
input bool  MACD                   =true;

input bool  Setup123               =true;
input double TakeProfit123         =1.5;

input bool  SetupDaveLandry        =true;
input double TakeProfitDaveLandry  =1.5;

input bool  SetupInsideBar         =true;
input double TakeProfitInsideBar   =1.5;

input int   Contract               =1;
input int   Budget                 =500;
input double Point_Value           =0.20;
input double Risk_Value            =0.05;
input bool  RiskTrade              =true;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   MACD_handle = iMACD(_Symbol,_Period,MACD_EMA_Rapida,MACD_EMA_Lenta,MACD_SMA,PRICE_CLOSE);
   ChartIndicatorAdd(ChartID(),1,MACD_handle);    
 
   Bands_handle = iBands(_Symbol,_Period,20,0,2,PRICE_CLOSE);
   ChartIndicatorAdd(ChartID(),0,Bands_handle);

//   MA8_handle = iMA(_Symbol,_Period,8,0,1,PRICE_CLOSE);
//   ChartIndicatorAdd(ChartID(),0,MA8_handle);

   MA50_handle = iMA(_Symbol,_Period,50,0,1,PRICE_CLOSE);
   ChartIndicatorAdd(ChartID(),0,MA50_handle);
   
//   MA80_handle = iMA(_Symbol,_Period,80,0,1,PRICE_CLOSE);
//   ChartIndicatorAdd(ChartID(),0,MA80_handle);

//   MA200_handle = iMA(_Symbol,_Period,200,0,1,PRICE_CLOSE);
//   ChartIndicatorAdd(ChartID(),0,MA200_handle);
   
   for(int i=0;i<ArraySize(name);i++)
     {
      ObjectCreate(0,name[i],OBJ_LABEL,0,0,0);
      ObjectSetString(0,name[i],OBJPROP_FONT,"Tahoma");
      ObjectSetInteger(0,name[i],OBJPROP_FONTSIZE,10);
      ObjectSetInteger(0,name[i],OBJPROP_CORNER,2);
      ObjectSetInteger(0,name[i],OBJPROP_ANCHOR,ANCHOR_RIGHT_LOWER);
      ObjectSetInteger(0,name[i],OBJPROP_XDISTANCE,10);
      ObjectSetInteger(0,name[i],OBJPROP_YDISTANCE,i*15);
      ObjectSetInteger(0,name[i],OBJPROP_COLOR,PlotIndexGetInteger(8,PLOT_LINE_COLOR,i));
      ObjectSetString(0,name[i],OBJPROP_TEXT,name[i]);
     }
       
//--- indicator buffers mapping
   SetIndexBuffer(0,Compra123Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Venda123Buffer,INDICATOR_DATA);
   SetIndexBuffer(2,CompraDLBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,VendaDLBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,CompraIBBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,VendaIBBuffer,INDICATOR_DATA);

   SetIndexBuffer(6,TakeProfitBuffer,INDICATOR_DATA);
   SetIndexBuffer(7,StopBuffer,INDICATOR_DATA);
            
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,167);
   PlotIndexSetInteger(1,PLOT_ARROW,167);   
   PlotIndexSetInteger(2,PLOT_ARROW,167);
   PlotIndexSetInteger(3,PLOT_ARROW,167);
   PlotIndexSetInteger(4,PLOT_ARROW,167);
   PlotIndexSetInteger(5,PLOT_ARROW,167);

   PlotIndexSetInteger(6,PLOT_ARROW,158);
   PlotIndexSetInteger(7,PLOT_ARROW,158);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
 {
    
  CopyBuffer(MACD_handle,0,0,rates_total,IMACDBuffer);  
        
  for(int i=2; i<rates_total;i++)
  {
 
    if(RiskTrade == true)
      {
      Risk = (high[i]-low[i-1])/(Budget/(Point_Value*Contract))>Risk_Value;     
      }
    else
      {
      Risk = true; 
      } 
                        
 // 123 ------------------------------------------------------------------------     
   if(Setup123==true)
   {
      if(MACD==true)
      {
      if(low[i]>low[i-1] && low[i-1]<low[i-2] && IMACDBuffer[i]>0 && CompraDLBuffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          Compra123Buffer[i]=high[i]+60;
          
          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfit123;
          StopBuffer[i]=low[i-1]-1;
         }
      else if(low[i]>low[i-1] && low[i-1]<low[i-2] && IMACDBuffer[i]>0 && CompraDLBuffer[i]>0 && Risk==true)
         {
          Compra123Buffer[i]=high[i]+50;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfit123;
          StopBuffer[i]=low[i-1]-1;
         }         
      else if(low[i]>low[i-1] && low[i-1]<low[i-2] && IMACDBuffer[i]>0 && Risk==true)
         {
          Compra123Buffer[i]=high[i]+20;
          
          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfit123;
          StopBuffer[i]=low[i-1]-1;
         }
      else
         {
          Compra123Buffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;
         }
      }
      else
      {
      if(low[i]>low[i-1] && low[i-1]<low[i-2] && CompraDLBuffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          Compra123Buffer[i]=high[i]+60;
          
          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfit123;
          StopBuffer[i]=low[i-1]-1;
         }
      else if(low[i]>low[i-1] && low[i-1]<low[i-2] && CompraDLBuffer[i]>0 && Risk==true)
         {
          Compra123Buffer[i]=high[i]+50;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfit123;
          StopBuffer[i]=low[i-1]-1;
         }         
      else if(low[i]>low[i-1] && low[i-1]<low[i-2] && Risk==true)
         {
          Compra123Buffer[i]=high[i]+20;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfit123;
          StopBuffer[i]=low[i-1]-1;
         }
      else
         {
          Compra123Buffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;
         }
      }
      
      if(MACD==true)
      {            
      if(high[i]<high[i-1] && high[i-1]>high[i-2] && IMACDBuffer[i]<0 && CompraDLBuffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          Venda123Buffer[i]=low[i]-60;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfit123;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && high[i-1]>high[i-2] && IMACDBuffer[i]<0 && CompraDLBuffer[i]>0 && Risk==true)
         {
          Venda123Buffer[i]=low[i]-50;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfit123;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && high[i-1]>high[i-2] && IMACDBuffer[i]<0 && Risk==true)
         {
          Venda123Buffer[i]=low[i]-20;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfit123;
          StopBuffer[i]=high[i-1]+1;
         }
      else
         {
          Venda123Buffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }
      }
      else
      {
      if(high[i]<high[i-1] && high[i-1]>high[i-2] && CompraDLBuffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          Venda123Buffer[i]=low[i]-60;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfit123;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && high[i-1]>high[i-2] && CompraDLBuffer[i]>0 && Risk==true)
         {
          Venda123Buffer[i]=low[i]-50;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfit123;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && high[i-1]>high[i-2] && Risk==true)
         {
          Venda123Buffer[i]=low[i]-20;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfit123;
          StopBuffer[i]=high[i-1]+1;
         }
      else
         {
          Venda123Buffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }
      }     
   }
 
 // Dave Landry ------------------------------------------------------------------      
   if(SetupDaveLandry==true)
   {
      if(MACD==true)
      {  
      if(low[i]<low[i-1] && low[i]<low[i-2] && IMACDBuffer[i]>0 && Compra123Buffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          CompraDLBuffer[i]=high[i]+60;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=low[i]-1;
         }
      else if(low[i]<low[i-1] && low[i]<low[i-2] && IMACDBuffer[i]>0 && Compra123Buffer[i]>0 && Risk==true)
         {
          CompraDLBuffer[i]=high[i]+50;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=low[i]-1;
         }
      else if(low[i]<low[i-1] && low[i]<low[i-2] && IMACDBuffer[i]>0 && Risk==true)
         {
          CompraDLBuffer[i]=high[i]+20;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=low[i]-1;
         }
      else
         {
          CompraDLBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }
      }
      else
      {
      if(low[i]<low[i-1] && low[i]<low[i-2] && Compra123Buffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          CompraDLBuffer[i]=high[i]+60;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=low[i]-1;
         }
      else if(low[i]<low[i-1] && low[i]<low[i-2] && Compra123Buffer[i]>0 && Risk==true)
         {
          CompraDLBuffer[i]=high[i]+50;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=low[i]-1;
         }
      else if(low[i]<low[i-1] && low[i]<low[i-2] && Risk==true)
         {
          CompraDLBuffer[i]=high[i]+20;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=low[i]-1;
         }
      else
         {
          CompraDLBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }
      }
      
      if(MACD==true)
      {              
      if(high[i]>high[i-1] && high[i]>high[i-2] && IMACDBuffer[i]<0 && Compra123Buffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          VendaDLBuffer[i]=low[i]-60;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=high[i]+1;
         }
      else if(high[i]>high[i-1] && high[i]>high[i-2] && IMACDBuffer[i]<0 && Compra123Buffer[i]>0 && Risk==true)
         {
          VendaDLBuffer[i]=low[i]-50;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=high[i]+1;
         }
      else if(high[i]>high[i-1] && high[i]>high[i-2] && IMACDBuffer[i]<0 && Risk==true)
         {
          VendaDLBuffer[i]=low[i]-20;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=high[i]+1;
         }
      else
         {
          VendaDLBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }   
      }
      else
      {
      if(high[i]>high[i-1] && high[i]>high[i-2] && Compra123Buffer[i]>0 && CompraIBBuffer[i]>0 && Risk==true)
         {
          VendaDLBuffer[i]=low[i]-60;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=high[i]+1;
         }
      else if(high[i]>high[i-1] && high[i]>high[i-2] && Compra123Buffer[i]>0 && Risk==true)
         {
          VendaDLBuffer[i]=low[i]-50;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=high[i]+1;
         }
      else if(high[i]>high[i-1] && high[i]>high[i-2] && Risk==true)
         {
          VendaDLBuffer[i]=low[i]-20;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitDaveLandry;
          StopBuffer[i]=high[i]+1;
         }
      else
         {
          VendaDLBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         } 
      }
   }
 // Inside Bar ------------------------------------------------------------------      
   if(SetupInsideBar==true)
   {
      if(MACD==true)
      {  
      if(high[i]<high[i-1] && low[i]>low[i-1] && IMACDBuffer[i]>0 && Compra123Buffer[i]>0 && CompraDLBuffer[i]>0 && Risk==true)
         {
          CompraIBBuffer[i]=high[i]+60;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=low[i-1]-1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && IMACDBuffer[i]>0 && Compra123Buffer[i]>0 && Risk==true)
         {
          CompraIBBuffer[i]=high[i]+50;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=low[i-1]-1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && IMACDBuffer[i]>0 && Risk==true)
         {
          CompraIBBuffer[i]=high[i]+20;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=low[i-1]-1;
         }                   
      else
         {
          CompraIBBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;
         }
      }
      else
      {
      if(high[i]<high[i-1] && low[i]>low[i-1] && Compra123Buffer[i]>0 && CompraDLBuffer[i]>0 && Risk==true)
         {
          CompraIBBuffer[i]=high[i]+60;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=low[i-1]-1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && Compra123Buffer[i]>0 && Risk==true)
         {
          CompraIBBuffer[i]=high[i]+50;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=low[i-1]-1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && Risk==true)
         {
          CompraIBBuffer[i]=high[i]+20;

          TakeProfitBuffer[i]=high[i]+((high[i]-low[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=low[i-1]-1;
         }                   
      else
         {
          CompraIBBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }
      }
      
      if(MACD==true)
      {  
      if(high[i]<high[i-1] && low[i]>low[i-1] && IMACDBuffer[i]<0 && Compra123Buffer[i]>0 && CompraDLBuffer[i]>0 && Risk==true)
         {
          VendaIBBuffer[i]=low[i]-60;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && IMACDBuffer[i]<0 && Compra123Buffer[i]>0 && Risk==true)
         {
          VendaIBBuffer[i]=low[i]-50;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && IMACDBuffer[i]<0 && Risk==true)
         {
          VendaIBBuffer[i]=low[i]-20;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=high[i-1]+1;
         }
      else
         {
          VendaIBBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         } 
      }
      else
      {
      if(high[i]<high[i-1] && low[i]>low[i-1] && Compra123Buffer[i]>0 && CompraDLBuffer[i]>0 && Risk==true)
         {
          VendaIBBuffer[i]=low[i]-60;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && Compra123Buffer[i]>0 && Risk==true)
         {
          VendaIBBuffer[i]=low[i]-50;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=high[i-1]+1;
         }
      else if(high[i]<high[i-1] && low[i]>low[i-1] && Risk==true)
         {
          VendaIBBuffer[i]=low[i]-20;

          TakeProfitBuffer[i]=low[i]+((low[i]-high[i-1]))*TakeProfitInsideBar;
          StopBuffer[i]=high[i-1]+1;
         }
      else
         {
          VendaIBBuffer[i]=0;
          
          //TakeProfitBuffer[i]=0;
          //StopBuffer[i]=0;         
         }
      }            
   }
  }
//--- return value of prev_calculated for next call
   return(rates_total);
 }
//+------------------------------------------------------------------+
Arquivos anexados:
Setup.PNG  45 kb
 
Igor Ronchi:

Olá,

Alguém poderia me ajudar em um código.

Está ficando "lixo", marcações sem necessidade, porém não sei o porque.

Não sou programador estou fazendo esse código para me auxiliar nos trades estatísticos.


Se você não é programador e não entende nada de MQL5, você precisa contratar alguém que saiba.

Pedir por ajuda é para quem sabe o que está fazendo, e realmente precisa de ajuda.

https://www.mql5.com/pt/job

Aplicativos de negociação para o MetaTrader 5 por encomenda
Aplicativos de negociação para o MetaTrader 5 por encomenda
  • www.mql5.com
Preciso de uma modificação em um indicador, o indicador mostra as entradas e tem um relatorio de acertividade para a primeira entrada, preciso que ele mostre a acertividade do com uma segunda entrada sendo o martin gale. calculando a acerticidade do graficona primeira entrada e na segunda tambem Robô faz zeragem automática quando toca a média...
 
Flavio Jarabeck:

Se você não é programador e não entende nada de MQL5, você precisa contratar alguém que saiba.

Pedir por ajuda é para quem sabe o que está fazendo, e realmente precisa de ajuda.

https://www.mql5.com/pt/job

O código acima foi eu quem desenvolveu, não sou programador um aprendiz talvez e estou desenvolvendo meu próprio código.

Estou pedindo ajuda para localizar erros que ainda não sou capaz de encontrar.

 
Igor Ronchi:

O código acima foi eu quem desenvolveu, não sou programador um aprendiz talvez e estou desenvolvendo meu próprio código.

Estou pedindo ajuda para localizar erros que ainda não sou capaz de encontrar.

Igor, 

Flávio está certo. 

Você não postou "...estou com problemas aqui nessa função ou nesse parâmetro..." simplesmente você jogou um código mal escrito que não foi feito por um programador e quer que alguém leia seu código inteiro e saia corrigindo falhas básicas. Isso não é pedir ajuda é transferir problema para que outro trabalhe para você. 

Você precisa estudar, talvez fazer um curso, aprender a testar, debugar, pesquisar, se esforçar um pouco para aprender, e dai quando você esbarrar em algum problema específico que sozinho não esteja conseguindo dai sim peça ajuda.

Mas neste momento o que você está pedindo não é uma ajuda, é alguém para trabalhar para você.

Razão: