Time Functions not working?

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #135826 quote
    Mike
    Participant
    Junior

    Hi

    Can anyone see why this code won’t run.  If I comment IN the defparams the code opens trades on the 1 minute time frame but nothing higher.  If I comment the defparams out then no trades are opened.

    I plagiarised “Morning CAC 40” from the library and it won’t open any trades either.  I have had differing results on my Spreadbet and CFD accounts in the past. Neither will open any trades.

    Thanks in advance

     

    DEFPARAM CumulateOrders = False
    //defparam flatbefore = 143000
    //defparam flatafter = 143300
    
    Stoplevel = SL
    Profitlevel = pl
    
    IF time = 142950 THEN
    SET STOP pLOSS StopLevel
    SET TARGET pPROFIT ProfitLevel
    SELLSHORT 10 perpoint at market
    ENDIF
    #135828 quote
    robertogozzi
    Moderator
    Master

    In your example you used 50 seconds, so only if a candle closes on that boundary (try on a 10-second TF).

    If you use 142900 it’ll work on a 1-minute TF, if you use 142500 it’ll work also on a 5-minute TF, and so forth…

    Mike thanked this post
    #135829 quote
    GraHal
    Participant
    Master

    on the 1 minute time frame but nothing higher

    That’s because you are using 143300 and so that time can only be met on a 1 min or less TF.

    IF time = 142950 THEN

    This means that your conditions must be met at that exact time else no trade.

    Mike thanked this post
    #135830 quote
    Mike
    Participant
    Junior

    Thanks Roberto

    I thought “time” versus “currenttime” worked on the clock time, irrespective of the candle close…Have I misunderstood that?

    #135831 quote
    Mike
    Participant
    Junior

    Thanks GraHal

    I thought my condition was the time of day, which must occur once every 24 hours, at which point I thought my trade would open.  Again, I may have this wrong but I think “time” is supposed to relate to “real” time and “currenttime” is candles based.

    It sounds like I can’t open a trade at this very specif time.  Is that correct?

    #135836 quote
    GraHal
    Participant
    Master

    It sounds like I can’t open a trade at this very specif time.  Is that correct?

    I was wrong, you can open at that specific time.

    I thought you have additional conditions, but now I see you haven’t.

    See Roberto comment re use of 142950

    Mike thanked this post
    #135886 quote
    Mike
    Participant
    Junior

    Sorry, I had the “time” and “currenttime” functions reversed.  It’s “currenttime” that is supposed to work independently of the candle/bar.

    The code still opens no trades on the daily timeframe.  It does, As Roberto suggested it would, open 1 trade at 142950 on the 10 second time frame.  However, to reiterate, this seems to be acting like the “time” function” and not the “currenttime” function.

    I have to imagine I can open a trade per day at a specific time…. Any further thoughts?

    Many thanks

    DEFPARAM CumulateOrders = False
    //defparam flatbefore = 143000
    //defparam flatafter = 143300
    
    Stoplevel = SL
    Profitlevel = pl
    
    IF currenttime = 142950 THEN
    SET STOP pLOSS StopLevel
    SET TARGET pPROFIT ProfitLevel
    SELLSHORT 10 perpoint at market
    ENDIF
    #135896 quote
    robertogozzi
    Moderator
    Master

    As from Nicolas’ explanation in a comment to official documentation “CurrentTime is the one of the official timezone where the instrument is traded.

    So if you trade Nikkei and it’s 11am UTC+0 and the bar is labelled  100000, OPENTIME will return 100000 (opening time) TIME returns 110000 (closing time), CURRENTTIME will return 110000 + TZ difference for Japan.

    Mike thanked this post
    #135897 quote
    GraHal
    Participant
    Master

    Above added as Log 223 here …

    Snippet Link Library

    I added the Comment … not code but worthy of logging here! 🙂

    robertogozzi thanked this post
    #135898 quote
    Mike
    Participant
    Junior

    Thanks again Roberto – yes, I know I will have to offset the time zone difference and my understanding of CURRENTTIME is as you/Nicolas describe it.   As a quick start I just wanted to get the code operational.  I still don’t see why “currenttime” won’t trigger one trade every 24 hours.  CURRENTTIME is acting like TIME.  Is this a bug or am I just not getting it!?

    To double check I tried this on the DAX and still no trades.

    #135899 quote
    Mike
    Participant
    Junior

    Droll 🙂

    #135900 quote
    Vonasi
    Moderator
    Master

    Code is read and decisions on orders made at the close of every candle. At this point the only times that the strategy can use are the ones at the open (OPENTIME) and at the close (TIME) of that candle. If you want a trade to open at time = 142950 then you must ensure that your chart has a candle that has a time of 142950.

    Mike and Nicolas thanked this post
    #135901 quote
    robertogozzi
    Moderator
    Master

    Just trying to figure… maybe the trade is still open next day due to high TP or SL and no further entry is allowed.

    Mike thanked this post
    #135902 quote
    Mike
    Participant
    Junior

    Thanks Vonasi

    The fact the code operates at the close of the candle is the point I had lost sight of!

    #135903 quote
    Mike
    Participant
    Junior

    Thanks for the thoughts Roberto – Vonasi has got it into my head my it’s not working as I had hoped.

    I appreciate your time

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

Time Functions not working?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mike @mikemccloskey-co Participant
Summary

This topic contains 14 replies,
has 4 voices, and was last updated by Mike
5 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/13/2020
Status: Active
Attachments: No files
Logo Logo
Loading...