[¡AVISO CERRADO!] Cualquier pregunta de novato, para no saturar el foro. Profesionales, no pasen. No puedo ir a ningún sitio sin ti. - página 160

 
extern double SL=100, TP=200, Tral=0, steps=2, Level=100;
extern int TF1=0, TF2=60, TF3=240, per1=14, per2=14, per3=14, shiftbars=20;
double sl, tp, cci[3], lastbar, lastpos=-1, lot=0.1, x=0.0001, calc, price, lb;
int init(){if( SL< Tral) SL= Tral;if(MarketInfo(Symbol(),MODE_DIGITS)==3) x=0.01; TP*= x; SL*= x; Tral*= x; calc=MathPow(2, steps)*0.1;}

double lot(){int l;double lotiki=0.1;bool isit=false;
for(int i=1; i<= steps; i++){
if(!OrderSelect(OrdersHistoryTotal()- i, SELECT_BY_POS, MODE_HISTORY))break;
if(OrderProfit()>0) lotiki*=2; l++;
if(OrderLots()== calc) { isit=true;break;}
if(OrderProfit()<0) break;}
if( l== steps+1 || isit) lotiki=0.1;
return( lotiki);}

int Trailing()
{double Tip, SL1;
for(int i=OrdersTotal()-1; i>=0; i--){
OrderSelect( i, SELECT_BY_POS);if(OrderMagicNumber()==350000){
Tip=OrderType(); SL1=OrderStopLoss();
if( Tip==0) {if(Bid- SL1> Tral) {OrderModify(OrderTicket(),OrderOpenPrice(),Bid- Tral,OrderTakeProfit(),0);break;}}
if( Tip==1) {if( SL1-Ask> Tral) {OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ Tral,OrderTakeProfit(),0);break;}}
}}}

int Closeorders(){
for(int i=OrdersTotal()-1; i>=0; i--){OrderSelect( i, SELECT_BY_POS);if(OrderMagicNumber()==350000)
{if(OrderType()==0) price=Bid;else price=Ask; OrderClose(OrderTicket(),OrderLots(), price,50);break;}}
}
void start(){
//if(iBarShift(NULL,0,lastbar,false)==0)return;
//lastbar=CurTime();
if(OrdersTotal()!=0 && Tral!=0){ Trailing();}
//cci=iCustom(NULL,0,"i-3CCI-h3",CCI_Period_0,Level_0,TF_1,CCI_Period_1,Level_1,TF_2,CCI_Period_2,Level_2,1000,-1,0,0);
cci[0]=iCCI(NULL, TF1, per1,0,1);
cci[1]=iCCI(NULL, TF2, per2,0,0);
cci[2]=iCCI(NULL, TF3, per3,0,0);
string s1="cci-0 *** "+DoubleToStr( cci[0],3);
string s2="cci-1 *** "+DoubleToStr( cci[1],3);
string s3="cci-2 *** "+DoubleToStr( cci[2],3);
string str[3];
str[0]= s1;
str[1]= s2;
str[2]= s3;
color col=Lime;
     for(int y=0; y<3; y++)
     {ObjectCreate("textSignal"+ y,OBJ_LABEL,0,0,0,0,0);    
      ObjectSet("textSignal"+ y, OBJPROP_CORNER,1);
      ObjectSet("textSignal"+ y, OBJPROP_XDISTANCE,35-25);
      ObjectSet("textSignal"+ y, OBJPROP_YDISTANCE, y*(20)+20+8);
      if( cci[ y]>=0) col=Lime;else col=Red;
      if( cci[ y]> Level) col=Aqua;
      if( cci[ y]<- Level) col=DarkViolet;
      ObjectSetText("textSignal"+ y, str[ y],15,"Tahoma", col);
     }
if(OrdersTotal()!=0)return;
if( cci[0]> Level && cci[1]> Level && cci[2]> Level && (/*iBarShift(NULL,0,lb,false)>shiftbars || */ lastpos!=0))
{ Closeorders(); tp=Ask+ TP; sl=Ask- SL;if( TP==0) tp=0;if( SL==0) sl=0;
OrderSend(Symbol(),0, lot(),Ask,50, sl, tp,"i-3CCI-h3_Buy",350000,0); lastpos=0; lb=Time[0];}
if( cci[0]<- Level && cci[1]<- Level && cci[2]<- Level && (/*iBarShift(NULL,0,lb,false)>shiftbars || */ lastpos!=1))
{ Closeorders(); tp=Bid- TP; sl=Ask+ SL;if( TP==0) tp=0;if( SL==0) sl=0;
OrderSend(Symbol(),1, lot(),Bid,50, sl, tp,"i-3CCI-h3_Sell",350000,0); lastpos=1; lb=Time[0];}
}
Por favor, ayuda.

