Weird spikes on GRAPH results with MTF

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #103988 quote
    Vonasi
    Moderator
    Master

    I’m messing around with a long only MTF strategy that makes all its decisions and has all the code on the monthly and weekly time frames but trades on the daily chart but there is no code under a daily timeframe. This is purely to allow it to trade as one day divides into a week and divides into a month but a week does not divide into a month – Yes MTF confuses me sometimes too!

    I have an IF THEN condition which if it is met sells everything and within this same IF THEN I add one to a variable just so that I can graph the variable and see how many times the condition led to trades being closed. Nothing ever subtracts from the variable but when I GRAPH it I get the weird spikes shown in the image.

    Screenshot_7.png Screenshot_7.png
    #103990 quote
    GraHal
    Participant
    Master

    a week does not divide into a month – Yes MTF confuses me sometimes too!

    It doesn’t thought does it, but you know that so you must mean something different than I read?

    #103992 quote
    GraHal
    Participant
    Master

    Vonasi please … what keyword(s) do I need to search for to find your code for including trial / virtual trades in a strategy so that if > x losing trades the strategy does not trade until > y winning trades?

    Thanks

    #103993 quote
    Vonasi
    Moderator
    Master

    What I don’t get is if I am just using month and week time frames then I can only open and close trades on the first candle of a week so what difference does it make that a week does not divide into a month? If I am looking at indicator values either on the fly during the month or at the end of the week it is the same thing as I can only look at them at the end of the week as I only have two time frames.

    Anyway this is a little off topic – it was the spikes that was bugging me more as I can’t trust the results of the graph that is shown.

    #103996 quote
    GraHal
    Participant
    Master

    to search for to find your code

    Aha it was Nicolas code, but I was sure you did one also?

    ‘Simulated trades’ is the keyword anyway …. found the code via google.

    #104011 quote
    Nicolas
    Keymaster
    Master

    The spikes are only jumping from 1 to 2 or 2 to 3, so I think that  there must be something in the code that makes this behavior and might be linked to a calendar condition that doesn’t exist: such as bank holidays, gap, ..

    #104015 quote
    Vonasi
    Moderator
    Master

    There is no date conditions in the code at all. It simply looks for the low to be above a value on the monthly timeframe and then on the weekly timeframe checks for a down week and buys at the end of the week on a daily chart. There are two exit conditions both on the weekly chart and both contained within their own IF THEN ENDIF’s. There is never anything deducted from the ex variable so I don’t understand the spikes. The code is something like this:

    timeframe(monthly, updateonclose)
    mflag = 0
    if (my condition1) then 
    mflag = 1
    
    timeframe(weekly)
    wflag = 0
    if close < open then 
    wflag = 1
    
    if wflag and mflag then
    buy 1 contract at market
    endif
    
    if onmarket and (my exit condition1) then
    sell at market
    endif
    
    if onmarket and (my exit conditions) then
    sell at market
    ex = ex + 1
    endif
    
    graph ex
    #104016 quote
    Nicolas
    Keymaster
    Master

    Well, if there is nothing in the code that decrease the ex value, there is no reason that it jumps from 2 to 3 and then suddenly decrease from 3 to 2.

    BUT! Did you try with “updateonclose” for the weekly timeframe?

    #104020 quote
    Vonasi
    Moderator
    Master

    With UPDATEONCLOSE it draws the correct line but with DEFAULT it draws a line with the impossible spikes.

    #104021 quote
    Nicolas
    Keymaster
    Master

    Yes, so there is something that happens during the week between the open and the close, because if we only read the code at Close we have no spike.

    BTW, I still can’t understand how the ‘ex’ variable can decrease!

    #104031 quote
    Vonasi
    Moderator
    Master

    I still can’t understand how the ‘ex’ variable can decrease!

    This is why I posted it! It’s a weird MTF bug! As I’m only using it to count how many times a condition occurs and to graph that it is not so important but if it was a variable that I used in the code for decision making then that is a little more important.

    The first image is with DEFAULT and the second is with UPDATEONCLOSE. The value is different throughout except when it spikes.

    Screenshot_1.png Screenshot_1.png Screenshot_2.png Screenshot_2.png
    #104034 quote
    Vonasi
    Moderator
    Master

    I tried putting the GRAPH under the TIMEFRAME(DAILY) but that didn’t change anything.

    #104040 quote
    Nicolas
    Keymaster
    Master

    Ok so because it happens during the life of a weekly candlestick, it would be nice to find similarities of when it happens: specific day of the week? hole in the data? ..

    #104041 quote
    Vonasi
    Moderator
    Master

    It seems pretty random. The last spike was on a Wednesday when selling can only occur on a Monday.

    I even tried this to see if it was an issue with two exit conditions being true at the same time but it makes no difference:

    if onmarket and (exit condition1) then
    flag = 1
    ex = ex + 1
    endif
    
    if onmarket and (exit condition2) then
    flag = 1
    endif
    
    if flag = 1 then
    sell at market
    flag = 0
    endif
    
    graph ex
    #104055 quote
    Nicolas
    Keymaster
    Master

    selling can only occur on a Monday when you updateonclose a weekly timeframe.

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

Weird spikes on GRAPH results with MTF


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 15 replies,
has 3 voices, and was last updated by Vonasi
6 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/01/2019
Status: Active
Attachments: 4 files
Logo Logo
Loading...