Jump to content


Photo

Horizontal Lines for TP and SL


  • Please log in to reply
7 replies to this topic

#1 beniko

beniko

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 18 February 2017 - 10:13 AM

Hello,

 

I am trying to develop a semi-automatic EA that includes Horizontal lines, which when moved, the price of a double variable is updated.

 

To be more specific, when I place the EA on a chart, 3 lines shall appear. One for Stop loss, one for resistance and one for support. The user shall be able to move the lines and when done so, the price of a variable shall be updated. This variable will be used in conditions or order placement.

 

I tried yesterday to copy the code from an indicator that uses lines but due to my limited programming experience was unsuccessful.

 

I believe it would be a useful special feature to be able to link the price of a Horizontal line to a double variable.

 

Ben



#2 tomas262

tomas262

    Advanced Member

  • Moderators
  • 2,368 posts

Posted 19 February 2017 - 09:37 PM

Hello,

 

I will check what can be done here. It might be possible to do it using custom function code



#3 beniko

beniko

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 20 February 2017 - 01:26 PM

Hello,

 

I will check what can be done here. It might be possible to do it using custom function code

Thank you, this would be very helpful!



#4 tomas262

tomas262

    Advanced Member

  • Moderators
  • 2,368 posts

Posted 22 February 2017 - 01:26 PM

Hello,

 

can those lines be drawn by your EA? They could be then modified by hand in MetaTrader on chart. The problem is that manually created lines have its own name generated which I do not know in advance so I cannot select the line 



#5 beniko

beniko

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 22 February 2017 - 04:34 PM

Hello,

 

can those lines be drawn by your EA? They could be then modified by hand in MetaTrader on chart. The problem is that manually created lines have its own name generated which I do not know in advance so I cannot select the line 

Yes they should be drawn by the EA itself. Not new lines that are added manually.

 

I got inspired by tools like "Money Manager Graphic Tool - indicator for MetaTrader 4" found here https://www.mql5.com/en/code/13804. There are many others like it.

 

But all I need are a few simple lines that are drawn by the EA once it is placed on the chart and then the user can move these lines. When moved the price of certain variables shall be updated accordingly (or the price of the variables could be updated with each new tick as well). These variables can then be used in decision making and placing orders.



#6 beniko

beniko

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 07 March 2017 - 02:01 PM

any luck?



#7 tomas262

tomas262

    Advanced Member

  • Moderators
  • 2,368 posts

Posted 08 March 2017 - 10:36 PM

Hello,

 

I have made an example on this. EA enters a trade + draws TP and SL lines, which when modified set the new price for SL and TP orders

 

You need to add this code into CustomFunctions.mq4 file

void drawHorizotalLine(string lineName = "hLine", double priceLevel = 0) {

   ObjectCreate(lineName, OBJ_HLINE, 0, Time[0], priceLevel); 

} 

double getProfitLinePrice() {

   double targetLine = ObjectGet("targetLine", OBJPROP_PRICE1) ;
   return targetLine;

} 

double getStopLinePrice() {

   double stopLine = ObjectGet("stopLine", OBJPROP_PRICE1) ;
   return stopLine;

}

And use it as shown in the project

Attached Files



#8 beniko

beniko

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 16 March 2017 - 02:52 PM

I didn't know about the CustomFunctions.mq4. It will come in handy for other functions as well!

 

You brought me a lot closer to creating exactly the EA I have in mind.

 

Thank you very much. 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users