Why compute price angle is always incorrect in mt4/mt5, what had happen? WHAT IS TRUTH ABOUT HIDING PRICE ANGLE AND WHY IT IS IMPORTANT?

 

THIS SCRIPT USING TWO POINT TO COMPUTE ANGLE OF TREND AND TREND RESULT. HOWEVER, THE MT4/MT5 SOFTWARE IS INCONSISTENT TO PROVIDE A CORRECT TREND VALUE. THE FIRST ANSWER ALWAYS A REVERSE ANSWER!!! IS MT4/MT5 A PIRATE SOFTWARE AND STOP USER FROM FINDING PRICE ANGLE? WHY ALWAYS GIVE FALSE OUTPUT?

SAME SCRIPT PROGRAM, IS IT POSSIBLE TO CHANGE THE PRICE TREND 3 TIME WITHIN A MINUTE? MAKE SENSE? is it funny all the false computing???

    


//+------------------------------------------------------------------+
//|                                                   Angle_Tool.mq4 |
//|                                                       TAN EK KUN |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "TAN EK KUN"
#property link      ""
#property version   "1.00"
#property strict

#property strict
//--- description
#property description "Script draws \"THIS IS A PROGRAM TO COMPUTE PRICE"
#property description "ANGLE AND TREND OF TWO GIVEN POINTS."
//--- display window of the input parameters during the script's launch
#property script_show_inputs
//--- input parameters of the script
input string          InpName="Trend";     // Line name
input int             InpDate1=100;         // 1 st point's date, %
input int             InpPrice1=95;        // 1 st point's price, %
input int             InpAngle=0;          // Line's slope angle
input color           InpColor=clrRed;     // Line color
input ENUM_LINE_STYLE InpStyle=STYLE_DASH; // Line style
input int             InpWidth=1;          // Line width
input bool            InpBack=false;       // Background line
input bool            InpSelection=true;   // Highlight to move
input bool            InpRayRight=true;    // Line's continuation to the right
input bool            InpHidden=true;      // Hidden in the object list
input long            InpZOrder=0;         // Priority for mouse click

string symbol="GBPCHF+";
string LLS_Period="PERIOD_H1";
//+------------------------------------------------------------------+
//| Create a trend line by angle                                     |
//+------------------------------------------------------------------+
bool TrendByAngleCreate(const long            chart_ID=0,        // chart's ID
                        const string          name="TrendLine",  // line name
                        const int             sub_window=0,      // subwindow index
                        datetime              time=0,            // point time
                        double                price=0,           // point price
                        datetime              time2=0,            // point time2
                        double                price2=0,           // point price2
                        const double          angle=45.0,        // slope angle
                        const color           clr=clrRed,        // line color
                        const ENUM_LINE_STYLE style=STYLE_SOLID, // line style
                        const int             width=1,           // line width
                        const bool            back=false,        // in the background
                        const bool            selection=true,    // highlight to move
                        const bool            ray_right=true,    // line's continuation to the right
                        const bool            hidden=true,       // hidden in the object list
                        const long            z_order=0)         // priority for mouse click
  {
//--- create the second point to facilitate dragging the trend line by mouse
   //datetime time2=0;
   //double   price2=0;
//--- set anchor points' coordinates if they are not set
   //ChangeTrendEmptyPoints(time,price,time2,price2);
//--- reset the error value
   ResetLastError();
//--- create a trend line using 2 points
   if(!ObjectCreate(chart_ID,name,OBJ_TRENDBYANGLE,sub_window,time,price,time2,price2))
     {
      Print(__FUNCTION__,
            ": failed to create a trend line! Error code = ",GetLastError());
      return(false);
     }
//--- change trend line's slope angle; when changing the angle, coordinates of the second
//--- point of the line are redefined automatically according to the angle's new value
   //ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set line color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line style
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the line by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- enable (true) or disable (false) the mode of continuation of the line's display to the right
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }

//+------------------------------------------------------------------+
//| Delete the trend line                                            |
//+------------------------------------------------------------------+
bool TrendDelete(const long   chart_ID=0,       // chart's ID
                 const string name="TrendLine") // line name
  {
//--- reset the error value
   ResetLastError();
//--- delete a trend line
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete a trend line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   long a = ChartOpen(symbol,LLS_Period);
//--- number of visible bars in the chart window
   int bars2=(int)ChartGetInteger(a,CHART_VISIBLE_BARS);
//--- price array size
   int accuracy2=1000;
//--- arrays for storing the date and price values to be used
//--- for setting and changing line anchor points' coordinates
   datetime date2[];

//--- memory allocation
   ArrayResize(date2,bars2);

//--- fill the array of dates
   ResetLastError();
   if(CopyTime(ChartSymbol(a),LLS_Period,0,bars2,date2)==-1)
     {
      Print("Failed to copy time values! Error code = ",GetLastError());
      return;
     }

//--- define points for drawing the line
   
   int d1=InpDate1*(bars2-1)/100;
   //Alert(date2[0]);  
//--- create a trend line
   
//create at your own. 
//--- redraw the chart and wait for 1 second
   //ChartRedraw();
   Sleep(1000);
      
   if (ObjectGetDouble(a,InpName,OBJPROP_ANGLE,0) < 180)
      {
         double delta= (180-ObjectGetDouble(a,InpName,OBJPROP_ANGLE,0))*-1; 
         Alert(symbol+":downtrend");
         Alert(delta);
         Alert("X-ANGLE:"+ObjectGetDouble(a,InpName,OBJPROP_ANGLE,0));
         
      }
   if (ObjectGetDouble(a,InpName,OBJPROP_ANGLE,0) > 180)
      {
         double delta= 1*(ObjectGetDouble(a,InpName,OBJPROP_ANGLE,0)-180); 
         Alert(symbol+":uptrend");
         Alert(delta);  
         Alert("X-ANGLE:"+ObjectGetDouble(a,InpName,OBJPROP_ANGLE,0));
      }

  
//--- 1 second of delay
   Sleep(1000);
//--- delete from the chart
   //TrendDelete(0,InpName);
   //ChartRedraw();
//--- 1 second of delay
   Sleep(1000);
//---
  }
 

Bug solved. Case closed. the code- "Symbol()"  io variable have been changed and inconsistent and changeable during programming environment(No sure why it change when user first open a new chart because open a new chart = current chart). Encourage to direct-use of string variable of symbol instead of using Symbol() or _Symbol. This is a significant weakness of mql4 programming. EA developer take noted.

 
Tan Ek Kun #: This is a significant weakness of mql4 programming. EA developer take noted.

There is no weakness. Your code is the one that has several bugs and using the functions incorrectly.

For example, you are using a string for the period instead of an enumeration:

// This is incorrect

   string LLS_Period="PERIOD_H1";
   // ...
   long a = ChartOpen(symbol,LLS_Period);
   // ...
   CopyTime( ChartSymbol(a),LLS_Period,0,bars2,date2)==-1)
// Use enumeration (not string)

   ENUM_TIMEFRAMES eLLS_Period = PERIOD_H1;
   // ...
   long a = ChartOpen( symbol, eLLS_Period );
   // ...
   CopyTime( ChartSymbol( a ), eLLS_Period, 0, bars2, date2 )


There are several other problems with your code, so don't go complaining about it before you properly understand how to code in MQL.

 
Also, please stop using UPCASE text. It is equivalent to SHOUTING and not considered polite.
 
Fernando Carreiro #:
Also, please stop using UPCASE text. It is equivalent to SHOUTING and not considered polite.

Thank you Fernando Carreiro. You are a smart guy.  Respect you as you are older. But there are more than 1 way to write code of mql4 programming. Symbol() refer to current chart and it is changeable. A variable changeable in programming environment is highly unstable. At least at the end, my code to compute angle work without changing price data of symbol anymore. Also, thank you for your patient to read my post and improve my code-"Period".