Pergunte! - página 34

 
AnasFX:
Ok, funcionou, mas agora o problema é o desempenho. A verificação de todo o histórico leva tempo. Eu fiz um backtest durante um ano e meio e notei que é lento. A razão é que estou verificando todos os pedidos na história e comparando o preço e o tempo de fechamento. Então, existe alguma forma de limitar a busca na história para que ela faça a busca apenas das encomendas recentes? Posso aumentar o desempenho de qualquer forma?

você pode tentar

OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY);

mas não tenho certeza para este, acho que ele vai pegar a última ordem em toda a história

aplausos

 

Hallo Folk...

pode alguém me ajudar...

eu tenho algum indicador para criar EA....

 
phoenix:
você pode tentar

OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY);

mas não tenho certeza para este, acho que ele vai pegar a última ordem em toda a história

aplausos

editado de falha minha...tem que ser

OrderSelect(HistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);

 

Desculpem a dupla postagem, mas preciso mesmo de ajuda...

Estou desesperado aqui. Tenho tentado a noite toda para que minha matriz funcione, mas nada acontece. Eu realmente tentei ser auto-suficiente e tentar aprender, mas ainda não consigo chegar aonde preciso ir. Se alguém pudesse por favor ter piedade de mim e me emprestar alguma ajuda....PLEASE!!!!!

Estou rodando um roteiro de grade, mas gostaria de rastrear quantos lotes eu estou rodando por Symbol. Quero ser capaz de somar qual é a minha posição total por lotes. Digamos que eu tenho 0,10, 0,10, 0,10, 0,10, 0,20, 0,30, quero poder saber que tenho o equivalente a 0,90 lotes. Também gostaria de saber os tamanhos mínimo e máximo de lotes.... 0,10 e 0,30

ArrayResize(OrderArray, i);

ArrayInitialize(OrderArray,0);

cnt = 0;

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

{

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

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

////// I can't get anything to work!!!!!!!

BuyLots += OrderArray[cnt][LOTS];

////// This returns Zero when I place BuyLots in my Comments

////// This returns error messages

MaxBuyLots =ArrayMaximum(OrderArray[LOTS],WHOLE_ARRAY,0);

}

 
deeforex:
Desculpe pela dupla postagem, mas eu realmente preciso de ajuda...

Estou desesperado aqui. Tenho tentado durante toda a noite fazer com que minha matriz funcione, mas nada acontece. Eu realmente tentei ser auto-suficiente e tentar aprender, mas ainda não consigo chegar aonde preciso ir. Se alguém pudesse ter piedade de mim e me emprestar alguma ajuda....PLEASE!!!!!

Estou rodando um roteiro de grade, mas gostaria de rastrear quantos lotes eu estou rodando por Symbol. Quero ser capaz de somar qual é a minha posição total por lotes. Digamos que eu tenho 0,10, 0,10, 0,10, 0,10, 0,20, 0,30, quero poder saber que tenho o equivalente a 0,90 lotes. Também gostaria de saber os tamanhos mínimo e máximo de lotes.... 0,10 e 0,30

O problema é que o arrayresize() só redimensiona o primeiro elemento, não o segundo. Obviamente seus LOTS,PROFIT,e OPEN macros devem ser 0,1,2 respectivamente. Também o objeto de contagem no for loop é (i) entretanto o código do bloco está se referindo ao (cnt). tente isto e veja se isto funciona.

double OrderArray[][3];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

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

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArray[cnt][LOTS];

MaxBuyLots =ArrayMaximum(OrderArray);

}

 

Obrigado Nicholishen,

Estou me aproximando um pouco mais. BuyLots está devolvendo o que eu quero, mas o ArrayMaximum está me dando um número estranho que eu não consigo entender bem. Ele não está devolvendo o maior LotSize.

Eu realmente aprecio a ajuda.

dee

 
deeforex:
Obrigado, Nicholishen,

Estou me aproximando um pouco mais. BuyLots está devolvendo o que eu quero, mas o ArrayMaximum está me dando um número estranho que eu não consigo entender bem. Ele não está devolvendo o maior LotSize.

Eu realmente aprecio a ajuda.

dee

Você precisará dividir o array em diferentes matrizes ou escrever um loop para extrair o máximo do array, como por exemplo:

double OrderArray...[];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

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

{

OrderArrayProfit[cnt] = OrderProfit() + OrderSwap();

OrderArrayOpen[cnt] = OrderOpenPrice();

OrderArrayLots[cnt] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArrayLots[cnt];

MaxBuyLots =ArrayMaximum(OrderArrayLots);

}

[/CODE]

or

[CODE]double OrderArray[][3];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

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

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArray[cnt][LOTS];

}

double MBL;

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

if(OrderArrayLots[LOTS]>MBL)MBL=OrderArrayLots[LOTS];

}

MaxBuyLots =MBL;

 

Aqui está outro exemplo de uma função que rastreia paradas apertadas através de múltiplas negociações na mesma moeda, emparelhando os dados de rastreamento com o número do bilhete da negociação correspondente - usando matrizes. Talvez isto ajude a dar algumas idéias também.

int tsTicket[21];

double tsPrice[21];

bool tsok[21];

int tkt3[20];

