How can I draw Buy/Sell arrows or symbols on the MT5 chart when my strategy generates a signal?

Asked by Radhesh Joshi · SOLVED
1 reply 407 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

I’m developing an MT5 strategy, and whenever my Buy or Sell condition is satisfied, I’d like to display an arrow or some symbol on the chart exactly at that candle.

For example, if a breakout happens, I want to draw a green up arrow below the breakout candle. Likewise, when a Sell signal occurs, I want to draw a red down arrow above the candle.

How can I achieve this in MQL5?

Posted Jul 27
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    Yes sir, you can easily do this using MT5 chart objects.

    The best approach is to create a reusable helper function that draws the required object whenever your strategy generates a signal.

    You only need to create this function once, and then call it wherever your Buy or Sell conditions are satisfied.

    You can place the following function anywhere above your OnTick() function.

    //+------------------------------------------------------------------+
    //| DRAW OBJECT ON CHART                                             |
    //+------------------------------------------------------------------+
    void DrawObject(string prefix, datetime time, double price, string objectType, color objColor, int width = 1, string text = "")
    {
       // Create unique name
       string name = prefix + "_" + IntegerToString((int)time) + "_" + IntegerToString(rand());
       
       // Delete existing object if any
       if(ObjectFind(0, name) >= 0)
          ObjectDelete(0, name);
       
       // Create arrow object
       if(!ObjectCreate(0, name, OBJ_ARROW, 0, time, price))
          return;
       
       //--- Set arrow code based on type
       if(objectType == "arrow_up")
          ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 233);   // Up arrow
       else if(objectType == "arrow_down")
          ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 234);   // Down arrow
       else if(objectType == "flag")
          ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 79);    // Flag
       else
          ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 234);   // Default Down arrow
       
       //--- Set properties
       ObjectSetInteger(0, name, OBJPROP_COLOR, objColor);
       ObjectSetInteger(0, name, OBJPROP_WIDTH, width);
       ObjectSetInteger(0, name, OBJPROP_BACK, false);
       ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
       ObjectSetInteger(0, name, OBJPROP_HIDDEN, false);
       
       //--- Tooltip
       ObjectSetString(0, name, OBJPROP_TOOLTIP, objectType + " at " + TimeToString(time, TIME_DATE | TIME_MINUTES | TIME_SECONDS));
    }

    Now, whenever your Buy condition is satisfied, simply call the function like this:

    double arrowPrice = breakoutLow - PipsToPoints(ArrowPips);
    DrawObject("Signal", breakoutTime, arrowPrice, "arrow_up", clrLime, 2);

    Similarly, for a Sell signal, you can draw a down arrow:

    double arrowPrice = breakoutHigh + PipsToPoints(ArrowPips);
    DrawObject("Signal", breakoutTime, arrowPrice, "arrow_down", clrRed, 2);

    That’s it.

    Whenever your strategy generates a signal, simply call DrawObject() with the appropriate parameters, and MT5 will plot the symbol on the chart automatically.

    You can also customise the symbols by changing the OBJPROP_ARROWCODE values. MT5 supports many different Wingdings symbols such as arrows, flags, stars, circles, check marks, and more.

    The DrawObject() function shown above is a reusable helper built using the official MQL object documentation. You can explore all available symbol codes here:

    –<https://docs.mql4.com/constants/objectconstants/wingdings>

    You can replace the arrow codes with any Wingdings code you like to display different symbols on your chart. This makes it easy to visually mark breakouts, entries, exits, reversals, or any other event generated by your strategy.

    Verified Solution
    • This is exactly what I am looking for, now I can be able to plot symbols in the MT5 also like TradingView. With the custom function it’s super easy to plot symbols and if we want to plot any new symbol then we will just have to add the code of that and that’s it. So, it’s really help me a lot! – Radhesh Joshi Jul 28
    Markdown supported · ```json for code blocks · paste or drop screenshots

    Be specific and kind. Never share API keys, passwords or personal account details.

    Welcome to the community

    Log in or create your account in under a minute.

    1. 1Mobile
    2. 2E-mail
    3. 3Password
    +91

    Have a password?

    By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.