Tutte le domande dei nuovi arrivati su MQL4 e MQL5, aiuto e discussione su algoritmi e codici - pagina 35

 

Ecco cosa è venuto fuori.

Sembra determinare il modo giusto a parte

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

Resta la domanda: come combinare tutto questo e l'uscita al buffer 5 e 6.

Grazie!

 

Saluti.

Ho cambiato il tipo di selezione dell'ordine nella funzione scritta del conteggio di certi ordini da selezione per ordine a selezione per biglietto.

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

Dopo di che, quando si eseguono alcune decine di candele, tutto funziona correttamente e dopo ci sono ripetuti errori nel log:

2016.12.17 17:44:31.609 2016.12.07 00:27 test3 EURUSD,M1: ticket 2 sconosciuto per la funzione OrderModify

2016.12.17 17:44:31.608 2016.12.07 00:25 test3 EURUSD,M1: OrderModify error 4108 // Invalid ticket number.

Ecco il testo completo, l'ho cambiato in tutte e quattro le funzioni:

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


Perché succede questo e come affrontarlo?


 
spoiltboy:

Saluti.

Nella funzione scritta per contare certi ordini nella funzione di selezione degli ordini, ho cambiato il tipo di selezione da selezione degli ordini a selezione dei biglietti.

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 dove?
 
Artyom Trishkin:
E dove?
Finito. Grazie per la vostra prontezza.
 
spoiltboy:
Finito. Grazie per la vostra prontezza.
E dov'è? Dov'è la selezione sul biglietto?
 
Artyom Trishkin:
E dove? Dov'è la scelta sul biglietto?

Proprio lì, nel post sopra. O c'è qualcosa che non va?

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:

Proprio lì, nel post sopra. O c'è qualcosa che non va?

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);}
Ti suggerisco di leggere come scegliere il biglietto giusto. Preferibilmente in modo che tu stesso capisca cosa stai facendo. È difficile per me dirvi qualcosa di diverso dal mio cellulare.
 
Artyom Trishkin:
Ti consiglio di leggere come selezionare per biglietto. Sarebbe bene che tu capissi cosa stai facendo. Non posso dirvi altro dal mio cellulare.

Ho letto, non ho trovato alcun errore (ho bisogno dell'aiuto della sala).

E c'è un punto qui - dopo aver cambiato la funzione di selezione, la funzione di modifica dell'ordine ha iniziato a dare un errore e solo qualche tempo dopo aver eseguito il test.

 
spoiltboy:

Ho letto, non ho trovato alcun errore (ho bisogno dell'aiuto della sala).

E c'è un punto qui - dopo aver cambiato la funzione di selezione, la funzione di modifica dell'ordine ha iniziato a generare un errore e solo qualche tempo dopo aver iniziato il test.

Da dove prendete il biglietto d'ordine?
 
Artyom Trishkin:
Da dove prendete il biglietto d'ordine?
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);
Motivazione: