Strategies calling strategies.  [SOLVED]

Questions about MultiCharts and user contributed studies.
biffhero
Posts: 47
Joined: 22 Sep 2020
Has thanked: 29 times
Been thanked: 7 times

Strategies calling strategies.

Postby biffhero » 27 Sep 2020

I am looking at this page:

https://www.multicharts.com/trading-sof ... a_function

and it looks like the signal or indicator is calling a function, is that a correct understanding?

Here is why I ask.

While I am working on signals, I have a lot of template code that gets copied into each one. One purpose for this is to evaluate different strategies for different times of the day, and things like that. For example:

Code: Select all

Inputs: timeMorningStart( 930 ), timeMorningStop( 1200 ), timeAfternoonStart( 1200 ), timeAfternoonStop( 1545 ), dateStart ( 1200330 ), dateStop ( 1200925 ), minPrice ( 4 ), maxPrice ( 12 ), ... Variables: longFilter1( TRUE ), longFilter2( TRUE ), longFilter3( TRUE ), ShortFilter1( TRUE ), ShortFilter2( TRUE ), ShortFilter3( TRUE ), timeMorning ( FALSE ), timeAfternoon ( FALSE ), timeAllDay ( FALSE ), timeFilter1 ( FALSE ), dateFilter1 ( FALSE ), dateTimeFilter1 ( FALSE ), priceFilter1 ( FALSE ), ... // We need the final comparison so that the optimizer doesn't get crazy. timeMorning = ( ( time >= timeMorningStart ) and ( time <= timeMorningStop ) and ( timeMorningStart < timeMorningStop ) ); // We need the final comparison so that the optimizer doesn't get crazy. timeAfternoon = ( ( time >= timeAfternoonStart ) and ( time <= timeAfternoonStop ) and ( timeAfternoonStart < timeAfternoonStop ) ); timeAllDay = ( timeMorning or timeAfternoon ); // `timeFilter1 = ( timeAllDay ); timeFilter1 = ( timeAfternoon ); // timeFilter1 = ( TRUE ); dateFilter1 = ( ( Date >= dateStart ) and ( Date <= dateStop ) ); // dateFilter1 = ( TRUE ); dateTimeFilter1 = ( timeFilter1 and dateFilter1 ); priceFilter1 = ( (Close[0] >= minPrice) and (Close[0] < maxPrice) );
As you can see, this only changes when I have (yet another) "bright idea" on my "filter library". But it also means that I need to go back and update the "filter library" everywhere. Since git isn't as easy to use here as one would expect, ;-) , I *am* going to make mistakes.

Is it possible to have a signal called _filterStrategy and have that called (maybe with a "#include" ??) from the ones I am working on?

Did I just figure out why I need to use Global Variables?

Have fun,
Rob

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Strategies calling strategies.

Postby TJ » 28 Sep 2020

You have many ideas floating around,
I can make a short answer regarding function: Yes, you can offload some of the codes to a function.

For example, AVERAGE is a function; it can be called by an indicator or a strategy.
For example, MACD is a function; it can be called by an indicator or a strategy.

You can create a function called PINK, and adjust the hue to any variation of red you like.

MultiCharts includes a lot of code examples; you can open them and see how they work.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Strategies calling strategies.

Postby JoshM » 01 Oct 2020

While I am working on signals, I have a lot of template code that gets copied into each one.

(...)

Is it possible to have a signal called _filterStrategy and have that called (maybe with a "#include" ??) from the ones I am working on?
In addition to what TJ already covered, the specific thing quoted above is not possible: a signal cannot include another signal. If you can encapsulate part of the signal logic into a function, the signal can call that function. But signals cannot reference or include each other.

biffhero
Posts: 47
Joined: 22 Sep 2020
Has thanked: 29 times
Been thanked: 7 times

Re: Strategies calling strategies.  [SOLVED]

Postby biffhero » 20 Oct 2020

Thanks guys.

It seems like the "_functionName" world is where I will get the most return for my programming efforts.

I will look to create functions whenever possible.

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: Strategies calling strategies.

Postby wilkinsw » 21 Oct 2020

You can also use indicators as signal inputs, if that helps.

>Format Signal
>Inputs

Click on an input and then click on the grey box with 3 dots in the corner.

You can then choose an indicator, define its inputs and choose it's output that feeds your signals input.

I think it's a pretty cool feature that is easy to overlook.

biffhero
Posts: 47
Joined: 22 Sep 2020
Has thanked: 29 times
Been thanked: 7 times

Re: Strategies calling strategies.

Postby biffhero » 22 Oct 2020

Oh, yeah, I had come upon that one time. I didn't remember it at this time.

Thank you,
Rob


Return to “MultiCharts”