Single out defparam flatafter for a specific day

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #152912 quote
    Albaran
    Participant
    Average

    Hi there,

    It’s all in the title; how can we single out the very useful command DEFPARAM flatafter = time for a specific day and only for long positions?

    I’ve been trying all sorts of tweaking but to no avail I’m afraid…

    Cheers,

    #152913 quote
    robertogozzi
    Moderator
    Master

    Indeed DEFPARAM flatafter = time does not allow anything other than a TIME.

    To be able to exit on selected days, at a given time you can use OpenDayOfWeek and OpenTime:

    If OpenDayOfWeek = 3 or OpenDayOfWeek = 5 Then
       If OpenTime = 190000 Then
          If OnMarket Then
             Sell at Market
             Exitshort at Market
          Endif
       Endif
    Endif

    This will close any open trade at 190000 on Wednesday and on Friday.

    #152969 quote
    Albaran
    Participant
    Average

    Above won’t work because I forgot to mention that I work with LIMIT orders..

    I can’t squeeze a SELL AT MARKET command because of it; at least, I haven’t figured this out up untill now..

    #152971 quote
    robertogozzi
    Moderator
    Master

    With pending (Limit or Stop) if already triggered you can use the above snippet, while if not triggered they are automatically CANCELLED the next time your code is executed, so you just need to apply the above (modified) snippet not to enter at market after a given time:

    If OpenDayOfWeek = 3 or OpenDayOfWeek = 5 Then
       If OpenTime < 190000 Then
           BUY       1 contract AT MyLongEntryPrice  LIMIT  //or STOP
           SELLSHORT 1 contract AT MyShortEntryPrice LIMIT  //or STOP
       Else
           Sell      at Market
           Exitshort at Market
       Endif
    Else
       BUY       1 contract AT MyLongEntryPrice  LIMIT  //or STOP
       SELLSHORT 1 contract AT MyShortEntryPrice LIMIT  //or STOP
    Endif

    in this case you place a pending order, on Wed. or Fri., only before 190000 (while you make no check the other days). You will also close ALL open orders at 190000 on those two days.

    Albaran thanked this post
    #153070 quote
    Albaran
    Participant
    Average

    Tested and working, many thanks!

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

Single out defparam flatafter for a specific day


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Albaran @albaran Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Albaran
5 years, 2 months ago.

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