Questions from a "dummy" - page 266

 
amidmir:
What is the exchange rate of the credits?

1 credit = $1

 
DC2008:

Use dynamic arrays or change the dimensionality of static arrays:

Thank you very much!
 

I'm trying to find the price of the last fractal in the EA, but it's not working...

int Fractals;
double UpVal[];
double DnVal[];
Fractals=iFractals(Symbol(),TimeFrame);
if(Fractals==INVALID_HANDLE) Print("HandleError = ",_LastError);
double FractalUp()
{
//-----
  CopyBuffer(Fractals,0,0,5,UpVal);
  ArraySetAsSeries(UpVal,true);
//-----
  for(i=0; i < 13; i++)
  {
    if(UpVal[i] != 0) return(NormalizeDouble(UpVal[i],_Digits));
  }
  return(0);
}
double FractalDn()
{
//-----
  CopyBuffer(Fractals,1,0,5,DnVal);
  ArraySetAsSeries(DnVal,true);
//-----
  for(i=0; i < 13; i++)
  {
    if(DnVal[i] != 0) return(NormalizeDouble(DnVal[i],_Digits));
  }
  return(0);
}
 
G001:

I'm trying to find the price of the last fractal in the EA, but something's not working...

You are going outside the array. Try it like this:

double FractalUp()
{
//-----
  int n=100; 
  CopyBuffer(Fractals,0,0,n,UpVal);
  ArraySetAsSeries(UpVal,true);
//-----
  for(i=0; i < n-1; i++)
  {
    if(UpVal[i] != 0) return(NormalizeDouble(UpVal[i],_Digits));
  }
  return(0);
}
 
DC2008:

You are going outside the array. Try it this way:

Thank you. Unfortunately it doesn't work correctly either.
 
G001:
Thank you. Unfortunately it doesn't work correctly either.

if there is no fractal, it will return EMPTY_VALUE instead of 0

working option in the script

input ENUM_TIMEFRAMES TimeFrame=PERIOD_CURRENT;
void OnStart()
  {
//---
int Fractals=iFractals(_Symbol,TimeFrame);
if(Fractals==INVALID_HANDLE) Print("HandleError = ",_LastError);
 double DnVal[];
   CopyBuffer(Fractals,1,0,30,DnVal);
  ArraySetAsSeries(DnVal,true);
//-----
  for(int i=0; i < 30; i++)
  {
    if(DnVal[i] != EMPTY_VALUE) Print(NormalizeDouble(DnVal[i],_Digits));
  }
  
  }
//+------------------------------------------------------------------+
 
_Techno_:

if there is no fractal, it will return EMPTY_VALUE instead of 0

working option in the script

Ok, it works... :) Thank you.
 

Good afternoon!

Parsing the following article -https://www.mql5.com/ru/articles/35

When I attach the attached indicator to the chart, it shows some nonsense and not what it is supposed to show.

What is the reason for this?

#property copyright "Denis Zyatkevich"
#property description "Это индикатор, вычисляющий уровни TakeProfit на основе"
#property description "средней волатильности рынка. При расчете индикатора"
#property description "используется значение индикатора Average True Range (ATR),"
#property description "вычисленного по дневным ценовым данным. Значение"
#property description "индикатора откладывается от минимального и"
#property description "максимального значения цены за день."
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  C'127,191,127'
#property  indicator_style1  STYLE_SOLID
#property  indicator_label1  "Buy TP"
#property  indicator_type2   DRAW_LINE
#property  indicator_color2  C'191,127,127'
#property  indicator_style2  STYLE_SOLID
#property  indicator_label2  "Sell TP"

input int             ATRper       = 5;         //ATR Period
input ENUM_TIMEFRAMES ATRtimeframe = PERIOD_D1; //Indicator timeframe

double bu[],bd[];
int hATR;

void OnInit()
  {
   SetIndexBuffer(0,bu,INDICATOR_DATA);
   SetIndexBuffer(1,bd,INDICATOR_DATA);
   hATR=iATR(NULL,ATRtimeframe,ATRper);
  }

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,day_n,day_t;
   double atr[],h_day,l_day;

   CopyBuffer(hATR,0,0,2,atr);
   ArraySetAsSeries(atr,true);

   for(i=prev_calculated;i<rates_total;i++)
     {
      day_t=int(time[i]/PeriodSeconds(ATRtimeframe));
      if(day_n<day_t)
        {
         day_n=day_t;
         l_day=low[i];
         h_day=high[i];
        }
        else
        {
         if(high[i]>h_day) h_day=high[i];
         if(low[i]<l_day) l_day=low[i];
        }
      bu[i]=l_day+atr[1];
      bd[i]=h_day-atr[1];
     }
   return(rates_total);
  }

void OnDeinit(const int reason)
  {
   IndicatorRelease(hATR);
  }
Знакомство с MQL5: написание простого советника и индикатора
Знакомство с MQL5: написание простого советника и индикатора
  • 2010.03.16
  • Denis Zyatkevich
  • www.mql5.com
В этой статье проведен краткий обзор языка MQL5, приведен пример написания советника и индикатора. Данная статья ориентирована как на читателей, знакомых с программированием на языке MQL4, так и на тех, кто только начинает знакомство с программированием торговых систем и индикаторов.
 
pavelrev:

Good afternoon!

Parsing the following article -https://www.mql5.com/ru/articles/35

When I attach the attached indicator to the chart, it shows some nonsense and not what it is supposed to show.

What is the reason?

Looks like in the output, CopyBuffer does not want to work properly.

Throw ATR on the chart, tf D1, then this indicator, try tf change, should work.

 
Silent:

It seems that on weekends, CopyBuffer does not want to work properly.

Throw on ATR chart, diff D1, then this indicator, try to change the diff, it should work.

On weekdays, when there are quotes, same thing.

Sometimes it slips and it shows what I need, but when I change TF or get a new quote it starts giving nonsense again.

Reason: