Pulldown menu in show_inputs within a script possible?

 

Hello,

I just want to know if it is possible to modify this script that I don't need to type the template's name. Instead I want to define some template names like {"temp1", "temp2", "temp3"} and these should be shown in a pulldown menu.

Difficult to explain but I hope it is understandable what I mean. You get a similar pulldown menu when you click on a line, open the dialog box and choose between different line widths.

#property strict
#property show_inputs
extern string templateName = "";
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ChartApplyTemplate(0, templateName);
  }
 

I thought about something like this but this syntax is obviously wrong:

#property strict
#property show_inputs
extern enum templateName {temp1, temp2, temp3};
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ChartApplyTemplate(0, templateName);
  }
 

Well, enums have uints under the hood. That is, they're both 4 bytes. But the name can be converted to a string.

As long as your template names can be expressed as proper variable name, i.e. no spaces or odd characters, you could use the enum construct, then convert it to a string when you need it.

enum EnTemplates
{
    template1,
    template2,
    template3,
    template4
};

//--- input parameters
input EnTemplates InpTemplate = template2;

int OnInit()
{
    const string templateName = EnumToString(InpTemplate);
    PrintFormat("The chosen template is [%s]",templateName);
    
    // Do something with the template here, e.g. 
    // ChartApplyTemplate(ChartID,templateName);

    return INIT_SUCCEEDED;
}
 
Anthony Garot:

Well, enums have uints under the hood. That is, they're both 4 bytes. But the name can be converted to a string.

As long as your template names can be expressed as proper variable name, i.e. no spaces or odd characters, you could use the enum construct, then convert it to a string when you need it.

This is exactly what I was looking for. Thank you very very much!!!

Reason: