Does anyone know how to add text to the entry, stop loss and take profit trade levels lines?

To add comments, please log in or register
kaira_1012
40
kaira_1012  

I would like to add the time the order was placed to the sell trade level line and move it to the right margin of the chart.


I have spent hours looking for the object names of these trade level lines to no avail...can some one please point me in the right direction?

MThomp
216
MThomp  
kaira_1012:

I would like to add the time the order was placed to the sell trade level line and move it to the right margin of the chart.


I have spent hours looking for the object names of these trade level lines to no avail...can some one please point me in the right direction?

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_label

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
  • www.mql5.com
//| Create a text label                                              |               chart_ID=0,                               sub_window=0,                             x=0,                                      y=0,                                      font_size=10,                          angle=0.0,                ...
kaira_1012
40
kaira_1012  

Thank you for the reply MThomp,

I know how to create a label, I am trying to figure out how to move the label of the trade levels, eg: entry price, SL and TP,  to the right of the chart window without having to create another label.

Example:

I open a long trade,

mt4 places a hline at the Ask price with a label on top "#12964132 buy .02" 

Here my problem:  The text object or label is on the left side of the chart I want it on the right side of the chart.  To move it I need the Handle(name) of that labels object and simply looking at the objects list does not show it, nor does any spararm for ONCHART click events.


that is the problem, I want all my level lines to show their price and type in the chart in the right margin of my shifted chart.

Have any suggestions?

Koros Jafarzadeh
478
Koros Jafarzadeh  
kaira_1012:

Thank you for the reply MThomp,

I know how to create a label, I am trying to figure out how to move the label of the trade levels, eg: entry price, SL and TP,  to the right of the chart window without having to create another label.

Example:

I open a long trade,

mt4 places a hline at the Ask price with a label on top "#12964132 buy .02" 

Here my problem:  The text object or label is on the left side of the chart I want it on the right side of the chart.  To move it I need the Handle(name) of that labels object and simply looking at the objects list does not show it, nor does any spararm for ONCHART click events.


that is the problem, I want all my level lines to show their price and type in the chart in the right margin of my shifted chart.

Have any suggestions?

have a nice coding :)


void OnTick()
{
    if (ShowOrderLable)
    {
        ObjectsDeleteAll(0, "Order Label");
        datetime t = Time[0] + Period() * 60;
        double   price;
        int      sub_window, result = (int) ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0) - 10;
        ChartXYToTimePrice(0, result, 1, sub_window, t, price);
        for (int i = OrdersTotal() - 1; i >= 0; i--)
        {
            if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            {
                if (OrderSymbol() == Symbol())
                {
                    int    OT   = OrderType();
                    double OOP  = OrderOpenPrice();
                    string name = StringConcatenate("Order Label", OrderTicket());
                    if (OT == OP_BUY)
                        TextCreate(0, name, 0, t, OOP, "#" + IntegerToString(OrderTicket()) + " " + "Buy " + DoubleToString(OrderLots(), 2), "Arial", 7, clrWhite, 0, ANCHOR_RIGHT_LOWER, false, false, false, true);
                    if (OT == OP_SELL)
                        TextCreate(0, name, 0, t, OOP, "#" + IntegerToString(OrderTicket()) + " " + "Sell " + DoubleToString(OrderLots(), 2), "Arial", 7, clrWhite, 0, ANCHOR_RIGHT_LOWER, false, false, false, true);
                }
            }
        }
    }
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
bool TextCreate(const long chart_ID = 0,
                const string name = "Text",
                const int sub_window = 0,
                datetime time = 0,
                double price = 0,
                const string text = "Text",
                const string font = "Arial",
                const int font_size = 10,
                const color clr = clrRed,
                const double angle = 90.0,
                const ENUM_ANCHOR_POINT anchor = ANCHOR_LEFT,
                const bool back = false,
                const bool selectable = false,
                const bool selected = false,
                const bool hidden = true,
                const long z_order = 0)
{
    if (ObjectFind(name) == -1)
    {
        if (!ObjectCreate(chart_ID, name, OBJ_TEXT, sub_window, time, price))
        {
            return(false);
        }
    }
    ObjectSetString(chart_ID, name, OBJPROP_TEXT, text);
    ObjectSetString(chart_ID, name, OBJPROP_FONT, font);
    ObjectSetInteger(chart_ID, name, OBJPROP_FONTSIZE, font_size);
    ObjectSetInteger(chart_ID, name, OBJPROP_TIME, time);
    ObjectSetDouble(chart_ID, name, OBJPROP_PRICE, price);
    ObjectSetDouble(chart_ID, name, OBJPROP_ANGLE, angle);
    ObjectSetInteger(chart_ID, name, OBJPROP_ANCHOR, anchor);
    ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
    ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back);
    ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selectable);
    ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selected);
    ObjectSetInteger(chart_ID, name, OBJPROP_HIDDEN, hidden);
    ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
    return(true);
}
//-------------------------------------------------------------------------------------------

kaira_1012
40
kaira_1012  
Koros Jafarzadeh:

have a nice coding :)


Many Many Thanks Koros Jafarzadeh,

You just solved my problem :)  Very elegant  coding by the way!  

This was just what I needed!  

Thank You!!!

Koros Jafarzadeh
478
Koros Jafarzadeh  
kaira_1012:

Many Many Thanks Koros Jafarzadeh,

You just solved my problem :)  Very elegant  coding by the way!  

This was just what I needed!  

Thank You!!!

dear kaira_1012

I updated the code to show better label position

try again

kaira_1012
40
kaira_1012  
Koros Jafarzadeh:

dear kaira_1012

I updated the code to show better label position

try again

Thanks Koros,

I just realized I can't see the results of the code in the strategy tester ..since it uses Arrow objects to simulate trade level lines and there is no order history when using the tester, Oh well, will have to wait till tomorrow evening to test and tweak

Koros Jafarzadeh
478
Koros Jafarzadeh  
kaira_1012:

Thanks Koros,

I just realized I can't see the results of the code in the strategy tester ..since it uses Arrow objects to simulate trade level lines and there is no order history when using the tester, Oh well, will have to wait till tomorrow evening to test and tweak

It's working , put this code inside void OnTick()

I updated again to remove closed order label

kaira_1012
40
kaira_1012  
Koros Jafarzadeh:

It's working , put this code inside void OnTick()

I updated again to remove closed order label

What simulator are you using?  I am using fxblue's simulator and the labels are still left justified on the chart. 

I think it might be my simulator not playing nice nice with the code.

Koros Jafarzadeh
478
Koros Jafarzadeh  
kaira_1012:

What simulator are you using?  I am using fxblue's simulator and the labels are still left justified on the chart. 

I think it might be my simulator not playing nice nice with the code.

I put the code inside my EA and work perfectly in MT4 strategy tester

kaira_1012
40
kaira_1012  
Koros Jafarzadeh:

I put the code inside my EA and work perfectly in MT4 strategy tester

I put the code inside of a custom indicator and running fxblue simulator in the strategy test with the indicator attached to the chart.


I first put it inside OnCalculate then tried as you suggested with OnTick and still no go.

 

attached is my indy.


then again, it maybe coding paralysis on my part....been at it a while this morning.

12
To add comments, please log in or register