Si durante la prueba visual del EA 1.mq4 (adjunto) pongo en un gráfico el indicador 3-cci-h3 (adjunto), entonces, como parecería, con exactamente los mismos parámetros de señales cci calculadas del indicador y el cci real (texto del objeto en la esquina superior derecha) no coinciden.

¿POR QUÉ?

¿Por qué no funcionan las alertas en este indicador?

Código de asesor experto:





Código del indicador:

//+------------------------------------------------------------------+
//| i-3CCI-h.mq4 ||
//| johnfantom & KimIV |
//| http://www.kimiv.ru |
//| |
//| 02.01.2006 CCI con 3 TF en una botella. ||
//+------------------------------------------------------------------+
#property copyright "johnfantom & KimIV"
#enlace de propiedad "http://www.kimiv.ru"

#property indicador_separar_ventana
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#propiedad indicador_máximo 1.4
#property indicator_level1 0
#propiedad indicador_mínimo -1.2

//------- Parámetros del indicador externo -------------------------------
extern int CCI_Period_0 = 14; // Periodo del CCI para el marco temporal actual
extern int Nivel_0 = 100; // Nivel del CCI para la TF actual
extern int TF_1 = 60; // Número de minutos en la primera franja de tiempo
extern int CCI_Period_1 = 14; // Periodo CCI para la primera TF
extern int Nivel_1 = 100; // Nivel CCI para la primera TF
extern int TF_2 = 240; // Número de minutos del segundo TF
extern int CCI_Period_2 = 14; // Periodo del CCI para la segunda TF
extern int Nivel_2 = 100; // Nivel de CCI para la segunda TF
extern int NumberOfBars = 1000; // Número de barras (0-Todas)
extern int ExtBars = 3;
int por;


//------- Buffer de indicadores ------------------------------------------
doble buf0[];

//+------------------------------------------------------------------+
//| Función de inicialización de indicadores personalizada |
//+------------------------------------------------------------------+
void init() {
IndicadorDígitos(1);

SetIndexBuffer(0, buf0);
SetIndexLabel(0, "i-3CCI-h");
SetIndexStyle (0, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexEmptyValue(0, 0);
}

//+------------------------------------------------------------------+
//| Función de desinicialización de indicadores personalizada |
//+------------------------------------------------------------------+
void deinit() {
Comentario(");
}

//+------------------------------------------------------------------+
//| Función de iteración de indicadores personalizada |
//+------------------------------------------------------------------+
void start() {
doble cci0,cci1,cci2;
int nb1, nb2; count;
int InicioDeBucle, sh;


if (NumberOfBars==0) LoopBegin=Bars-1;
else LoopBegin=NúmeroDeBarras-1;
LoopBegin=MathMin(Bars-1, LoopBegin);
count=IndicadorContado();
for (sh=cuenta; sh>=0; sh--) {
nb1=iBarShift(NULL, TF_1, Time[sh+1], False);
nb2=iBarShift(NULL, TF_2, Time[sh+1], False);

cci0=iCCI(NULL, 0, CCI_Period_0, PRICE_CLOSE, sh+1);
cci1=iCCI(NULL, TF_1, CCI_Period_1, PRICE_CLOSE, nb1);
cci2=iCCI(NULL, TF_2, CCI_Period_2, PRICE_CLOSE, nb2);
/* doble cci[3];
cci[0]=cci0;
cci[1]=cci1;
cci[2]=cci2;
string s1="cci-0 ***"+DoubleToStr(cci[0],3);
string s2="cci-1 ***"+DoubleToStr(cci[1],3);
string s3="cci-2 ***"+DoubleToStr(cci[2],3);
cadena str[3];
str[0]=s1;
str[1]=s2;
str[2]=s3;
color col=Lima;
for(int y=0;y<3;y++)
{ObjectCreate("señaldetexto "+y,OBJ_LABEL,0,0,0)
ObjectSet("señal de texto "+y,OBJPROP_CORNER,1);
ObjectSet("textSignal "+y,OBJPROP_XDISTANCE,35-25);
ObjectSet("textSignal "+y,OBJPROP_YDISTANCE,y*(20)+20+8);
if(cci[y]>=0)col=Lima;else col=Rojo;
if(cci[y]>Nivel_0) col=Aqua;
if(cci[y]<Nivel_0) col=VioletaOscuro;
ObjectSetText("textoSeñal "+y,str[y],15, "Tahoma",col);
}
*/
if (cci0>Nivel_0 && cci1>Nivel_1 && cci2>Nivel_2) {buf0[sh]=1;
if (per != Time[0]) {per = Time[0];
if(sh<=ExtBars && ExtBars!=-1)
Alert(Symbol(),Period()," ",
TiempoAño(Tiempo[sh]),",
TimeDay(Time[sh]),",
TimeMonth(Time[sh]),",
TiempoHora(Tiempo[sh]),":",
TimeMinute(Time[sh]),",
"Compra");}}
if (cci0<-Nivel_0 && cci1<-Nivel_1 && cci2<-Nivel_2) {buf0[sh]=-1;
if (per != Time[0]) {per = Time[0];
if(sh<=ExtBars && ExtBars!=-1)
Alert(Symbol(),Period()," ",
TiempoAño(Tiempo[sh]),",
TimeDay(Time[sh]),",
TimeMonth(Time[sh]),",
TiempoHora(Tiempo[sh]),":",
TimeMinute(Time[sh]),",
"Venta");}}
}
}
//+------------------------------------------------------------------+
 

Pruébalo por tu cuenta. Yo no consigo que funcione en absoluto. No funciona en absoluto.

Las líneas deben estar alineadas. Pero en la práctica es un poco diferente.

int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   ObjectCreate("fibowhite",OBJ_TRENDBYANGLE,0,0,0,0,0);
   //ObjectSet("fibowhite",OBJPROP_ANGLE,angle_);
   ObjectSet("fibowhite", OBJPROP_TIME1,Time[5]);
   ObjectSet("fibowhite", OBJPROP_TIME2,Time[1]);
   ObjectSet("fibowhite", OBJPROP_PRICE1,Low[5]);
   ObjectSet("fibowhite", OBJPROP_PRICE2,Low[1]);
   ObjectSet("fibowhite", OBJPROP_COLOR,Red);
   //----------------------------------------------------------
   ObjectCreate("fibowhite1",OBJ_TRENDBYANGLE,0,0,0,0,0);
   ObjectSet("fibowhite1", OBJPROP_TIME1,Time[5]);
   //ObjectSet("fibowhite1",OBJPROP_TIME2,Time[1]);
   ObjectSet("fibowhite1", OBJPROP_PRICE1,Low[5]);
   //ObjectSet("fibowhite1",OBJPROP_PRICE2,Low[1]);
   ObjectSet("fibowhite1", OBJPROP_COLOR,Green);
   WindowRedraw();
   double awd=ObjectGet("fibowhite", OBJPROP_ANGLE);
   Comment("AngleRED= ",ObjectGet("fibowhite", OBJPROP_ANGLE),"\n AngleWHITE= ",ObjectGet("fibowhite1", OBJPROP_ANGLE));
   ObjectSet("fibowhite1", OBJPROP_ANGLE,ObjectGet("fibowhite", OBJPROP_ANGLE));
   
//----
   return(0);
  }
 

¿Puede decirme qué puede estar mal?

Hice una función recursiva que escribe un valor en el buffer.

Cuando se llama desde el indicador funciona bien, cuando intenté ponerlo en el EA, la respuesta es 0

¿Cuál puede ser el problema?

 
Andrej78 писал(а) >>

¿Puede decirme qué puede estar mal?

Hice una función recursiva que escribe un valor en el buffer.

Cuando se llama desde el indicador funciona bien, cuando intenté ponerlo en el EA, la respuesta es 0

¿Cuál puede ser el problema?

¿¡Tal vez el tamaño del buffer no está ajustado!?

 

He encontrado donde se produce el enganche.

Resulta que IndicatorCounted da 0 en el indicador y -1 en el Asesor Experto (esta función tiene comprobación de corrección - ser >=0, por lo tanto no se considera en el Asesor Experto)

¿Cuál es el motivo y cómo se soluciona el error?

MT4 build 225, eurusd M1.

 
Andrej78 писал(а) >>

He encontrado donde se produce el enganche.

Resulta que IndicatorCounted da 0 en el indicador y -1 en el Asesor Experto (esta función tiene comprobación de corrección - ser >=0, por lo tanto no se considera en el Asesor Experto)

¿Cuál es el motivo y cómo se soluciona el error?

MT4 build 225, eurusd M1.

https://docs.mql4.com/ru/customind

 

if (k>k1+7 && s<(High[1]-(High[1]-Low[1])/2) && bay==true)
{
int t=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,NULL,NULL,"My order #",16384,0,Green);
bay=false;
Print (GetLastError());
}
}
if (s>(High[0]-(High[0]-Low[0])/2) && bay==false)
{
OrderSelect(t,SELECT_BY_TICKET,MODE_TRADES);
Print (GetLastError());
OrderClose(t,0.1,Ask,5,Red);
}

¿Cuál es el error en el código de registro 4051 no es el ticket correcto cuando se cierra una orden, por favor aconsejar?
 
evgenio писал(а) >>

if (k>k1+7 && s<(High[1]-(High[1]-Low[1])/2) && bay==true)
{
int t=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,NULL,NULL,"My order #",16384,0,Green);
bay=false;
Print (GetLastError());
}
}
if (s>(High[0]-(High[0]-Low[0])/2) && bay==false)
{
OrderSelect(t,SELECT_BY_TICKET,MODE_TRADES);
Print (GetLastError());
OrderClose(t,0.1,Ask,5,Red);
}

¿Cuál es el error en el código de registro 4051 no es un billete válido al cerrar una orden por favor aconsejar?

La apertura y el cierre tienen lugar en diferentes ticks. Y el Asesor Experto ya no recuerda lo que se asignó a la variable t. Debe ser global o estática.

Una variable global se define fuera de las funciones. O puede declararse como static int

 
Vinin >> :

La apertura y el cierre tienen lugar en diferentes ticks. Y el Asesor Experto ya no recuerda lo que se asignó a la variable t. Debe ser global o estática.

Una variable global se define fuera de las funciones. O puede declararse como static int

muchas gracias, lo había olvidado ))

 

En el Indicador que puse (para luego compararlos con el Tiempo[i]):

extern datetime StartRange          = D'1970.12.24';
extern datetime EndRange            = D'2020.12.24';


Luego, en el bucle

   Comment(
      "\n", "Time[i]                = "   , Time[ i],
      "\n", "StrToTime(StartRange)  = "   , StrToTime( StartRange),
      "\n", "StrToTime(EndRange)    = "   , StrToTime( EndRange),
   "\n" );


Como resultado, StrToTime (StartRange) y StrToTime(EndRange) producen ceros .

- ¿Por qué y cómo solucionarlo?

Razón de la queja: