"if" statement for object text...

 

How would I do something like this...

if (some condition)
{
ObjectSetText("lblText", "Strong Buy", 24, "Arial", Green);
}

if (lblText == "Strong Buy")
{
ObjectSetText("lblConsensus", "The consensus is a strong buy.", 24, "Arial", "151,0,0");
}

The second condition is based on the contents of a label. This will eventually be based off of several conditions, but I'm new and still just trying to learn.

Also, I'm trying to do a different color outside the standard by using color codes. How do I do this? I tried quotes, but my text disappears.

Thank you.

 

The function you would usually use is ObjectGet

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

Then use a parameter

https://docs.mql4.com/constants/objects/properties

but there does not seem to be a text parameter and there is a separate function ObjectSettext.

Looks like you need to save the text to a separate string for later use.

 
Collusion:

Also, I'm trying to do a different color outside the standard by using color codes. How do I do this? I tried quotes, but my text disappears.

here is the data you need ...

https://docs.mql4.com/basis/types/color

 
void TLine( string name, datetime T0, double P0, datetime T1, double P1,
            color clr, double V0=INF, double V1=INF, bool ray=false){
    if (!Show.Objects)  return;                 #define WINDOW_MAIN 0
    if      (ObjectMove( name, 0, T0, P0 ))     ObjectMove(name, 1, T1, P1);
    else if (!ObjectCreate( name, OBJ_TREND, WINDOW_MAIN, T0, P0, T1, P1 ))
        Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() );
    else if (!ObjectSet( name, OBJPROP_RAY, ray ))
        Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError());
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [4] failed: ", GetLastError());
    if (V0 == INF || V0 == P0){
        string  P0t = PriceToStr(P0);           if (MathAbs(P0 - P1) >= Point)
                P0t = StringConcatenate(P0t, " to ", PriceToStr(P1));       }
    else if (V0 == V1)  P0t = StringConcatenate(V0,""); // Suppress trailing to
    else                P0t = StringConcatenate(V0, " to ", V1);
    if (!ObjectSetText(name, P0t, 10))
        Alert("ObjectSetText(",name,") [2] failed: ", GetLastError());
}