Perguntas de Iniciantes MQL4 MT4 MetaTrader 4 - página 35

 

Olá!
Para fixar o indicador, era preciso substituir todos os pontos "." por um "." em branco.

Arquivos anexados:
supDem.zip  68 kb
 

Saudações.

Mudei o tipo de seleção deordem na função escrita de determinada ordem contando de seleção por ordem para seleção por bilhete.

int BuyLimitCount(){
int count=0
for(int i=OrdersTotal()-1; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POSMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}}return(count);}  

int BuyLimitCount(){
int count=0
if(OrderSelect(ticketUP, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}return(count);}

Depois disso, ao executar algumas dúzias de velas, tudo funciona corretamente e, depois disso, há erros repetidos no registro:

2016.12.17 17:44:31.609 2016.12.07 00:27 teste3 EURUSD,M1: bilhete desconhecido 2 para a função OrderModify

2016.12.17 17:44:31.608 2016.12.07 00:25 teste3 EURUSD,M1: OrderModify error 4108 // Número de bilhete inválido.

Aqui está o texto completo, eu o alterei em todas as quatro funções:

extern int pointsl=100, pointtp=100, MagicB=1111, MagicS=2222, bars=10;  extern double lotB=0.1, lotS=0.1;
double slB, tpB, slS, tpS;  double x=0, z=0int ticketUP, ticketD;


void OnTick()  
{
double maxpr1=-9999double minpr1=9999;

for(int shift1=0; shift1<bars; shift1++)
{double i=iHigh(Symbol(), PERIOD_CURRENT, shift1);
if (i>maxpr1){maxpr1=i;}}

for(int shiftA1=0; shiftA1<bars; shiftA1++)
{double y=iLow(Symbol(), PERIOD_CURRENT, shiftA1);
if (y<minpr1) {minpr1=y;}} 

if (BuyLimitCount()==0 && BuyCount()==0){
slB=NormalizeDouble(minpr1-pointsl*Point,5);
tpB=NormalizeDouble(minpr1+pointtp*Point,5);
ticketUP=OrderSend(Symbol(), OP_BUYLIMIT, lotB, minpr1, 3, slB, tpB, "", MagicB, 0, Red);
if (ticketUP==-1Print("ERROR OP_BUY"); else Print("OP_BUY OK");}

if (SellLimitCount()==0 && SellCount() ==0){
slS=NormalizeDouble(maxpr1+pointsl*Point,5);
tpS=NormalizeDouble(maxpr1-pointtp*Point,5);
ticketD=OrderSend(Symbol(), OP_SELLLIMIT, lotS, maxpr1, 3, slS, tpS, "", MagicS, 0, Blue);
if (ticketD==-1Print("ERROR OP_SELL"); else Print("OP_SELL OK");}

if (x!=maxpr1){x=maxpr1;
slS=NormalizeDouble(maxpr1+pointsl*Point,5);
tpS=NormalizeDouble(maxpr1-pointtp*Point,5);
OrderModify(ticketD, maxpr1, slS, tpS, 0, Blue);}

if (z!=minpr1){z=minpr1;
slB=NormalizeDouble(minpr1-pointsl*Point,5);
tpB=NormalizeDouble(minpr1+pointtp*Point,5);
OrderModify(ticketUP, minpr1, slB, tpB, 0, Red);}

double maxpr=-9999double minpr=9999;

for(int shift=0; shift<bars; shift++)
{double e=iHigh(Symbol(), PERIOD_CURRENT, shift);
if (e>maxpr){maxpr=e;}}

for(int shiftA=0; shiftA<bars; shiftA++)
{double r=iLow(Symbol(), PERIOD_CURRENT, shiftA);
if (r<minpr) {minpr=r;}} 

string a;
if(bars==1)a="bar: ";
else a= IntegerToString(bars,1) + " bar's: ";
Comment("Last ", a, "max "DoubleToStr(maxpr, 5), ", min "DoubleToStr(minpr, 5),".");
}

int BuyLimitCount(){
int count=0
if(OrderSelect(ticketUP, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}return(count);}

int BuyCount(){
int count=0
if(OrderSelect(ticketUP, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUY)
count++;}}return(count);}

int SellLimitCount(){
int count=0
if(OrderSelect(ticketD, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicS){
if(OrderType()==OP_SELLLIMIT)
count++;}}return(count);}

int SellCount(){
int count=0
if(OrderSelect(ticketD, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicS){
if(OrderType()==OP_SELL)
count++;}}return(count);}


E aqui há um momento - depois que mudei a função de seleção, a função de modificação de ordem começou a gerar um erro e somente após algum tempo detestes, no início tudo estava normal.

Por que isso acontece e como lidar com isso?


 
spoiltboy:

Saudações.

Mudei o tipo de seleção deordem na função escrita de determinada ordem contando de seleção por ordem para seleção por bilhete.

int BuyLimitCount(){
int count=0
for(int i=OrdersTotal()-1; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POSMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}}return(count);}  

int BuyLimitCount(){
int count=0
if(OrderSelect(ticketUP, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}return(count);}

Depois disso, ao executar algumas dúzias de velas, tudo funciona corretamente e, depois disso, há erros repetidos no registro:

2016.12.17 17:44:31.609 2016.12.07 00:27 teste3 EURUSD,M1: bilhete desconhecido 2 para a função OrderModify

2016.12.17 17:44:31.608 2016.12.07 00:25 teste3 EURUSD,M1: OrderModify error 4108 // Número de bilhete inválido.

Aqui está o texto completo, eu o alterei em todas as quatro funções:

extern int pointsl=100, pointtp=100, MagicB=1111, MagicS=2222, bars=10;  extern double lotB=0.1, lotS=0.1;
double slB, tpB, slS, tpS;  double x=0, z=0int ticketUP, ticketD;


void OnTick()  
{
double maxpr1=-9999double minpr1=9999;

for(int shift1=0; shift1<bars; shift1++)
{double i=iHigh(Symbol(), PERIOD_CURRENT, shift1);
if (i>maxpr1){maxpr1=i;}}

for(int shiftA1=0; shiftA1<bars; shiftA1++)
{double y=iLow(Symbol(), PERIOD_CURRENT, shiftA1);
if (y<minpr1) {minpr1=y;}} 

if (BuyLimitCount()==0 && BuyCount()==0){
slB=NormalizeDouble(minpr1-pointsl*Point,5);
tpB=NormalizeDouble(minpr1+pointtp*Point,5);
ticketUP=OrderSend(Symbol(), OP_BUYLIMIT, lotB, minpr1, 3, slB, tpB, "", MagicB, 0, Red);
if (ticketUP==-1Print("ERROR OP_BUY"); else Print("OP_BUY OK");}

if (SellLimitCount()==0 && SellCount() ==0){
slS=NormalizeDouble(maxpr1+pointsl*Point,5);
tpS=NormalizeDouble(maxpr1-pointtp*Point,5);
ticketD=OrderSend(Symbol(), OP_SELLLIMIT, lotS, maxpr1, 3, slS, tpS, "", MagicS, 0, Blue);
if (ticketD==-1Print("ERROR OP_SELL"); else Print("OP_SELL OK");}

if (x!=maxpr1){x=maxpr1;
slS=NormalizeDouble(maxpr1+pointsl*Point,5);
tpS=NormalizeDouble(maxpr1-pointtp*Point,5);
OrderModify(ticketD, maxpr1, slS, tpS, 0, Blue);}

if (z!=minpr1){z=minpr1;
slB=NormalizeDouble(minpr1-pointsl*Point,5);
tpB=NormalizeDouble(minpr1+pointtp*Point,5);
OrderModify(ticketUP, minpr1, slB, tpB, 0, Red);}

double maxpr=-9999double minpr=9999;

for(int shift=0; shift<bars; shift++)
{double e=iHigh(Symbol(), PERIOD_CURRENT, shift);
if (e>maxpr){maxpr=e;}}

for(int shiftA=0; shiftA<bars; shiftA++)
{double r=iLow(Symbol(), PERIOD_CURRENT, shiftA);
if (r<minpr) {minpr=r;}} 

string a;
if(bars==1)a="bar: ";
else a= IntegerToString(bars,1) + " bar's: ";
Comment("Last ", a, "max "DoubleToStr(maxpr, 5), ", min "DoubleToStr(minpr, 5),".");
}

int BuyLimitCount(){
int count=0
if(OrderSelect(ticketUP, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}return(count);}

int BuyCount(){
int count=0
if(OrderSelect(ticketUP, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUY)
count++;}}return(count);}

int SellLimitCount(){
int count=0
if(OrderSelect(ticketD, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicS){
if(OrderType()==OP_SELLLIMIT)
count++;}}return(count);}

int SellCount(){
int count=0
if(OrderSelect(ticketD, SELECT_BY_TICKETMODE_TRADES)==true){
if(OrderMagicNumber()==MagicS){
if(OrderType()==OP_SELL)
count++;}}return(count);}


E aqui há um momento - depois que mudei a função de seleção, a função de modificação de ordem começou a gerar um erro e somente após algum tempo detestes, no início tudo estava normal.

Por que isso acontece e como lidar com isso?


Muito provavelmente, você está recebendo este erro porque está tentando modificar um pedido que já foi acionado ou excluído. Você deve limpar as variáveis onde o pedido é armazenado, por exemplo, quando o pedido pendente tiver sido acionado.
 
Sergey Gritsay:
Você provavelmente recebe este erro porque está tentando modificar uma ordem pendente que já foi acionada ou excluída. Você precisa redefinir as variáveis onde o bilhete pendente está armazenado, por exemplo, quando a ordem pendente foi acionada.
Você sabe como fazer isso corretamente? Não tenho idéia de como fazer isso.
 

Olá a todos, ajudem-me a entender o que está errado.

meu Expert Advisor abre ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0, "AV2",1111,0,Green);

feche МТ4, abra МТ4 e confira os trabalhos anteriores da EA

for(int prev=0; prev<OrdersTotal();prev++) //Checking of previous EA operation

{

ViborOrdera=OrderSelect(prev,SELECT_BY_POS);

if(OrderSymbol()==Symbol())

//*************************************

//-------Cheque o ciclo de compras--------

if(OrderType()==OP_BUY && OrderMagicNumber()==1111)

{

PreçoAsk=Preço de Encomenda Aberto();// preço aberto, necessário para o trabalho futuro da EA

}

pergunta, onde está o erro, não há verificação? O corpo do laço está na Inite.

 

Não há tempo para resolver..........

Tente ler e colocar nos lugares certos.

RefreshRates();

///
 
ed3sss:

Olá a todos, ajudem-me a entender o que está errado.

meu Expert Advisor abre ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0, "AV2",1111,0,Green);

feche МТ4, abra МТ4 e confira os trabalhos anteriores da EA


Pergunta, onde está o erro, não há verificação? O corpo do laço está em Inite.

E provar que é o laço que não entra no laço. Além disso, por que verificar TODOS os pedidos, desde o início da vida da conta, se você precisa dos últimos???
 
Mikhail Kozhemyako:

Não há tempo para resolver..........

Tente ler e colocar nos lugares certos.

RefreshRates();

///
Não ajudou(
 
Vitalie Postolache:
E provar que é o ciclo que não está entrando. Além disso, por que devemos verificar TODOS os pedidos desde o início da vida da conta se precisamos dos mais recentes?

Prova: Imprimir("Previous PriceAsk-",PriceAsk); o tronco está vazio.

Além disso, por que devo verificar TODOS os pedidos desde o início da vida da conta, se eu precisar dos mais recentes? - Como fazer isso, se há 10 pares de moedas abertos?


 

Tudo estava bem até mudarmos ViborOrdera=OrderSelect(prev,SELECT_BY_POS) em MQL;

Costumava serOrderSelect(prev,SELECT_BY_POS);. Foi há muito tempo), mas funcionou.

Razão: