Quaisquer perguntas de recém-chegados sobre MQL4 e MQL5, ajuda e discussão sobre algoritmos e códigos - página 35

 

Eis o que veio à tona.

Parece determinar o caminho certo para a separação

#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots   6
//--- plot UpBar
#property indicator_label1  "UpBar"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot DnBar
#property indicator_label2  "DnBar"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrDeepPink
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

//--- plot UpFr
#property indicator_label3  "UpFr"
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot DnFr
#property indicator_label4  "DnFr"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1

//--- plot UpBarFr
#property indicator_label5  "UpBarFr"
#property indicator_type5   DRAW_ARROW
#property indicator_color5  clrBlue
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1
//--- plot DnBarFr
#property indicator_label6  "DnBarFr"
#property indicator_type6   DRAW_ARROW
#property indicator_color6  clrRed
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1

//--- input parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
input string          cSymbol   = "AUDCAD";
input int             CountBar  = 5; // Баров подряд

//--- indicator buffers
double BufferUPb[];
double BufferDNb[];
double BufferUPf[];
double BufferDNf[];
double BufferUPbf[];
double BufferDNbf[];

//--- global variables
double open1=0,close1=0,open2=0,close2=0;
double frDn=0,frUp=0,frUp1=0,frUp2=0,frUp3=0,frDn1=0,frDn2=0,frDn3=0;
string dSymbol;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
dSymbol=cSymbol==""?_Symbol:cSymbol;
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUPb);
   SetIndexBuffer(1,BufferDNb);
   SetIndexBuffer(2,BufferUPf);
   SetIndexBuffer(3,BufferDNf);
   SetIndexBuffer(4,BufferUPbf);
   SetIndexBuffer(5,BufferDNbf);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   SetIndexArrow(0,233);
   SetIndexArrow(1,234);
   SetIndexArrow(2,221);
   SetIndexArrow(3,222);
   SetIndexArrow(4,108);
   SetIndexArrow(5,108);
//---
   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[])
{
//---
int    b=1,s=1;

if(rates_total<2) return(0);
int limit=rates_total-prev_calculated;
  if(limit>1) {
   limit=rates_total-2;
    ArrayInitialize(BufferUPb,EMPTY_VALUE);
    ArrayInitialize(BufferDNb,EMPTY_VALUE);
    ArrayInitialize(BufferUPf,EMPTY_VALUE);
    ArrayInitialize(BufferDNf,EMPTY_VALUE);
    ArrayInitialize(BufferUPbf,EMPTY_VALUE);
    ArrayInitialize(BufferDNbf,EMPTY_VALUE);
  }
  
for(int i=limit; i>=0; i--) {

//--------------------------------------------------------------
  open1=iOpen(dSymbol, TimeFrame, i);
  close1=iClose(dSymbol, TimeFrame, i);
  open2= iOpen(dSymbol, TimeFrame, i+1);
  close2= iClose(dSymbol, TimeFrame, i+1);
  
  if(open2<close2 && open1<close1 && open2<open1) {
    b++;
    if(b==CountBar) {
      BufferUPb[i]=Low[i]-200*_Point;
      b=1;
    }
   } else { b=1;}

//---
  if(open2>close2 && open1>close1 && open2>open1) {
    s++;
    if(s==CountBar) {
      BufferDNb[i]=High[i]+200*_Point;
      s=1;
    }
   } else { s=1;}

//--------------------------------------------------------------
  frDn=iFractals(dSymbol, TimeFrame, MODE_LOWER, i);
  if(frDn!=0) {
    frDn1=frDn;
   }
//-
  if(frDn3 > frDn2 && frDn2 < frDn1) {
    BufferUPf[i]=Low[i]-200*_Point;
  }

  if(frDn2!=frDn3 && frDn2!=frDn1) { frDn3=frDn2;} frDn2=frDn1;
  
//---
  frUp=iFractals(dSymbol, TimeFrame, MODE_UPPER, i);
  if(frUp!=0) {
    frUp1=frUp;
   }
//-
  if(frUp3 < frUp2 && frUp2 > frUp1) {
    BufferDNf[i]=High[i]+200*_Point;
  }

  if(frUp2!=frUp3 && frUp2!=frUp1) { frUp3=frUp2;} frUp2=frUp1;

//--------------------------------------------------------------

//-
  if(/*что сюда*/) {
    BufferUPbf[i]=Low[i]-200*_Point;
  }
  
//-
  if(/*что сюда*/) {
    BufferDNbf[i]=High[i]+200*_Point;
  }


//------------
  } // end for
//--- return value of prev_calculated for next call
   return(rates_total);
}
//--------------------------------------------------------------