int SuperClose(){// superclose by nicholishen

int cnp=ordercnt();

for(int i=0;i<cnp;i++){

if(OrderMatch(i)){

if(0==0){//Pulls in order that meets the criteria for processing

int num=0;int pos=0;

for(int b=0;b<21;b++){// this (loopB) compares the ticket# of the selected order against the number stored in the ticket array

if(tsTicket==OrderTicket() ){

num++; pos=b;// if ticket numbers match, pos is the position in the array where the trailing data is stored

break;

}

}

if(num==0){ // if the loopB did not find a matching ticket number it is time to initialize the data

for(int j=0;j<21;j++){

if(tsTicket[j]==0){// this is looking for the earliest instance within the array to store the data

pos=j;

break;

}

}

tsTicket[pos]=OrderTicket();// setting the ticket number

tsok[pos]=false;// this is to determine when trailing kicks in

// Print("(",pos,") New ticket initialized = ",tsTicket[pos]);

}

if (OrderType()==OP_SELL) {

if (!tsok[pos] && (OrderOpenPrice()-Ask>=TSactivation*Point || TSactivation==0 ) ) {// if the trailing factor is false, but it has hit the activation point continue

tsPrice[pos]=Ask+TrailPips*Point;// this is the new trailinf stop price

tsok[pos]=true;// it's ok to proceed with trailing stop

if(TrailPips>8){// if this distance from the current price to the new stop, then modify the order.

ModifyStopLoss(Ask+TrailPips*Point,OrderTakeProfit());//modifies order

}

}

if (tsok[pos] && Ask+TrailPips*Point < tsPrice[pos] ){//if the position is gaining in profit

tsPrice[pos]=Ask+TrailPips*Point;

if(TrailPips>8){

ModifyStopLoss(Ask+TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Ask >= tsPrice[pos] ){// if the postion hits the stop price

if(CloseOrder(Ask)==STOP)return(STOP);

Print("Short Order ",tsTicket[pos]," Closed from TS");

}

}

else if (OrderType()==OP_BUY) {// reverse of SELL

if(!tsok[pos] && (Bid-OrderOpenPrice() >= TSactivation*Point || TSactivation==0 ) ) {

tsPrice[pos]=Bid-TrailPips*Point;

tsok[pos]=true;

if(TrailPips>8){

ModifyStopLoss(Bid-TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Bid-TrailPips*Point > tsPrice[pos] ){

tsPrice[pos]=Bid-TrailPips*Point;

if(TrailPips > 8){

ModifyStopLoss(Bid-TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Bid <= tsPrice[pos] ){

if(CloseOrder(Bid)==STOP)return(STOP);

Print("Long Order ",tsTicket[pos]," Closed from TS");

}

}

}

}

if(RefreshRates())return(STOP);

}

for(i=0;i<21;i++){// this searches the array for ticket numbers that are now obsolete due to an order that has closed

if(tsTicket>0){

bool found=false;

for(b=0;b<OrdersTotal();b++){

OrderSelect(b,SELECT_BY_POS);

if(tsTicket==OrderTicket()){

found=true;

break;

}

}

if(!found){// if there are matching ticket numbers in the trade pool and the array then nothing happens

tsTicket=0;tsPrice=0;tsok=false;// if there is an obolete ticket the the data is reset. And the next new ticket data can occupy this space

// Print("Array pos ",i," Cleaned");

}

}

}

return(0);

}

int ordercnt(){

int c;

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

if(OrderSelect(i,SELECT_BY_POS)){

if(OrderMagicNumber()==ID && OrderSymbol()==Symbol()){

tkt3[c]=OrderTicket();

c++;

}

}

}

return(c);

}

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

int curcnt(){

int c;

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

if(OrderSelect(i,SELECT_BY_POS)){

if(OrderSymbol()==Symbol()){

c++;

return(c);

}

}

}

return(c);

}

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

bool OrderMatch(int i){

if(OrderSelect(tkt3,SELECT_BY_TICKET)){

if(OrderMagicNumber()==ID && OrderSymbol()==Symbol()){

return(true);

}

}

return(false);

}
 

Mais uma vez, obrigado!

Mudei a 3ª linha da última linha para esta

if(OrderArray[LOTS]>MBL)MBL=OrderArray[LOTS];

e consegui que funcionasse. Já passa da minha hora de dormir. Amanhã, quando eu acordar, estudarei a lógica de seu código. Mas como sou teimoso, vou descobrir como usar a maldita função ArrayMaximum!! Também terei que ler mais sobre indexação para ver como minhas antigas maneiras estavam tão erradas.

Obrigado novamente!!!!

dee

 
deeforex:
Mais uma vez, obrigado!

Mudei a 3ª linha da última linha para esta

if(OrderArray[LOTS]>MBL)MBL=OrderArray[LOTS];

e consegui que funcionasse. Já passa da minha hora de dormir. Amanhã, quando eu acordar, estudarei a lógica de seu código. Mas como sou teimoso, vou descobrir como usar a maldita função ArrayMaximum!! Também terei que ler mais sobre indexação para ver como minhas antigas maneiras estavam tão erradas.

Obrigado novamente!!!!

dee

só para poupar tempo, a razão pela qual a função max não estava funcionando para o que você queria é porque você está usando um array multidimensional e está armazenando diferentes tipos de dados. Ele retornará o máximo desses dados, então é provável que você esteja retornando um número de lucro ou algo maior do que seu tamanho de lote REAL máximo