Download MetaTrader 5
To add comments, please log in or register
Publish your article to let the traders see it in MetaTrader 5!
william hare
137
william hare 2016.05.19 08:34 

Hey all,

 I have been using LOCLinePips.mq4 which basically displays the distance in pips from price to HLINE.

I want to modify it to only calculate from solid horizontal lines only is this possible?

I guess i will have to change this part of the code

 

 void DoJob(){

   int    obj_total=ObjectsTotal();

   string name;

   DeleteLabels(_objPref);

   for(int i=0;i<obj_total;i++)

   {

      name=ObjectName(i);        

      if(ObjectType(name)==OBJ_HLINE){

         double price = ObjectGet(name, OBJPROP_PRICE1) ;

         CreateText(_objPref+name,Time[0],price,_textColor,DoubleToStr(MathAbs((Bid-price)/Point),0));

      }      

Sorry if this is a really basic thing to do im new :/

 Thamks all.

will 

Keith Watford
Moderator
7955
Keith Watford 2016.05.19 08:49  
willthare:

I want to modify it to only calculate from solid horizontal lines only is this possible?


Check the line's properties using OBJPROP_STYLE to detect whether it is a solid line or not
william hare
137
william hare 2016.05.19 09:11  

Thank you for you quick response I am really sorry i have no idea how you do that :s but heres the full code.

 

string _verName="LOCLinePips";

string _ver="v2.0";



extern color _textColor=Blue;

extern int _sleepTimeMS=50;



bool _isRunning=false;

string _fullName;

string _objPref="LOCLinePips";





int start()

{

   _fullName=_verName+" "+_ver;

   Print("LandOfCash.net "+_fullName+" Started.");  

   Comment("LandOfCash.net "+_fullName);

   if(!_isRunning){

      Iterate();

   }

   DeleteLabels(_objPref);

   return (0);

}

  



void DoJob(){

   int    obj_total=ObjectsTotal();

   string name;

   DeleteLabels(_objPref);

   for(int i=0;i<obj_total;i++)

   {

      name=ObjectName(i);        

      if(ObjectType(name)==OBJ_HLINE ){

         double price = ObjectGet(name, OBJPROP_PRICE1) ;

         CreateText(_objPref+name,Time[0],price,_textColor,DoubleToStr(MathAbs((Bid-price)/Point),0));

      }      

   }

}





void Iterate() {

   _isRunning=true;

   while(!IsStopped())    

   {              

    RefreshRates();     

    DoJob();

    Sleep(_sleepTimeMS);        

   }

}



void CreateText(string name, datetime time1, double price,color boxcolor, string text){

   ObjectDelete(name);

   if(!ObjectCreate(name, OBJ_TEXT,0, time1, price))

   {

    Print("error: cant create OBJ_TEXT! code #",GetLastError());

    return(0);

   }

   ObjectSetText(name, text, 15, "Verdana", boxcolor);

}

void DeleteLabels(string objPref){

   int    obj_total=ObjectsTotal();

   string name;

   for(int i=0;i<obj_total;i++)

   {

    name=ObjectName(i);    

    if(StringFind(name, objPref,0)>-1){      

      ObjectDelete(name);

      i--;

    }

   }

}

//+------------------------------------------------------------------+
whroeder1
13627
whroeder1 2016.05.19 12:03  
willthare: Thank you for you quick response I am really sorry i have no idea how you do that :s but heres the full code.
  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. You already know how to get the objects price. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
    double price = ObjectGet(name, OBJPROP_PRICE1) ;
william hare
137
william hare 2016.05.19 12:20  

I am so sorry i have no clue as I am new to this.

 

The code was not coded by me i just want to learn how to do basic modifications, I have read some of the manual to mgl4 code but i still haven't got a clue where to start.

 So i have to add  OBJPROP_STYLE somewhere and maybe STYLE_SOLID.

Sorry all must really P you lot off getting basic annoying questions from Noobs like myself

but we all start somewhere.    

Keith Watford
Moderator
7955
Keith Watford 2016.05.19 12:50  

The problem is that people who are new to coding want to jump straight in and modify others' code without learning the basics first.

To be able to modify code, you really need to be able to understand precisely what the code is doing. That takes time to learn.

Set yourself simple tasks such as drawing a horizontal line at the last closed bar's high, read the documentation and try to code it.

Post your attempt if you have problems and the contributors here will see that you are trying and will be very helpful.

/
To add comments, please log in or register