Not logged in

Forums

Viewing 8 posts - 1 through 8 (of 8 total)

Forums>EA Wizard>Strategy Samples>Horizontal Lines for TP and SL

  • #116349 |
    Participant
    33 Posts

    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

    #141619
    Moderator
    2349 Posts

    Hello,

     

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

    #141652
    Participant
    33 Posts

    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!

    #141723
    Moderator
    2349 Posts

    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 

    #141731
    Participant
    33 Posts

    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.

    #142014
    Participant
    33 Posts

    any luck?

    #142028
    Moderator
    2349 Posts

    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

    Attachments in this forum are visible only for registered users.
    #142136
    Participant
    33 Posts

    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. 

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.