Please help !!! value of indicator and iCustom is different

 

Hi everybody,

I'm trying to get the value from the "average angle" indicator. But the value of the indicator displayed on the chart is different from the value of the indicator taken from iCustom. I am very confused with this problem

Please help me fix my code. Thanks in advance.

//+------------------------------------------------------------------+
//|                                                     MA-angle.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//--- input parameters MA
input int                  Inp_Period = 5;            // Moving average
input int                  MA_Shift=0;
input ENUM_MA_METHOD       Inp_Method = MODE_SMA;   
input ENUM_APPLIED_PRICE   Inp_Apply = PRICE_CLOSE; // MA: type of price   
input int                  AngleBars  = 3;        // Bars for angle
input double               AngleLevel = 8;        // Level  
                          
int   count_Candle=10;

int Handle_of_Angle; 



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

Handle_of_Angle = iCustom(Symbol(),PERIOD_CURRENT,"angle_of_averages",
                                 Inp_Period,
                                 Inp_Method,
                                 Inp_Apply,
                                 AngleBars,
                                 AngleLevel);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double array_ma_angle[];
   ArraySetAsSeries(array_ma_angle,true);
   
   if (CopyBuffer(Handle_of_Angle,0,0,count_Candle,array_ma_angle) < 0){Print("CopyBufferMA_Angle error =",GetLastError());}
   
   string text="";
   for (int i=0;i<count_Candle;i++)
   text=text+"Value of Angle "+ IntegerToString(i)+ " : " +DoubleToString(array_ma_angle[i], Digits())+"\n";
      
       
   
   Comment(text);
   
  }
 
Tomq:

Hi everybody,

I'm trying to get the value from the "average angle" indicator. But the value of the indicator displayed on the chart is different from the value of the indicator taken from iCustom. I am very confused with this problem

Please help me fix my code. Thanks in advance.

instead of placing the indicator separately onto the chart, do it from the EA after creating the handle.

the inputs of that indicator are using non-standard enumerations so it is likely an issue with the way you are setting the inputs, this avoids that and will match but you still need to ensure you are getting the inputed values that you have specified - check the enumerations...

also set the array as series in Oninit not every tick.

  ChartIndicatorAdd(0,1,Handle_of_Angle);
 
Tomq:

Hi everybody,

I'm trying to get the value from the "average angle" indicator. But the value of the indicator displayed on the chart is different from the value of the indicator taken from iCustom. I am very confused with this problem

Please help me fix my code. Thanks in advance.

All working just fine :


input int              MAPeriod   = 34;       // MA period
   enum enumAveragesType
      {
         avgSma,    // Simple moving average
         avgEma,    // Exponential moving average
         avgDsema,  // Double smoothed EMA
         avgDema,   // Double EMA
         avgTema,   // Tripple EMA
         avgSmma,   // Smoothed MA
         avgLwma,   // Linear weighted MA
         avgPwma,   // Parabolic weighted MA
         avgAlex,   // Alexander MA
         avgHull,   // Hull MA
         avgTma,    // Triangular MA
         avgSine,   // Sine weighted MA
         avgLsma,   // Linear regression value
         avgIe2,    // IE/2
         avgNlma,   // Non lag MA
         avgZlma,   // Zeo lag EMA
         avgLead    // Leader EMA
      };
input enumAveragesType MAType     = avgNlma;  // Calculation type
   enum enPrices
      {
         pr_close,      // Close
         pr_open,       // Open
         pr_high,       // High
         pr_low,        // Low
         pr_median,     // Median
         pr_typical,    // Typical
         pr_weighted    // Weighted
      };
input enPrices         MAPrice    = pr_close; // Price to use
input int              AngleBars  = 6;        // Bars for angle
input double           AngleLevel = 8;        // Level

//
//
//

int _handle;
int OnInit()
  {
      _handle = iCustom(_Symbol,_Period,"angle_of_averages",MAPeriod,MAType,MAPrice,AngleBars,AngleLevel);
         if (_handle==INVALID_HANDLE)
            {
               Print("Error loading indicator"); return(INIT_FAILED);
            }      
      return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason) {}
void OnTick()
  {   
      double _result[];
         if (CopyBuffer(_handle,0,0,10,_result)==10)
            {
               string _comment = (string)TimeLocal()+"\n\n";
                     for (int i=0; i<10; i++)
                           _comment += StringFormat("   bar : %i value : %s\n",9-i,DoubleToString(_result[i],_Digits));
               Comment(_comment);
            }
 
I did it, it show correct value. Thank you so much
 
Tomq: I'm trying to get the value from the "average angle" indicator. But the value of the indicator displayed on the chart is different from the value of the indicator taken from iCustom. I am very confused with this problem

Please help me fix my code. Thanks in advance.

Can't be done.
  1. There is no angle from 2 anchor points. An angle requires distance divided by distance; a unit-less number. A chart has price and time. What is the angle of going 30 miles in 45 minutes? Meaningless!

  2. You can get the slope from a trendline: m=ΔPrice÷ΔTime or m=ΔPrice÷Δ(bar index). Changing the price scale, bar width, or window size, changes the apparent angle, the slope is constant. Angle is meaningless.

  3. You can create an angled line using one point and setting the angle (Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference.) The line is drawn that angle in pixels. Changing the axes scales does NOT change the angle (and thus is meaningless.)

  4. If you insist, take the two price/time coordinates, convert them to pixel coordinates and then to apparent angle with arctan.
              How to get the angle of a trendline and place a text object to it? - Trend Indicators - MQL4 programming forum - Page 2