Logic error

 
This logic is crazy, in the middle of this codes is a commentary of the problem.

This codes ignore the logic and buy: bool comprar_darvas = UpperBuffer[0] > BOX_TOP_Buffer[0]; with the same values of the variables. Why?

For example, the variables UpperBuffer[0] = 41.23 and BOX_TOP_Buffer[0] = 41.23 and the buy occurs. 

The code is below:
--------------------------------------------------------------------------------------
void OnTick()
{
//---
CopyRates(_Symbol,_Period,0,4,velas);
ArraySetAsSeries(velas,true);
SymbolInfoTick(_Symbol,tick);
CopyBuffer(cus_Handle,0,0,4,UpperBuffer);
CopyBuffer(cus_Handle,1,0,4,LowerBuffer);
CopyBuffer(cus_Handle,2,0,4,BOX_TOP_Buffer);
ArraySetAsSeries(UpperBuffer,true);
ArraySetAsSeries(LowerBuffer,true);
ArraySetAsSeries(BOX_TOP_Buffer,true);
//---
bool Comprar = false;
bool Vender = false;
// Logic for buy
bool comprar_darvas = UpperBuffer[0] > BOX_TOP_Buffer[0]; // Here is the problem, the value of the variables are the same and it buys.
if(comprar_darvas=true)
{
Comprar = comprar_darvas;
Print("Dados da compra:");
Print("BOX_TOP_Buffer[0] = ", BOX_TOP_Buffer[0]);
Print("UpperBuffer[0] = ", UpperBuffer[0]);
Print("=================================");
}
//---
bool temosNovaVela = TemosNovaVela();
if(temosNovaVela)
{
if(Comprar==true && PositionSelect(_Symbol)==false)
{
desenhaLinhaVertical("Compra",velas[1].time,clrBlue);
CompraAMercado();
}
}
}
 
Camunda:
This logic is crazy, in the middle of this codes is a commentary of the problem.

This codes ignore the logic and buy: bool comprar_darvas = UpperBuffer[0] > BOX_TOP_Buffer[0]; with the same values of the variables. Why?

For example, the variables UpperBuffer[0] = 41.23 and BOX_TOP_Buffer[0] = 41.23 and the buy occurs. 

The code is below:
--------------------------------------------------------------------------------------
void OnTick()
{
//---
CopyRates(_Symbol,_Period,0,4,velas);
ArraySetAsSeries(velas,true);
SymbolInfoTick(_Symbol,tick);
CopyBuffer(cus_Handle,0,0,4,UpperBuffer);
CopyBuffer(cus_Handle,1,0,4,LowerBuffer);
CopyBuffer(cus_Handle,2,0,4,BOX_TOP_Buffer);
ArraySetAsSeries(UpperBuffer,true);
ArraySetAsSeries(LowerBuffer,true);
ArraySetAsSeries(BOX_TOP_Buffer,true);
//---
bool Comprar = false;
bool Vender = false;
// Logic for buy
bool comprar_darvas = UpperBuffer[0] > BOX_TOP_Buffer[0]; // Here is the problem, the value of the variables are the same and it buys.
if(comprar_darvas=true)
{
Comprar = comprar_darvas;
Print("Dados da compra:");
Print("BOX_TOP_Buffer[0] = ", BOX_TOP_Buffer[0]);
Print("UpperBuffer[0] = ", UpperBuffer[0]);
Print("=================================");
}
//---
bool temosNovaVela = TemosNovaVela();
if(temosNovaVela)
{
if(Comprar==true && PositionSelect(_Symbol)==false)
{
desenhaLinhaVertical("Compra",velas[1].time,clrBlue);
CompraAMercado();
}
}
}


Sempre que postar código use o ícone:


Não sei de onde você tirou esse código, mas ele é perigosíssimo... Ele simplesmente não checa NADA dos retornos dos Copys....

E, o erro está na linha:

if(comprar_darvas=true) 

Você está atribuindo TRUE à variável, portanto o IF será verdadeiro.

O operador de comparação no MQL5, bem como no C++, é "==".


;)

 
Flavio Jarabeck #:


Sempre que postar código use o ícone:


Não sei de onde você tirou esse código, mas ele é perigosíssimo... Ele simplesmente não checa NADA dos retornos dos Copys....

E, o erro está na linha:

Você está atribuindo TRUE à variável, portanto o IF será verdadeiro.

O operador de comparação no MQL5, bem como no C++, é "==".


;)

Muito obrigado Flavio.