Indicator Display different in backtester.

Moderator: admin

Indicator Display different in backtester.

Postby jch001 » Tue Dec 08, 2015 1:03 pm

Hi I wonder if you can help or point me in the right direction.

I have a simple indicator I use for a strategy. I draw the high and low of a 30 min candle on a 1 min chart at the close of the 30min candle.
If the price action is closer to the bottom/top of the range I draw an arrow pointing to the line it is Furthest from. This works brilliantly in the indicator debugger and in Marketscope. However in the back-tester I get some odd behaviour. I would say it works 95% of the time. Please NOTE: The strategy in the backtester uses the correct value from the indicator, it is only the display of the indicator that doesn't work from time to time, which makes it hard to validate results.
I have attached an example of the sample screenshots from marketscope and the backtester. Note the same 1min candle validates too different sides of the range, in the backtester display this is incorrect.

can you see what I am doing wrong from the code sample below? or am I missing some setting in the backtester?

Code: Select all
        h = (high - close)/source:pipSize();                        -- distance from top range
        l = (close - low)/source:pipSize();                          -- distance from bottom range
        p = (high - low)/source:pipSize();                          -- pip range
        c = p*(instance.parameters.Percentage/100);              -- pip amount of percentage of range


 
        -- added to record at current candle close if we are near the top or the bottom of the range (not both)
        -- at end of range time see if we are nearer the top or the bottom set one - verify the opposite of the one its closest too
        if (neartop == false) and (nearbottom == false) and (source:date(period) >= adjustedtime) and extended == nil and not(rangeverified) then
      
         -- furthest from the top than bottom
         -- distance from bottom must be greater than retrace percentage
            if (l > h) and (l > c) then
                -- its near the top, so bottom verified
                neartop = true;
                --nearbottom = false;
                if not(instance.parameters.RunningInStrategy) then
                    -- NOTE: paste the picture on the previous closed candle as this is the one its based on.
                    Short:set(period-1, source[period-1], "\234"); --change the symbol to something else
                end
            end
           
         -- furthest from the bottom than top
         -- distance from top must be greater than retrace percentage
            if (h > l) and (h > c) then   
                -- if its not near top it must be near bottom
                --neartop = false;
                nearbottom = true;
                if not(instance.parameters.RunningInStrategy) then
                    -- NOTE: paste the picture on the previous closed candle as this is the one its based on.
                    Long:set(period-1, source[period-1], "\233"); --change the symbol to something else
                end 
            end
        end
Attachments
example.jpg
jch001
 
Posts: 14
Joined: Tue Aug 28, 2012 3:41 am

Re: Indicator Display different in backtester.

Postby Julia CJ » Wed Dec 09, 2015 6:28 am

Hi Jch001,

It is hard to say why the issue happens in accordance with the specified code.
Please output the parameter values in log. This will help us find a reason of such behavior.
Julia CJ
 

Re: Indicator Display different in backtester.

Postby jch001 » Wed Dec 09, 2015 7:54 am

Hi, thanks for the response. the issue is with the backtester display only and as far as I'm aware I can't output the parameter values. If I could I would be easily able to fix it. the behaviour is correct in the indicator debugger (marketscope and the indicator values used by the backtester to calculate the results).

but, for arguments sake. these are the parameter values from the indicator debugger. somehow the backtester display is getting the high and the low the wrong way round or something (I'm speculating... I just don't know).

Code: Select all
        h = (high - close)/source:pipSize();                        -- distance from top range
        l = (close - low)/source:pipSize();                          -- distance from bottom range
        p = (high - low)/source:pipSize();                          -- pip range
        c = p*(instance.parameters.Percentage/100);              -- pip amount of percentage of range


high = 1.089220 (of 30min candle)
close = 1.087090 (of the 1 min candle)
low = 1.086960 (of 30min candle)

h = 21.3
l = 1.3
p = 22.6
c = 8.362
jch001
 
Posts: 14
Joined: Tue Aug 28, 2012 3:41 am

Re: Indicator Display different in backtester.

Postby Julia CJ » Fri Dec 11, 2015 4:21 am

Hi Jch001,

as far as I'm aware I can't output the parameter values

You can output the values:

function writeToLog(str)
local f;
while (f == nil) do
f = io.open("D:\\test.log", "a");
end
f:write(str .. "\n");
f:close();
end
Julia CJ
 

Re: Indicator Display different in backtester.

Postby jch001 » Tue Dec 15, 2015 2:13 pm

Hi Julia, thank you very much for the reply. With that function I can now debug what is going on in the Backtester. Out of interest is there a way to write out a log to VB or another language. so ultimately I can save logs in a database?

The issue outlined earlier is being caused by the wrong 1 min candle being returned (this only occurs in the Backtester display)

I have a 1min candle - fastcandles

Code: Select all
core.findDate(fastcandles, source:date(period), true)


this returns 1440 normally, in the Backtester I get -1, I have tried swapping the <precise> option to false, I get the same result.
the period is correct in both 180
and source:date(period) - 42342.125 which is correct in both (8am).

this gives me an incorrect 1 min candle in the Backtester display, so my close amount is incorrect.

do you know how I can fix this?
jch001
 
Posts: 14
Joined: Tue Aug 28, 2012 3:41 am

Re: Indicator Display different in backtester.

Postby Julia CJ » Wed Dec 16, 2015 3:58 am

Hi Jch001,

Out of interest is there a way to write out a log to VB or another language


You can see the example for C# here.

do you know how I can fix this?


Please try to clean “Quotes Manager” (Charts->File->Quotes Manager->Remove Quotes...).
If it does not help, please send your Backtester project at ycherepanova@gehtsoft.com.
We will investigate this issue.
Julia CJ
 

Re: Indicator Display different in backtester.

Postby jch001 » Wed Dec 16, 2015 1:39 pm

Julia, thank you very much for the help, I will check out that link. I have managed to solve the issue with your help.

Code: Select all
        if source:isAlive() then
            to = 0;
        else
            to = getopening(source:date(source:size() - 1));
        end


the above code caused the issue. it worked fine when the source was Alive... just not in the backtester display. I wasn't returning enough candles getopening(source:date(source:size() - 1)
I have modified this and it works as expected.

thanks again.
jch001
 
Posts: 14
Joined: Tue Aug 28, 2012 3:41 am


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 30 guests