Jump to content
Medved Trader Forums

Using an Indexed variable (such as Close, High, Low) as a function input


Thebattlefront

Recommended Posts

Hello,

I was wondering if it were possible to use a system-defined indexed variable as an argument to a function. For example, this function:

//----------------------------------------- lowest function

private double Lowest(double Value, int candle_Start, int candle_End)

{

double a = Min(candle_Start, candle_End, Value);

return a;

}

Returns an error because the variable "Value" is not an indexed variable. In this context, I'd like the variable "Value" to be one of either Close, Low, or High (something that is inherently an indexed variable) but I'm not sure how to declare the variable type in the function's argument. I know it's not double, but I don't know what exactly the variable type it is.

So an example of how I want this function to work is:

Lowest(Close, 0, 4)

Will return the lowest value of the close from day 0 to day 4.

Edit:

I understand I can separate the function definitions to be LowestClose(candle_start, candle_End) and LowestHigh(), LowestLow() etc but I'd like for the function to be more dynamic if I could make it that way because It allows for less repetition.

 

 

Edited by Thebattlefront
Link to comment
Share on other sites

Unfortunately no. The pre-processor does some "magic" to convert

Min(1, 10, Close)

to

Close.Min(1, 10, (i, x) => { return Close; });

It needs an indexed variable as that third parameter otherwise it's a problem.

You cannot even pass Close to the function as an IndexedPropertyDouble variable because the preprocessor converts Close to Close[0], and that breaks things.

Basically it is the convenience of preprocessor sugar that spoils things...

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...