[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate. Non posso andare da nessuna parte senza di te. - pagina 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];}
}
Per favore, aiutatemi.

Se durante il test visivo dell'EA 1.mq4 (allegato) metto su un grafico l'indicatore 3-cci-h3 (allegato), allora, come sembrerebbe, con esattamente gli stessi parametri di segnali cci calcolati dell'indicatore e il cci reale (oggetto testo in alto a destra) non coincidono.

PERCHE'?

Perché gli avvisi non funzionano in questo indicatore?

Codice Expert Advisor:





Codice indicatore:

//+------------------------------------------------------------------+
//| i-3CCI-h.mq4 |
//| johnfantom & kimIV |
//| http://www.kimiv.ru |
//| |
//| 02.01.2006 CCI con 3 TF in una bottiglia.
//+------------------------------------------------------------------+
#proprietà copyright "johnfantom & KimIV"
#proprietà link "http://www.kimiv.ru"

#proprietà indicator_separate_window
#proprietà indicator_buffers 1
#property indicator_color1 DodgerBlue
#proprietà indicator_maximum 1.4
#proprietà indicatore_livello1 0
#proprietà indicatore_minimo -1,2

//------- Parametri dell'indicatore esterno -------------------------------
extern int CCI_Period_0 = 14; // periodo CCI per il timeframe corrente
extern int Level_0 = 100; // Livello CCI per il TF corrente
extern int TF_1 = 60; // Numero di minuti nel primo intervallo di tempo
extern int CCI_Period_1 = 14; // periodo CCI per il primo TF
extern int Level_1 = 100; // livello CCI per il primo TF
extern int TF_2 = 240; // Numero di minuti del secondo TF
extern int CCI_Period_2 = 14; // periodo CCI per il secondo TF
extern int Level_2 = 100; // livello CCI per il secondo TF
extern int NumberOfBars = 1000; // Numero di barre (0-All)
extern int ExtBars = 3;
int per;


//------- Buffer indicatori ------------------------------------------
doppio buf0[];

//+------------------------------------------------------------------+
//| funzione di inizializzazione dell'indicatore personalizzato
//+------------------------------------------------------------------+
void init() {
IndicatoreCifre(1);

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

//+------------------------------------------------------------------+
//| funzione di deinizializzazione dell'indicatore personalizzata
//+------------------------------------------------------------------+
void deinit() {
Commento(");
}

//+------------------------------------------------------------------+
//| funzione di iterazione dell'indicatore personalizzata
//+------------------------------------------------------------------+
void start() {
doppio cci0,cci1,cci2;
int nb1, nb2; count;
int LoopBegin, sh;


if (NumberOfBars==0) LoopBegin=Bars-1;
else LoopBegin=NumberOfBars-1;
LoopBegin=MathMin(Bars-1, LoopBegin);
count=IndicatorCounted();
per (sh=conteggio; 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);
/* doppio cci[3];
cci[0]=cci0;
cci[1]=cci1;
cci[2]=cci2;
stringa s1="cci-0 ***"+DoubleToStr(cci[0],3);
stringa s2="cci-1 ***"+DoubleToStr(cci[1],3);
stringa s3="cci-2 ***"+DoubleToStr(cci[2],3);
stringa 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)
ObjectSet("textSignal "+y,OBJPROP_CORNER,1);
ObjectSet("textSignal "+y,OBJPROP_XDISTANCE,35-25);
ObjectSet("textSignal "+y,OBJPROP_YDISTANCE,y*(20)+20+8);
se(cci[y]>=0)col=Lime; altrimenti col=Red;
se(cci[y]>Livello_0) col=Aqua;
if(cci[y]<-Level_0) col=DarkViolet;
ObjectSetText("textSignal "+y,str[y],15, "Tahoma",col);
}
*/
if (cci0>Level_0 && cci1>Level_1 && cci2>Level_2) {buf0[sh]=1;
if (per != Time[0]) {per = Time[0];
if(sh<=ExtBars && ExtBars!=-1)
Alert(Symbol(),Period()," ",
TimeYear(Time[sh]),",
TimeDay(Time[sh]),",
TimeMonth(Time[sh]),",
TimeHour(Time[sh]),":",
TimeMinute(Time[sh]),",
"Acquisto");}}
if (cci0<-Level_0 && cci1<-Level_1 && cci2<-Level_2) {buf0[sh]=-1;
if (per != Time[0]) {per = Time[0];
if(sh<=ExtBars && ExtBars!=-1)
Alert(Symbol(),Period()," ",
TimeYear(Time[sh]),",
TimeDay(Time[sh]),",
TimeMonth(Time[sh]),",
TimeHour(Time[sh]),":",
TimeMinute(Time[sh])," ",
"Vendita");}}
}
}
//+------------------------------------------------------------------+
 

Provate da soli, io non riesco proprio a farlo funzionare. Non funziona affatto.

Le linee dovrebbero essere allineate. Ma in pratica è un po' diverso.

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);
  }
 

Potete dirmi per favore cosa potrebbe essere sbagliato?

Ho fatto una funzione ricorsiva che scrive un valore nel buffer.

Quando è chiamato da indictor funziona bene, quando ho provato a metterlo in EA, la risposta è 0

Quale può essere il problema?

 
Andrej78 писал(а) >>

Potete dirmi per favore cosa potrebbe essere sbagliato?

Ho fatto una funzione ricorsiva che scrive un valore nel buffer.

Quando è chiamato da indictor funziona bene, quando ho provato a metterlo in EA, la risposta è 0

Quale può essere il problema?

forse la dimensione del buffer non è impostata?

 

Ho trovato dove si verifica l'intoppo.

Risulta che IndicatorCounted dà 0 nell'indicatore e -1 nell'Expert Advisor (questa funzione ha un controllo di correttezza - essere >=0, quindi non è considerata nell'Expert Advisor)

Qual è la ragione e come risolvere l'errore?

MT4 build 225, eurusd M1.

 
Andrej78 писал(а) >>

Ho trovato dove si verifica l'intoppo.

Risulta che IndicatorCounted dà 0 nell'indicatore e -1 nell'Expert Advisor (questa funzione ha un controllo di correttezza - essere >=0, quindi non è considerata nell'Expert Advisor)

Qual è la ragione e come risolvere l'errore?

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);
}

Qual è l'errore nel codice di registrazione 4051 non giusto ticket quando si chiude un ordine per favore consigliare?
 
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);
}

Qual è il bug nel codice di registrazione 4051 non è un biglietto valido quando si chiude un ordine, per favore consiglia?

L'apertura e la chiusura avvengono su tick diversi. E l'Expert Advisor non ricorda più cosa è stato assegnato alla variabile t. O dovrebbe essere globale o statico.

Una variabile globale è definita al di fuori delle funzioni. Oppure può essere dichiarato come int statico

 
Vinin >> :

L'apertura e la chiusura avvengono su tick diversi. E l'Expert Advisor non ricorda più cosa è stato assegnato alla variabile t. O dovrebbe essere globale o statico.

Una variabile globale è definita al di fuori delle funzioni. Oppure può essere dichiarato come int statico

grazie mille, l'avevo dimenticato ))

 

Nell'indicatore che ho impostato (per poi confrontarli con Time[i]):

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


Poi nel ciclo

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


Di conseguenza, StrToTime(StartRange) e StrToTime(EndRange) producono degli zeri .

- Perché e come risolvere il problema?

Motivazione: