Download MetaTrader 5

how to get current value of a trendline drawn on chart

To add comments, please log in or register
Ronald Kirby
192
Ronald Kirby  

 Hi there this is an old   indicator and I am trying to modify it from horizontal lines to trend lines  , but I cant figure out how to read a trendline That I have added to the chart ,

any ideas or articles on this subject would be appreciated

cheers Ron  

 

 

//|  //+------------------------------------------------------------------+                                                  indicator.mq4 |
//|                                     
//|  
                                         
//+------------------------------------------------------------------+
//
//   
extern bool    AlarmOn   =True; // Alarm on or off
extern bool    SignalOnClose  = False; // if false we use bid price to signal line break
extern string    ResistanceLineName   = "R_Alert"; // Line ID that will trigger alarm                 Note I rename trendline to "R_Alert"  in its properties
extern string    SupportLineName      = "S_Alert"; // Line ID that will trigger alarm
extern string     SoundFile      = "alert2.wav";   // Sound ID
extern int     DelayBetweenAlarm    = 10; //
extern color   SRLineClr         = Lime; // SR Line color
extern color   SRLineClr2        = Red;  // SR Line color
extern int     SRLineWidth      = 2;
#property indicator_chart_window
double R_Alert;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//int init()
//  {
//---- indicators
//---- indicators
//if(ObjectFind(ResistanceLineName) == -1) {
 //  ObjectCreate(ResistanceLineName, OBJ_TREND, 0, 0,iHigh(NULL, 0,0));
 //  }
 //  ObjectSet(ResistanceLineName, OBJPROP_COLOR, SRLineClr);
 //  ObjectSet(ResistanceLineName, OBJPROP_WIDTH, SRLineWidth);
  
 //  if(ObjectFind(SupportLineName) == -1) {
 //  ObjectCreate(SupportLineName, OBJ_TREND, 0, 0,iLow(NULL, 0, 0));
  
 //     ObjectSet(SupportLineName, OBJPROP_COLOR, SRLineClr2);
 //  ObjectSet(SupportLineName, OBJPROP_WIDTH, SRLineWidth);
  
 //  }
//----
//   return(0);
//  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
//int deinit()
//  {
//----
   //----
//     if(UninitializeReason() !=  REASON_PARAMETERS  && UninitializeReason() != REASON_CHARTCHANGE) {
//            ObjectDelete (SupportLineName);
//          }
//----
//   return(0);
//  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
 
     
      //----
   //----
   if(AlarmOn){
      double PreviousClosePrice  =  Bid;
      if(SignalOnClose  == true) {PreviousClosePrice  =  iClose(NULL, 0, 1);}
      double   ResistancePrice   =  ObjectGet(R_Alert, OBJPROP_PRICE1);
      double   SupportPrice   =  ObjectGet(SupportLineName, OBJPROP_PRICE1);
      if(PreviousClosePrice > ResistancePrice && ResistancePrice !=0)Alerts(1);
      if(PreviousClosePrice < SupportPrice && SupportPrice !=0)Alerts(2);
      }
     
     
     
       Print ("R_Alert=  ", ResistancePrice);                                                                          // NOTE   I try to print value of trend line
          
//----
   return(0);
  }
//+------------------------------------------------------------------+
 void Alerts(int Direction)
  {                                                //in reverse ie }
      static   datetime AlertLastTime = 0;
     
      if(TimeCurrent() >   AlertLastTime ) {
         AlertLastTime = TimeCurrent () + DelayBetweenAlarm;
         PlaySound(SoundFile);
         }
       }
whroeder1
17063
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Perhaps you should read the manual. ObjectGetValueByShift - Object Functions - MQL4 Reference


To add comments, please log in or register