Javascript Fitness Function

Questions about MultiCharts and user contributed studies.
Aston01
Posts: 21
Joined: 24 Oct 2013

Javascript Fitness Function

Postby Aston01 » 20 Nov 2013

Unfortunately I don't have much experience with javascript and in writing a custom fitness function I am running into a bit of an issue somewhere. The problem is I am just not sure what is formatted wrong and causing the syntax error.

Code: Select all

var DayHigh = high;
var DayLow = low;

if (date<>date[1]) {DayHigh = high;}
if (date<>date[1]) {DayLow= low;} 

if (DayHigh > high) 
{DayHigh = DayHigh ;}
else  
{DayHigh = high;}
 
if (DayLow> low)
{DayLow= low;} 
else
{DayLow= DayLow;}  
 
var NP = NetProfit;
var OPP = OpenPositionProfit;
var PLB4Today = NP[1] + OPP[1] ;
var ProfToday = NP + OPP - PLB4Today ;



return ((ProfToday-PLB4Today) / (DayHigh - DayLow));
Any idea where I am possibly going wrong with the formatting ?


Update: I am referring specifically to the use in Portfolio Backtester, I can use SetCustomFitnessValue if I were going to use this on a conventional chart.
Last edited by Aston01 on 21 Nov 2013, edited 1 time in total.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Javascript Fitness Function

Postby Andrew MultiCharts » 21 Nov 2013

Hello Aston01,

I believe we talked yesterday in the live chat in regards to this, though i can see the code is slightly different from what I have shown in the chat. There is no such keyword as "return" in MC. What are you trying to do?

Aston01
Posts: 21
Joined: 24 Oct 2013

Re: Javascript Fitness Function

Postby Aston01 » 21 Nov 2013

Hi Andrew,

Yes, this is the same project we discussed yesterday. As we discussed the SetCustomFitnessValue keyword isn't currently supported under portfolio back testing so I was attempting to write a javascript version in the mean time. It seems somewhere along the line I didn't format the javascript version properly and it is causing a syntax error I just can't quite sort out what the error is.

I was hoping someone with a better understanding of javascript could possibly see where I made a mistake in my formatting.

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

Re: Javascript Fitness Function

Postby JoshM » 21 Nov 2013

(...) As we discussed the SetCustomFitnessValue keyword isn't currently supported under portfolio back testing so I was attempting to write a javascript version in the mean time. It seems somewhere along the line I didn't format the javascript version properly and it is causing a syntax error I just can't quite sort out what the error is.

I was hoping someone with a better understanding of javascript could possibly see where I made a mistake in my formatting.
I haven't used custom criteria in a while, but looking at your code you use high, low, date which are not available as far as I know (perhaps this changed recently?). Also see this thread with a lot of custom criteria examples.
(..)As we discussed the SetCustomFitnessValue keyword isn't currently supported under portfolio back testing (...)
When will this limitation on the Portfolio Backtester be removed, MC Support? The Portfolio Backtester really needs an overhaul:

For example:
PM strategy weighting,
PM walk-forward optimizations,
PM custom criteria fitness,
PM bar magnifier.

It's not okay how long we're already wishing for things like the Bar Magnifier for the Portfolio Backtester. Time to take algorithmic traders more serious, now that discretionary traders have their Volume Profile, T&S, Chart Trading, and other toys. ;)

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Javascript Fitness Function

Postby Andrew MultiCharts » 21 Nov 2013

When will this limitation on the Portfolio Backtester be removed, MC Support? The Portfolio Backtester really needs an overhaul:

For example:
PM strategy weighting,
PM walk-forward optimizations,
PM custom criteria fitness,
PM bar magnifier.

It's not okay how long we're already wishing for things like the Bar Magnifier for the Portfolio Backtester. Time to take algorithmic traders more serious, now that discretionary traders have their Volume Profile, T&S, Chart Trading, and other toys. ;)
Some things will be implemented, unfortunately no eta at the moment. I would say these are "not an easy tasks to do", but that would be a terrific underestimate.

Aston01
Posts: 21
Joined: 24 Oct 2013

Re: Javascript Fitness Function

Postby Aston01 » 21 Nov 2013

I haven't used custom criteria in a while, but looking at your code you use high, low, date which are not available as far as I know (perhaps this changed recently?).
Yeah, this was the basis for my discussion with Andrew yesterday, but we were talking about SetCustomFitnessValue which may be more flexible than the javascript implementation of the custom fitness criteria.

I honestly forgot to clarify that with him and that slight difference may very well be what is causing my issue.

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

Re: Javascript Fitness Function

Postby JoshM » 21 Nov 2013

Some things will be implemented, unfortunately no eta at the moment. I would say these are "not an easy tasks to do", but that would be a terrific underestimate.
I don't want to sound overly critical now, since that would not be fair towards you or the MultiCharts product, but if you say 'some things will be implemented', are you saying that at least one of those four things will not be implemented?

While I'm biased towards more features for the Portfolio Backtester, I'd say that at three of these (WFO, Bar Magnifier, Custom Criteria Fitness) are absolutely necessary. Otherwise, why add multi-currency support if all other features are still behind the MultiCharts charting software itself?
(..) I would say these are "not an easy tasks to do", but that would be a terrific underestimate.
That's certainly true, but in 2010 a need for the Bar Magnifier in the Portfolio Backtester was already expressed (the PM does not list its year of creation, but it's certainly older than 1.5 years).

Of course there are also other things to work on, but if it takes so long, shouldn't you (meaning: MultiCharts Support) get started on it today? ;)
Yeah, this was the basis for my discussion with Andrew yesterday, but we were talking about SetCustomFitnessValue which may be more flexible than the javascript implementation of the custom fitness criteria.

I honestly forgot to clarify that with him and that slight difference may very well be what is causing my issue.
SetCustomFitnessValue is indeed more flexible than Javascript implementation, but this doesn't work in the Portfolio Backtester (you said it yourself ;) ). So then you have to use Javascript, right? Oh, you mean regular signals in non-Portfolio Backtester?

I now see that your first post did not mentioned the Portfolio Backtester, so I might have misunderstood you. If you want to use SetCustomFitnessValue, you need to convert your code to something like this (untested!):

Code: Select all

Variables:
dayHigh(0), dayLow(0), NP(0), OPP(0), PLB4Today(0), ProfToday(0);

if (date<>date[1]) then begin
dayHigh = 0;
dayLow = 99999;
end;

dayLow = MinList(dayLow, Low);
dayHigh = MaxList(dayHigh, High);

NP = NetProfit;
OPP = OpenPositionProfit;
PLB4Today = NP[1] + OPP[1] ;
ProfToday = NP + OPP - PLB4Today;

SetCustomFitnessValue ( ((ProfToday-PLB4Today) / (dayHigh - dayLow)) );

Aston01
Posts: 21
Joined: 24 Oct 2013

Re: Javascript Fitness Function

Postby Aston01 » 21 Nov 2013

Wow, your right I forgot to even mention that my question was in regards to Portfolio Backtester.

(I have updated my original post accordingly)

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Javascript Fitness Function

Postby Andrew MultiCharts » 25 Nov 2013

I don't want to sound overly critical now, since that would not be fair towards you or the MultiCharts product, but if you say 'some things will be implemented', are you saying that at least one of those four things will not be implemented?
No. I am saying some will be sooner than others. They are not coming all at once.
Of course there are also other things to work on, but if it takes so long, shouldn't you (meaning: MultiCharts Support) get started on it today? ;)
Features are implemented according to their priorities, complexity of the implementation, number of votes in PM and so on. If you are interested in us to develop this for you on paid basis within a specific time period, please contact us (support@multicharts.com) and we will evaluate the project. ;)


Return to “MultiCharts”