Indicator to Draw Wingdings on Chart using Hotkeys 1-5

 

I was searching and couldn't find, so here's my version.

Simply move mouse where you want wingding and press 1-5.  It will create the wingding at mouse location.  Good for quickly marking up charts.


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
/* first you need to store the previous coordinates of the mouse 
*/
int previous_x=0,previous_y=0,previous_click=0;
int OnInit()
  {
  //reset on init
    previous_x=0;previous_y=0;previous_click=0;
  //enable the mouse track
    ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration 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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
// Input variables for each Wingding symbol
input int wingding1 = 129; // Wingding code for 1 key
input int wingding2 = 130; // Wingding code for 2 key
input int wingding3 = 131; // Wingding code for 3 key
input int wingding4 = 132; // Wingding code for 4 key
input int wingding5 = 133; // Wingding code for 5 key

input double symbolSize = 2; // Size of the Wingding symbol
input color symbolColor = clrYellow; // Color of the Wingding symbol

datetime time_result=0;
double   price_result=0.0;
int      subwindow_result=0;

// OnChartEvent function to handle chart events
void OnChartEvent(const int id, 
                  const long& lparam, 
                  const double& dparam, 
                  const string& sparam) {
 
  //when the mouse moves 
    if(id==CHARTEVENT_MOUSE_MOVE){
    //grab the x y and click 
      int x=(int)lparam,y=(int)dparam,click=(int)StringToInteger(sparam);
    //if the x or the y are different you are interested 
      if(x!=previous_x||y!=previous_y){
      //you need to get the time where the x axis of the mouse is pointing at 
        ChartXYToTimePrice(ChartID(),x,y,subwindow_result,time_result,price_result);
        //now you have the time at the location of the  x 
        //             the price at the location of the y
        //             and the subwindow #
        /*
        So , if the time returned is <= Time[0]
        // visual of mouse location
        if(time_result<=Time[0]){
        //then look for the bar index 
          int barTarget=iBarShift(_Symbol,_Period,time_result,true);
          Comment("Bar["+IntegerToString(barTarget)+"] "+TimeToString(time_result));
        }else{
        Comment("No Bar");
        }
        */
      }
    //pass the x y and click to the previous for recalling later 
      previous_x=x;
      previous_y=y;
      previous_click=click;
    } 
                  
    if (id == CHARTEVENT_KEYDOWN) {
        int wingdingCode = 0; // Variable to store the chosen Wingding code

        // Determine which key was pressed and set the corresponding Wingding code
        switch(lparam) {
            case '1': // If key '1' is pressed
                wingdingCode = wingding1;
                break;
            case '2': // If key '2' is pressed
                wingdingCode = wingding2;
                break;
            case '3': // If key '3' is pressed
                wingdingCode = wingding3;
                break;
            case '4': // If key '4' is pressed
                wingdingCode = wingding4;
                break;
            case '5': // If key '5' is pressed
                wingdingCode = wingding5;
                break;
        }

        // If a valid key was pressed, draw the Wingding
        if (wingdingCode != 0) {
            // Create a unique name for the object to avoid conflicts
            string objectName = "Wingding_" + IntegerToString(GetTickCount());

            // Draw the Wingding symbol at the cursor position
            ObjectCreate(0, objectName, OBJ_ARROW, 0, time_result, price_result);
            ObjectSetInteger(0, objectName, OBJPROP_ARROWCODE, wingdingCode);
            ObjectSetInteger(0, objectName, OBJPROP_COLOR, symbolColor);
            ObjectSetInteger(0, objectName, OBJPROP_WIDTH, symbolSize);
        }
    }
}
//+------------------------------------------------------------------+
 

Hi,

Thank you for the indicator, Im new to coding and i t's easier to learn from programs like this one.


Just one question, Im sorry if it's a silly one, its just I can't get with the way to delete them once I place them in the chart. I can't select them with double click

on them, neither they show up in the objects list in mt5.


Could you help me with this?


Thanks.
 
Alfredo2024 #:

Hi,

Thank you for the indicator, Im new to coding and i t's easier to learn from programs like this one.


Just one question, Im sorry if it's a silly one, its just I can't get with the way to delete them once I place them in the chart. I can't select them with double click

on them, neither they show up in the objects list in mt5.


Could you help me with this?


Thanks.

Thanks, I really don't know.  I wrote the for MT4. I'm surprised it works on MT5.  

 
Here's source file.
Files:
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  // Enable the mouse track
    ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, 
                  const long& lparam, 
                  const double& dparam, 
                  const string& sparam) {
    static int previous_x=0,previous_y=0;
    static datetime last_time=0;
    static double last_price=0.0;

  // When the mouse moves 
    if(id==CHARTEVENT_MOUSE_MOVE){
      // Grab the x y 
      int x=(int)lparam,y=(int)dparam;
      // If the x or the y are different you are interested 
      if(x!=previous_x||y!=previous_y){
        // You need to get the time and price where the mouse is pointing at
        double price;
        datetime time;
        int sub_window;
        if(ChartXYToTimePrice(ChartID(),x,y,sub_window,time,price)){
          // Store the last known good values
          last_time=time;
          last_price=price;
        }
        // Update the previous x and y
        previous_x=x;
        previous_y=y;
      }
    } 
                  
    if (id == CHARTEVENT_KEYDOWN) {
        int wingdingCode = 0; // Variable to store the chosen Wingding code

        // Determine which key was pressed and set the corresponding Wingding code
        switch(lparam) {
            case '1': wingdingCode = wingding1; break;
            case '2': wingdingCode = wingding2; break;
            case '3': wingdingCode = wingding3; break;
            case '4': wingdingCode = wingding4; break;
            case '5': wingdingCode = wingding5; break;
        }

        // If a valid key was pressed, draw the Wingding
        if (wingdingCode != 0 && last_time != 0) {
            // Create a unique name for the object to avoid conflicts
            string objectName = "Wingding_" + IntegerToString(GetTickCount());

            // Draw the Wingding symbol at the last known mouse chart position
            ObjectCreate(0, objectName, OBJ_ARROW, 0, last_time, last_price);
            ObjectSetInteger(0, objectName, OBJPROP_ARROWCODE, wingdingCode);
            ObjectSetInteger(0, objectName, OBJPROP_COLOR, symbolColor);
            ObjectSetInteger(0, objectName, OBJPROP_WIDTH, symbolSize);
        }
    }
}
//+------------------------------------------------------------------+