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

 
Perché le citazioni sono di 5 cifre, ma l'indicatore dà valori di 4 cifre? Non c'è nessun arrotondamento o altro
 
Roman Sharanov:
Perché le citazioni sono di 5 cifre, ma l'indicatore dà valori di 4 cifre? Non c'è nessun arrotondamento o altro
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
 
Artyom Trishkin:

grazie

 

Perché la funzione ...

PositionsTotal()

... ...a volte restituisce 0 quando c'è effettivamente una posizione aperta? MQL5


La logica del suo funzionamento dipende da questo

if(trade_p && PositionsTotal() == 0 && trade_o && OrdersTotal() > 0)
     {
      if(Order_Close()) ExpertRemove();
     }

... ecco la prova


 
Buon pomeriggio, potreste dirmi come disabilitare la grafica a scorrimento automatico su Android? ( Meta Treder 4)
 
Salve.

Sto passando un momento difficile. Non posso impostare nella logica dell'indicatore Bolingeer Bunds la regola di disegnare le linee dalla chiusura del giorno precedente.

La funzione iClose("USDCHF",PERIOD_D1,0) sembra essere adatta, ma non del tutto. Quando si ricalcola il ciclo sul grafico orario tutto si rompe immediatamente.

//+------------------------------------------------------------------+
//|                                                       Клюква.mq4 |
//|                                              Алексей Корольков . |
//|                            https://www.mql5.com/ru/users/alekkar |
//+------------------------------------------------------------------+
#property copyright   "2020 Алексей Корольков ."
#property link        "https://www.mql5.com/ru/users/alekkar"
#property description "Клюква"
#property strict

#include <MovingAverages.mqh>

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen
//--- indicator parameters
input int    InpBandsPeriod=20;      // Bands Period
input int    InpBandsShift=0;        // Bands Shift
input double InpBandsDeviations=2.0; // Bands Deviations
input string SimbolUSD="USDIDX..";
//--- buffers
double ExtMovingBuffer[];
double ExtUpperBuffer[];
double ExtLowerBuffer[];
double ExtStdDevBuffer[];
double Drv,DrvIn,min,max,minIn,maxIn,xx,xIn,natr,natrIn,ma1,ma2,bid1,bid2,R1,R2,R01,R02;
int tm,mn;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- 1 additional buffer used for counting.
   IndicatorBuffers(4);
   IndicatorDigits(Digits);
//--- middle line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMovingBuffer);
   SetIndexShift(0,InpBandsShift);
   SetIndexLabel(0,"Bands SMA");
//--- upper band
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtUpperBuffer);
   SetIndexShift(1,InpBandsShift);
   SetIndexLabel(1,"Bands Upper");
//--- lower band
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtLowerBuffer);
   SetIndexShift(2,InpBandsShift);
   SetIndexLabel(2,"Bands Lower");
//--- work buffer
   SetIndexBuffer(3,ExtStdDevBuffer);
//--- check for input parameter
   if(InpBandsPeriod<=0)
     {
      Print("Wrong input parameter Bands Period=",InpBandsPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(0,InpBandsPeriod+InpBandsShift);
   SetIndexDrawBegin(1,InpBandsPeriod+InpBandsShift);
   SetIndexDrawBegin(2,InpBandsPeriod+InpBandsShift);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Bollinger Bands                                                  |
//+------------------------------------------------------------------+
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 i,pos;
//---
   if(rates_total<=InpBandsPeriod || InpBandsPeriod<=0)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtMovingBuffer,false);
   ArraySetAsSeries(ExtUpperBuffer,false);
   ArraySetAsSeries(ExtLowerBuffer,false);
   ArraySetAsSeries(ExtStdDevBuffer,false);
   ArraySetAsSeries(close,false);
//--- initial zero
   if(prev_calculated<1)
     {
      for(i=0; i<InpBandsPeriod; i++)
        {
         ExtMovingBuffer[i]=EMPTY_VALUE;
         ExtUpperBuffer[i]=EMPTY_VALUE;
         ExtLowerBuffer[i]=EMPTY_VALUE;
         
        }
     }
//--- определение АТР  
for(i=InpBandsPeriod-1; i>=0; i--)
        {
         xx=High[i]-Low[i];
         Drv+=xx;
         if(min>xx) min=xx;
         if(max<xx) max=xx;
         xIn=iHigh(SimbolUSD,NULL,i)-iLow(SimbolUSD,NULL,i);
         DrvIn+=xIn;
         if(minIn>xIn) minIn=xIn;
         if(maxIn<xIn) maxIn=xIn; 
        }   
 Drv/=InpBandsPeriod;
 DrvIn/=InpBandsPeriod;
 natr=((Drv-min)/(max-min))*100; //тут определяем пройденное значение атр инструментом на графике
 natrIn=((DrvIn-minIn)/(maxIn-minIn))*100; //тут определяем пройденное значение атр инструментом на индексе доллара
 //средние АТР
 ma1=iMA(NULL,0,InpBandsPeriod,0,2,1,0);
 ma2=iMA(SimbolUSD,0,InpBandsPeriod,0,2,1,0); 
 //определяем знак АТР
 bid1=MarketInfo(NULL,MODE_BID);
 bid2=MarketInfo(SimbolUSD,MODE_BID);
 if (bid1-ma1<0) Drv=Drv*(-1); // если цена падает значит минус
 if (bid2-ma2<0) DrvIn=DrvIn*(-1); // если цена падает значит минус
 
 // а теперь сама она родная 
 //где Drv инструмент графика,а DrvIn индекс доллара
 //расчёт индекса волатильности для инструмента
 R01 = (1-(1+Drv)/(1+max))*100;//используем для движения вверх
 R02 = (1-(1-Drv)/(1+max))*100;//используем для движения вниз
 //расчёт индекса волатильности для доллара
 R1 = (1-(1+DrvIn)/(1+maxIn))*100;// 
 R2 = (1-(1-DrvIn)/(1+maxIn))*100;//используем для движения вниз 
 // далее сам расчёт
 
 
         
     
//--- начальный расчет
   if(prev_calculated>1)
      pos=prev_calculated-1;
   else
      pos=0;
//--- главный цикл
   for(i=pos; i<rates_total && !IsStopped(); i++)
     { 
      //--- средняя линия
      ExtMovingBuffer[i]=SimpleMA(i,InpBandsPeriod,close);
      //--- рассчитайте и запишите со стандартным отклонением
      ExtStdDevBuffer[i]=StdDev_Func(i,close,ExtMovingBuffer,InpBandsPeriod); // тут наверно смогу разместить код 
      //--- верхняя линия указывает зону перекупленности
     // -- тут хотел параметр ExtMovingBuffer[i] заменить на  iClose("USDCHF",PERIOD_D1,0)
      ExtUpperBuffer[i]=ExtMovingBuffer[i]+(max)*(R01+R2)/2; //Print("Drv ",Drv,",DrvIn",DrvIn,", R1", R1,", R2 ", R2);
      //--- нижняя линия указывает зону перепроданности
      ExtLowerBuffer[i]=ExtMovingBuffer[i]+(-max)*(R02+R1)/2; 
      //---
     }
//---- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Calculate Standard Deviation                                     |
//+------------------------------------------------------------------+
double StdDev_Func(int position,const double &price[],const double &MAprice[],int period)
  {
//--- variables
   double StdDev_dTmp=0.0;
//--- check for position
   if(position>=period)
     {
      //--- calcualte StdDev
      for(int i=0; i<period; i++)
         StdDev_dTmp+=MathPow(price[position-i]-MAprice[position],2);
      StdDev_dTmp=MathSqrt(StdDev_dTmp/period);
     }
//--- return calculated value
   return(StdDev_dTmp);
  }
//+------------------------------------------------------------------+




Grazie per l'aiuto

Aliaksei Karalkou
Aliaksei Karalkou
  • www.mql5.com
Опубликовал MetaTrader 4 сигнал Выставил продукт Советник DSvoltage  использует индикатор MACD. Торговый объём зависит от результата предыдущих сделок, фиксированного лота, и размера показателя Автолота. Советник DCvoltage хеджирует размер позиции и направление в зависимости от ситуации на рынке за счёт перекрытых ордеров. В советнике...
 

Buon pomeriggio.

C'è una domanda sui file binari: c'è un modo per tagliare le loro code?

 
Yurij Kozhevnikov:

Buon pomeriggio.

Ecco una domanda sui file binari: c'è un modo per tagliare le loro code?

filename = "эта@с_хвостом.bin";

nome del file = "a_et@tailless";

)))

O a quale coda si riferiva?

 
Сергей Таболин:

filename = "эта@с_хвостом.bin";

filename = "a_ta@no_tail";

)))

O a quale coda si riferiva?

Potete spostare il puntatore intorno ai file binari e leggere e scrivere da qualsiasi punto. C'è un modo per cancellare, cancellare, dal punto corrente alla fine del file? È possibile scrivere un segno della fine del file? Si può ridurre? Senza sovrascrittura.

 
Yurij Kozhevnikov:

Buon pomeriggio.

C'è una domanda sui file binari: è possibile in qualche modo tagliare la loro coda?

non puoi

Cercate un argomento nella sezione 4. C'era una domanda simile circa una settimana fa e qualcuno ha suggerito una soluzione con la chiamata WinAPI (.dll)