Como codificar? - página 115

 
matrixebiz:
Não estou fazendo a mesma coisa ao fazer isto?

se (Hora() 17) TradeHour = falso;

Ou seja, se a hora estiver entre 12 e 17 TradeHour=verdadeiro , correto?

(Adicionando && TradeHour em minha declaração de Compra/Venda)

Negando a seguinte afirmação:

if(Hour()>=12 && Hour()<17)

TradingEnabled=true;

[/CODE]

is

[CODE]

if(Hour()=17)

TradingEnabled=false;

 

Mais uma coisa como acrescentar um atraso de reentrada ao código para que se uma negociação fosse apenas aberta e fechada, para esperar uns 60 min, então verifique novamente se as condições comerciais ainda são cumpridas.

Obrigado.

 
matrixebiz:
Mais uma coisa como acrescentar um atraso de reentrada ao código para que, se uma negociação acabou de ser aberta e fechada, para esperar uns 60 minutos, então verifique novamente se as condições da negociação ainda são cumpridas. Obrigado.

Não está claro qual é o seu pedido.

Você quer esperar 60 minutos entre uma verificação das condições comerciais e a próxima?

Se este é seu pedido, pode ser que isto funcione:

// Global variable

bool TradingEnabled = true; // flag to enable/disabled trading logic

bool TradingCheckDone = false; // flag to know if a a check was just done

datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....

if( !TradingCheckDone )

{

// Default: We assume that trading logic must run ...

TradingEnabled = true;

// ... but only between 12:00:00 and 16:59:59

if(Hour()=17)

TradingEnabled=false;

// We must remember a check was just done

TradingCheckDone = true;

// We must even know when it was done

LastCheckTime = TimeCurrent();

} else

{

// if a hour has passed since the last check, it's time to retry

if( TimeCurrent() - LastCheckTime >= 3600 )

{

TradingCheckDone = false;

}

}

 
gorgoroth:
Não está claro qual é o seu pedido.

Você quer esperar 60 minutos entre uma verificação das condições comerciais e a próxima?

Se este for o seu pedido, talvez isto funcione:

// Global variable

bool TradingEnabled = true; // flag to enable/disabled trading logic

bool TradingCheckDone = false; // flag to know if a a check was just done

datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....

if( !TradingCheckDone )

{

// Default: We assume that trading logic must run ...

TradingEnabled = true;

// ... but only between 12:00:00 and 16:59:59

if(Hour()=17)

TradingEnabled=false;

// We must remember a check was just done

TradingCheckDone = true;

// We must even know when it was done

LastCheckTime = TimeCurrent();

} else

{

// if a hour has passed since the last check, it's time to retry

if( TimeCurrent() - LastCheckTime >= 3600 )

{

TradingCheckDone = false;

}

}

Não, somente se um comércio acabou de acontecer e fechar, então quero que a EA espere uma hora e verifique se as condições comerciais ainda estão satisfeitas, se estão, então ok, comércio novamente, mas se não estiver, que seja assim. Este código vai fazer o que eu quero então? Será que isto funcionará no testador, devido à verificação da TimeCurrent?

EDIT: nem toda hora faz a verificação logo após o fechamento de uma troca, então espere uma hora por uma verificação de condição e pronto. Então, se em um dia outra profissão for gerada e fechada, então espere novamente uma hora e se não houver sinal, então não haverá mais checagens de espera até a próxima profissão abrir e fechar.

Obrigado.

Em anexo está uma pequena EA se você pudesse modificá-la com as configurações corretas que mencionei. Obrigado

Arquivos anexados:
ozfx_method.mq4  11 kb
 

Buy_Limit e Buy_Stop

Qual é a diferença entre uma ordem Limite e uma ordem Stop?

Obrigado

 
gorgoroth:
Olá a todos,

Eu desenvolvi um conjunto de funções para gerenciar as configurações de uma EA.

Essas funções são exportadas por uma DLL c++ e cada uma das funções exportadas tem a chamada __stdcall call convetion solicitada pelo meu MQL4.

Meu problema surge quando uma função precisa retornar uma string para o EA.

Naturalmente, a função não pode:

- retornar um ponteiro a uma variável local (a variável sai do escopo)

- retornar um ponteiro para uma variável global dll (problemas com acesso simultâneo)

- devolver um ponteiro a um monte de cordel alocado (preciso de funções para liberar a memória para ser chamado da EA: não gosto desta abordagem)

Portanto, resolvi passar um fio e um tamanho de fio da EA. Es:

string buffer;

GetString( buffer, 30 );

[/CODE]

and from the c++ dll, something like this

void __stdcall GetString( LPTSTR buffer, int BufSize )

{

// Read a string from a some source

....

// -1 to take into account the terminating null character

StringCchCopy( buffer, BufSize-1, ReadStringFromASource );

}

[/CODE]

Here starts the weird behaviour of MQL managing strings returned from a DLL.

using the following code:

string buffer;

GetString( buffer, 30 );

the first time buffer contains the right string. A first question arises: buffer is not initialized but after calling GetString it contains the string returned. I have to suppose that MQL allocates space for a string variable when it's declared.

Next time GetString() is called the string returned seems to be truncated to the length-1 of the previous string length and not resetted as expected because of the 'string buffer;' statement.

Tried even:

[CODE]

string buffer = " "; // 'allocate' 30 blank characters

GetString( buffer, StringLen(buffer) );

but after the first time, when the execution returns to this code, the assignment of buffer does not work any more and buffer still contains the previous read string, and it seems it can only contains the number of characters of his content.

At first I have thought that the null character is not handled very well by MQL and modified the c++ code like this ...

[CODE]

CopyMemory( buffer, ReadStringFromASource, min(BufferSize,ReadStringFromASourceLength) );

e não acrescentar o caráter nulo terminante.

Mas quando chamado da MQL, nenhuma cadeia de caracteres está retornando.

Alguém tem uma resposta?

Ninguém tem problemas ao retornar uma string das DLLs ?

 

Eu preciso de ajuda...

Alguém pode me mostrar um código? para anexar ao meu EA...

Uma ordem por sinal... porque às vezes tenho 3 sinais causa de TF diferente... quero que todos os sinais se abram...

ou um código que levaria uma ordem por barra, mas cada Timeframe anexado a uma EA... não quero abrir um monte de gráfico...

 

O que há de errado com minha BuyStop?

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);

 
matrixebiz:
O que há de errado com minha BuyStop?

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);

seu Stop Loss and Take Profit...

você também deve adicionar *ponto à sua distância antes de adicioná-lo...

OU

Bid-((Distance-StopLoss)*Point),Ask+((Distance+TakeProfit)*Point)