OBJ_TEXT not showing

 
I just want to print a small OBJ_TEXT in the right upper corner of the main chart window showing SWAP LONG and SWAP SHORT.
I can print the values and show it in a comment but OBJ_TEXT is not showing up at all

Am I missing something?



#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    // Initialization code here

    return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    // Deinitialization code here
}
//+------------------------------------------------------------------+
//| Expert tick function                                            |
//+------------------------------------------------------------------+
void OnTick()
{
    // Tick event handling code here
}
//+------------------------------------------------------------------+
//| Custom indicator calculation function                            |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    // Indicator calculation code here
    DisplaySwapLong();
    DisplaySwapShort();
    return (rates_total);
}
//+------------------------------------------------------------------+
//| Expert text display functions                                   |
//+------------------------------------------------------------------+
void DisplaySwapLong()
{

    double swapShort = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_SHORT);
    ObjectCreate("swapShort", OBJ_TEXT, 0, 0, 0);
    ObjectSetInteger(0, "swapShort", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
    ObjectSetText("swapShort", DoubleToStr(swapShort), 20, "Arial", clrAqua);
    ObjectSet("swapShort", OBJPROP_CORNER, 2);
    ObjectSet("swapShort", OBJPROP_XDISTANCE, 100);
    ObjectSet("swapShort", OBJPROP_YDISTANCE, 200);
}

void DisplaySwapShort()
{
    double swapLong = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_LONG);
    //Print(swapLong);
    //Comment("Swap Long =", swapLong);
    ObjectCreate("swapLong", OBJ_TEXT, 0, 0, 0);
    ObjectSetInteger(0, "swapLong", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
    ObjectSetText("swapLong", DoubleToStr(swapLong), 20, "Arial", clrAntiqueWhite);
    ObjectSet("swapLong", OBJPROP_CORNER, 2);
    ObjectSet("swapLong", OBJPROP_XDISTANCE, 10);
    ObjectSet("swapLong", OBJPROP_YDISTANCE, 40);

    
    
}

//+------------------------------------------------------------------+


 
DGRL: Am I missing something?
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2.  //| Expert tick function                                            |
    //+------------------------------------------------------------------+
    void OnTick()
    {
        // Tick event handling code here
    }
    //+------------------------------------------------------------------+
    //| Custom indicator calculation function                            |
    //+------------------------------------------------------------------+
    int OnCalculate(const int rates_total, …

    Decide whether your code is an EA or an indicator. It can not be both.

  3. ObjectCreate("swapShort", OBJ_TEXT, 0, 0, 0);
        ObjectSetInteger(0, "swapShort", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER); 

    Text objects are connected to a price and time. Labels are connected to an anchor point and offset. PICNIC.

  4. ANCHOR_LEFT_UPPER is not an anchor offset.
 
change OBJ_TEXT to OBJ_LABEL

Before
void DisplaySwapLong()
{
    double swapShort = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_SHORT);
    ObjectCreate("swapShort", OBJ_TEXT, 0, 0, 0);
    ObjectSetInteger(0, "swapShort", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
    ObjectSetText("swapShort", DoubleToStr(swapShort), 20, "Arial", clrAqua);
    ObjectSet("swapShort", OBJPROP_CORNER, 2);
    ObjectSet("swapShort", OBJPROP_XDISTANCE, 100);
    ObjectSet("swapShort", OBJPROP_YDISTANCE, 200);
}

void DisplaySwapShort()
{
    double swapLong = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_LONG);
    //Print(swapLong);
    //Comment("Swap Long =", swapLong);
    ObjectCreate("swapLong", OBJ_TEXT, 0, 0, 0);
    ObjectSetInteger(0, "swapLong", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
    ObjectSetText("swapLong", DoubleToStr(swapLong), 20, "Arial", clrAntiqueWhite);
    ObjectSet("swapLong", OBJPROP_CORNER, 2);
    ObjectSet("swapLong", OBJPROP_XDISTANCE, 10);
    ObjectSet("swapLong", OBJPROP_YDISTANCE, 40);
}

After
void DisplaySwapLong()
{
    double swapShort = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_SHORT);
    ObjectCreate("swapShort", OBJ_LABEL, 0, 0, 0);
    ObjectSetInteger(0, "swapShort", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
    ObjectSetText("swapShort", DoubleToStr(swapShort), 20, "Arial", clrAqua);
    ObjectSet("swapShort", OBJPROP_CORNER, 2);
    ObjectSet("swapShort", OBJPROP_XDISTANCE, 100);
    ObjectSet("swapShort", OBJPROP_YDISTANCE, 200);
}

void DisplaySwapShort()
{
    double swapLong = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_LONG);
    //Print(swapLong);
    //Comment("Swap Long =", swapLong);
    ObjectCreate("swapLong", OBJ_LABEL, 0, 0, 0);
    ObjectSetInteger(0, "swapLong", OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
    ObjectSetText("swapLong", DoubleToStr(swapLong), 20, "Arial", clrAntiqueWhite);
    ObjectSet("swapLong", OBJPROP_CORNER, 2);
    ObjectSet("swapLong", OBJPROP_XDISTANCE, 10);
    ObjectSet("swapLong", OBJPROP_YDISTANCE, 40);  
}
Files:
 
DGRL:

Am I missing something?


Use the documentation and use the correct functions….  There is no such thing as ObjectSetText or ObjectSet
 
Paul Anscombe #:
ObjectSet

@Paul Anscombe,

I am using the documentation sir

For your reference here the link to the 2 functions that do excist


https://docs.mql4.com/objects/objectset

https://docs.mql4.com/objects/objectsettext

ObjectSetText - Object Functions - MQL4 Reference
ObjectSetText - Object Functions - MQL4 Reference
  • docs.mql4.com
ObjectSetText - Object Functions - MQL4 Reference
 
Denis Adha #:
change OBJ_TEXT to OBJ_LABEL

Before

After

Kudos Sir

Many thanks

 
DGRL #:

@Paul Anscombe,

I am using the documentation sir

For your reference here the link to the 2 functions that do excist


https://docs.mql4.com/objects/objectset

https://docs.mql4.com/objects/objectsettext

that is MT4  you have posted in the MT5 section....

 
Paul Anscombe #:

that is MT4  you have posted in the MT5 section....

Apologies for that 
I will repost it in the right forum 

 
DGRL #: For your reference here the link to the 2 functions that do excist


https://docs.mql4.com/objects/objectset

https://docs.mql4.com/objects/objectsettext

Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
          General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon.