ParamToggle works fine, was: Not Working with Buy/Sell

I have tried to use a ParamToggle function to determine whether to show an indicator and whether to compute Buy and Sell signals or not. The toggle works fine for showing or not showing the indicator, but does not work for producing Buy/Sell signals. Backtesting produces no results whether "Use" is toggled on or off, and Backtesting shows the number of rows as 0. Why?

If I remove the "//" comment in the last line Backtesting gives results.

Please help me understand why the "Use" ParamToggle does not work with the Buy/Sell signals. Code example follows.

_SECTION_BEGIN("Testing"); // Test of ParamToggle
	Use  = ParamToggle("Use", "No|Yes", 0);
	bars = Param("Period", 50, 1, 100, 1);
	MovAvg = MA(C, bars); 

if (Use) Plot(MovAvg, "MovAvg", colorBlue);

if (Use) { Buy = C > MovAvg; Sell = C < MovAvg; }
// Buy = C > MovAvg; Sell = C < MovAvg;

After digging a little further I think I know the answer. The ParamToggle variable "Use" is associated with the chart, but when running a back test the ChartID is 0 and not the same as the ChartID used for displaying the indicator.

How can I use a ParamToggle variable to influence how and what is included in a back test?

Your thread subject is incorrect statement!

Any param function works fine.

Analysis has its own Parameter window.
So using chart window's param toggle for your code is not correct procedure to get output of backtest result list.

SEE below picture how to use in analysis:

Thanks fxshrat. Setting the parameters from the analysis window parameters box does the job. I mistakenly thought the analysis window parameter box was just there to make it easier to change parameters when only running a series of back tests.

Would be nice not to have to use two different parameter boxes (one for charts and one for analysis) especially when using a number of parameters as it is quite easy to miss getting all the settings the same in both, but does work as you said.

function gParamToggle( pname, plist, def ) {
    // by Herman v. d. Bergen
    local p;
    if ( Status( "action" ) == actionIndicator ) {
        p = ParamToggle( pname, plist, def );
        StaticVarSet( pname, p );
    } else
        p = StaticVarGet( pname );
    return p;

... Param value set in Indicator window will be used in Analysis too.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.