Trendline angle

 
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs

#include <Trade\Trade.mqh>
CTrade trade;
CPositionInfo  position;                   // trade position object
                    

//--- input parameters
input group             "MA Fast"
input int                  Inp_MA_ma_period     = 10;          // MA: averaging period
input int                  Inp_MA_ma_shift      = 0;           // MA: horizontal shift
input ENUM_MA_METHOD       Inp_MA_ma_method     = MODE_SMA;    // MA: smoothing type
input ENUM_APPLIED_PRICE   Inp_MA_applied_price = PRICE_CLOSE; // MA: type of price
int      handle_iMA;                            // variable for storing the handle of the iMA indicator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
 MqlRates Priceinfo [];
  
void OnTick()
  
 {
    double priceU [];
    double ma[];
   
   ArraySetAsSeries(ma,true);
   ArraySetAsSeries(Priceinfo,true);
   ArraySetAsSeries(priceU,true);
    int data=CopyRates(_Symbol,PERIOD_CURRENT,0,20,Priceinfo);
     int bb=iBands(_Symbol,PERIOD_CURRENT,20,0,2,PRICE_CLOSE);
    string signal="";
 handle_iMA=iMA(_Symbol,PERIOD_CURRENT,Inp_MA_ma_period,Inp_MA_ma_shift,
                  Inp_MA_ma_method,Inp_MA_applied_price);
   CopyBuffer(handle_iMA,0,0,3,ma);               
   CopyBuffer(bb,1,0,3,priceU);
  
   double priceUvalue0=priceU[0];
   double priceUvalue1=priceU[1];
   double Priceinfoclosevalue0=Priceinfo[0].close;
   double Priceinfoclosevalue1=Priceinfo[1].close;
   double Priceinfohighvalue0=Priceinfo[0].high;
   double Priceinfohighvalue1=Priceinfo[1].high;
   double Priceinfotimevalue0=Priceinfo[0].time;
   double Priceinfotimevalue1=Priceinfo[1].time;
   double mavalue0=ma[0];
   double mavalue1=ma[1];
  
  ObjectDelete(_Symbol,"MRG4"); 
  ObjectCreate(_Symbol,"MRG4",OBJ_TRENDBYANGLE,0,Priceinfotimevalue1,
       priceUvalue1,Priceinfotimevalue0,priceUvalue0);
  
   ObjectSetInteger(0,"MRG4",OBJPROP_COLOR,clrRed);
   ObjectSetInteger(0,"MRG4",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"MRG4",OBJPROP_WIDTH,1);
   ObjectSetInteger(0,"MRG4",OBJPROP_RAY_RIGHT,true);
   ObjectGetValueByTime(_Symbol,"MRG4",Priceinfo[0].time);
   double pricevalue=ObjectGetValueByTime(_Symbol,"MRG1",Priceinfo[0].time);
   double value=NormalizeDouble(pricevalue,3);
   double Angle=ObjectGetDouble(_Symbol,"MRG4",OBJPROP_ANGLE,0);
   double degree= Angle;
   Comment("degree = ",degree);

  double ask= SymbolInfoDouble(_Symbol,SYMBOL_ASK);
  double bid= SymbolInfoDouble(_Symbol,SYMBOL_BID);
 
 /* if(Angle < 50.0)
  {signal="SELL";}*/

 /* if(degree > 45.0 && Angle < 90.0)
      {signal="BUY";}*/
  
  if(signal =="BUY" && PositionsTotal()<1)
  trade.Buy(0.01,_Symbol,ask,0,0,NULL);
  
  }
//+------------------------------------------------------------------+

Dear Authorities, Is there a way to express the Trend angle as data for use in EA?
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.07.24
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Sorry to say it, but your idea won't help you as the x- and the y- axis aren't fix and unitary. The price side and then the angle changes as soon as new highs or lows appear or disappear e.g. because the actual one disappear from the window (to old), or if you change the time frame.
 
mr.guney: Dear Authorities, Is there a way to express the Trend angle as data for use in EA?
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. 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