A questão permanece: como combinar tudo isso e a saída para amortecer 5 e 6.

Obrigado!

 

Saudações.

Mudei o tipo de seleção de ordem 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_POS, MODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}}return(count);}  

int BuyLimitCount(){
int count=0;
if(OrderSelect(ticketUP, SELECT_BY_TICKET, MODE_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 test3 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=0; int ticketUP, ticketD;


void OnTick()  
{
double maxpr1=-9999; double 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==-1) Print("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==-1) Print("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=-9999; double 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_TICKET, MODE_TRADES)==true){
if(OrderMagicNumber()==MagicB){
if(OrderType()==OP_BUYLIMIT)
count++;}}return(count);}

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

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

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


Por que isso acontece e como lidar com isso?


 
spoiltboy:

Saudações.

Na função escrita para contar determinadas ordens na função de seleção de ordens, mudei o tipo de seleção de ordem para seleção de bilhetes.

int BuyLimitCount(){

int count=0;

for(int i=OrdersTotal()-1; i>=0; i--){

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true){

if(OrderMagicNumber()==MagicB){

if(OrderType()==OP_BUYLIMIT)

count++;}}}return(count);}  
E onde?
 
Artyom Trishkin:
E onde?
Acabado. Obrigado por sua prontidão.
 
spoiltboy:
Acabado. Obrigado por sua prontidão.
E onde está? Onde está a seleção no bilhete?
 
Artyom Trishkin:
E onde? Onde está a escolha no bilhete?

Bem ali, no posto acima. Ou há algo errado?

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

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

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

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

Bem ali, no posto acima. Ou há algo errado?

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

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

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

int SellCount(){
int count=0;
if(OrderSelect(ticketD, SELECT_BY_TICKET, MODE_TRADES)==true){
if(OrderMagicNumber()==MagicS){
if(OrderType()==OP_SELL)
count++;}}return(count);}
Sugiro que você leia sobre como pegar o bilhete certo. De preferência, para que você mesmo entenda o que está fazendo. É difícil para mim dizer-lhe algo diferente do meu celular.
 
Artyom Trishkin:
Aconselho você a ler como selecionar por bilhete. Seria bom se você entendesse o que está fazendo. Não posso lhe dizer mais nada do meu celular.

Estive lendo, não consegui encontrar nenhum erro (preciso de ajuda do salão).

E há um ponto aqui - depois de mudar a função de seleção, a função de modificação de ordem começou a dar um erro e somente algum tempo depois de executar o teste.

 
spoiltboy:

Estive lendo, não consegui encontrar nenhum erro (preciso de ajuda do salão).

E há um ponto aqui - após alterar a função de seleção, a função de modificação do pedido começou a gerar um erro e somente algum tempo após o início do teste.

De onde você obtém o bilhete de pedido?
 
Artyom Trishkin:
De onde você obtém o bilhete de pedido?
ticketUP=OrderSend(Symbol(), OP_BUYLIMIT, lotB, minpr1, 3, slB, tpB, "", MagicB, 0, Red);

ticketD=OrderSend(Symbol(), OP_SELLLIMIT, lotS, maxpr1, 3, slS, tpS, "", MagicS, 0, Blue);
Razão: