You don't know how to check the return value for zero? And don't know how to exit OnCalculate() with a return of zero? Have you never tried to search for information on the website?
Getting the required value from the function
Check if it is zero
If it is zero, then return 0;
If it is not zero, then to step 3
Working with this value
I never thought that I will be telling the basics of logic on this resource to a man with the rating exceeding 13 thousand...
This is not an indicator.
I intentionally specified whether I should do checks at each call or one at start of OnTick is enough...
Returns are not acceptable for me ... and to loop the wait in the tester is impossible, and in the real should work (or not?).
My rating is not for programming, I am not a programmer, and I am learning this complicated business only thanks to people like you, I really appreciate feedback from knowledgeable people.
Hello. For some reason Handel only transmits when set to all periods, but I set to a specific period and there is nothing. I don't know what the problem is. Tried typing in handel directly not from global variables, result is the same. What's wrong? I need the value to be from one period.
//+------------------------------------------------------------------+//| 77777.mq5 |//| Copyright 2019, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2018, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property strict#property indicator_chart_window#property indicator_buffers1#property indicator_plots0//+----------------------------------------------+//| Параметры отрисовки индикатора 1 |//+----------------------------------------------+//----inputstring xBars="2018.11.19 00:00"; //Дата начала отсчетаinputbool DataBars=false; //Считать по дате (true)inputint InpMAShift=1; //Сдвиг бара расчета inputENUM_TIMEFRAMES Timeframes=PERIOD_D1; //Таймфрейм скользящейinputENUM_MA_METHOD Method=MODE_EMA; //Метод расчета скользящейinputENUM_APPLIED_PRICE AppliedPrice=PRICE_CLOSE; //Расчет цены скользящейinputENUM_LINE_STYLE MAStyle=STYLE_DASH; //Стиль всех скользящих линийinputint InpMAPeriod1=5; //Скользящая 1 периода//----int handle_ma,shift;
double BufferPrice[];
//---int period;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---
period=(InpMAPeriod1<1 ? 1 : InpMAPeriod1);
//---SetIndexBuffer(2,BufferPrice,INDICATOR_CALCULATIONS);
ArraySetAsSeries(BufferPrice,true);
//--- create MA's handlesResetLastError();
//----------------------------------------------------------------+// ПРОБЛЕМА ТУТ ////----------------------------------------------------------------+
handle_ma=iMA(NULL,PERIOD_D1,period,0,MODE_SMA,PRICE_CLOSE); //ПРОБЛЕМА ТУТ
// handle_ma=iMA(NULL,PERIOD_CURRENT,period,0,MODE_SMA,PRICE_CLOSE); // БЕЗ ПРОБЛЕМЫif(handle_ma==INVALID_HANDLE)
{
Print("The iMA (",(string)period,") object was not created: Error ",GetLastError());
returnINIT_FAILED;
}
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function | //+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
ObjectDelete(0,"Proba");
Comment("");
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//--- Проверка количества доступных баровif(rates_total<4) return0;
//--- Проверка и расчёт количества просчитываемых баровint limit=rates_total-prev_calculated;
if(limit>1)
{
limit=rates_total-1;
ArrayInitialize(BufferPrice,0);
}
//--- Подготовка данныхint count=(limit>1 ? rates_total : 2),copied=0;
copied=CopyBuffer(handle_ma,0,0,count,BufferPrice);
if(copied!=count) return0;
//---- if(DataBars==false)
shift=InpMAShift;
else
shift=iBarShift(NULL,PERIOD_CURRENT,StringToTime(xBars));
double ma1=BufferPrice[shift];
datetime tm=iTime(NULL,Timeframes,shift);
Comment(NormalizeDouble(BufferPrice[shift],_Digits)," ",shift);
HLine("Proba","",tm,ma1,MAStyle,1,Red);
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+void HLine(string name,
string text,
datetime tm,
double price,
int stl,
int wid,
color clr)
{
if(ObjectFind(0,name)!=0)
{
ObjectCreate(0,name,OBJ_HLINE,0,tm,price);
ObjectSetInteger(0,name,OBJPROP_TIME, tm);
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetString(0,name,OBJPROP_FONT,"Times New Roman");
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
ObjectSetInteger(0,name,OBJPROP_STYLE, stl);
ObjectSetInteger(0,name,OBJPROP_WIDTH, wid);
ObjectSetInteger(0,name,OBJPROP_COLOR, clr);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
}
}
kopeyka2: Hello. I can't find anything, for some reason the handel only transfers when it's set to all periods, but I set it to a certain period and nothing happens. I don't know what the problem is. I tried to input data not from global variables directly into handel, the result is the same. What's wrong?
ResetLastError();
if(CopyBuffer(handle_ma,0,0,count,BufferPrice)<0)
{
PrintFormat("Failed to copy data from the handle_ma indicator, error code %d",GetLastError());
return(0.0);
}
// copied=CopyBuffer(handle_ma,0,0,count,BufferPrice);
Study the error, Artem is right in saying that you should check everything 10 times...
2019.01.2520:12:26.169 Test777 (Si Splice,M1) Failed to copy data from the handle_ma indicator, error code 4806
ERR_INVALID_ARRAY
4006
Array of unsuitable type, unsuitable size or corrupted dynamic array object
kopeyka2: Hello. I've noticed that the handel only transfers when it's set for all periods, but when I set it for a certain period, nothing happens. I do not understand what the problem is. Tried typing in handel directly not from global variables, result is the same. What's wrong? I need the value to be from the same period.
You take examples from the CodeBase from Scriptor's indicators, don't you? Right? Then look in his code (recently published) for examples that have MTF in their name, but without MCP.
MTF = MultiTimeFrame, MCP = MultiCurrencyPair. I.e., if you want to get data on the current symbol, but from another timeframe than the chart period, then you need an example of a multi-timeframe indicator. In MCP you should not get involved yet - there on the OOP with the use of the standard classes. You will get confused.
It's only for MA working on the current period and symbol. For working on a different period, the calculation will be different. Look it up - everything is close, and the direction I gave you.
You take examples from the CodeBase from Scriptor's indicators, don't you? Right? Then look in his code (recently published) for examples that have MTF in their name, but without MCP.
MTF = MultiTimeFrame, MCP = MultiCurrencyPair. I.e., if you want to get data on the current symbol, but from another timeframe than the chart period, then you need an example of a multi-timeframe indicator. In MCP you should not get involved yet - there on the OOP with the use of the standard classes. You will get confused.
For example, this calculation:
it is only for MA working on current period and symbol. For work on a different period, the calculation will be different. Search - everything is close, and I gave you the direction.
Please, but I copied the wrong error, it should be
ERR_INDICATOR_DATA_NOT_FOUND
4806
The requested data was not found
The point is that the number of bars is different for different TFs and this should be taken into account.
I was just checking it. But the PROBLEM is that having set handel on one constant period, in
CopyBuffer the value on other timeframes is NOT PERMANENT. On the set handle period the value was, but on the smaller timeframes 0.0 (zero). Moved it around the buffer in search... zero. Why is it not passed toCopyBuffer ?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
How do I find the reason for this message?
Profiler
You don't know how to check the return value for zero? And don't know how to exit OnCalculate() with a return of zero? Have you never tried to search for information on the website?
This is not an indicator.
I intentionally specified whether I should do checks at each call or one at start of OnTick is enough...
Returns are not acceptable for me ... and to loop the wait in the tester is impossible, and in the real should work (or not?).
My rating is not for programming, I am not a programmer, and I am learning this complicated business only thanks to people like you, I really appreciate feedback from knowledgeable people.
Thank you for your understanding.
Profiler
What if it happens once a day or less?
Hello. I can't find anything, for some reason the handel only transfers when it's set to all periods, but I set it to a certain period and nothing happens. I don't know what the problem is. I tried to input data not from global variables directly into handel, the result is the same. What's wrong?
Study the error, Artem is right in saying that you should check everything 10 times...
ERR_INVALID_ARRAY
4006
Array of unsuitable type, unsuitable size or corrupted dynamic array object
ERR_INDICATOR_DATA_NOT_FOUND
4806
Requested data not found
Hello. I've noticed that the handel only transfers when it's set for all periods, but when I set it for a certain period, nothing happens. I do not understand what the problem is. Tried typing in handel directly not from global variables, result is the same. What's wrong? I need the value to be from the same period.
You take examples from the CodeBase from Scriptor's indicators, don't you? Right? Then look in his code (recently published) for examples that have MTF in their name, but without MCP.
MTF = MultiTimeFrame, MCP = MultiCurrencyPair. I.e., if you want to get data on the current symbol, but from another timeframe than the chart period, then you need an example of a multi-timeframe indicator. In MCP you should not get involved yet - there on the OOP with the use of the standard classes. You will get confused.
For example, this calculation:
It's only for MA working on the current period and symbol. For working on a different period, the calculation will be different. Look it up - everything is close, and the direction I gave you.
You take examples from the CodeBase from Scriptor's indicators, don't you? Right? Then look in his code (recently published) for examples that have MTF in their name, but without MCP.
MTF = MultiTimeFrame, MCP = MultiCurrencyPair. I.e., if you want to get data on the current symbol, but from another timeframe than the chart period, then you need an example of a multi-timeframe indicator. In MCP you should not get involved yet - there on the OOP with the use of the standard classes. You will get confused.
For example, this calculation:
it is only for MA working on current period and symbol. For work on a different period, the calculation will be different. Search - everything is close, and I gave you the direction.
Study the error, Artem is right in saying that you should check everything 10 times...
ERR_INVALID_ARRAY
4006
Array of unsuitable type, unsuitable size or corrupted dynamic array object
Thank you
Please, but I copied the wrong error, it should be
ERR_INDICATOR_DATA_NOT_FOUND
4806
The requested data was not found
The point is that the number of bars is different for different TFs and this should be taken into account.
Please, but I copied the wrong error, it should be
ERR_INDICATOR_DATA_NOT_FOUND
4806
The requested data was not found
The point is that the number of bars is different for different TFs and this should be taken into account.
I was just checking it. But the PROBLEM is that having set handel on one constant period, in
CopyBuffer the value on other timeframes is NOT PERMANENT. On the set handle period the value was, but on the smaller timeframes 0.0 (zero). Moved it around the buffer in search... zero. Why is it not passed toCopyBuffer ?