Coding required – Trade on specific day only via parameter

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #243292 quote
    OggyFluff77
    Participant
    New

    hi,

    that’s great – many thanks for coming back to me. my coding is very basic so i will need time to test this but really appreciate you sending over the code.

    regards

    #243456 quote
    OggyFluff77
    Participant
    New

    HI Roberto,

    ok, the array tables have been a game changer for me and work perfectly and I now have all 5 trading days with different parameters all working – so a massive thank you.

    in addition, I have managed to get the code working for opening a trade from a specific time for a specific day (using the ‘TimeRef = OpenTime’), so again – thank you, but I can not manage to get a trade to close at a certain time for a specific day.

    I do have a ‘DefParam FlatAfter’ that works very well in the main code but that closes trades at that one specific time for every day and I still would like the ability to close trades on different days at different times.

    I have tried all the suggestions above but none seem to work – anymore suggestions?

    thanks in advance

    #243457 quote
    robertogozzi
    Moderator
    Master

    I only can suggest what I posted at https://www.prorealcode.com/topic/coding-required-trade-on-specific-day-only-via-parameter/#post-242966.

    I can’t understand whythe version to open a trade works fine, while the verskion to close a trade doesn’t. What’s different between the two cases?

    #243468 quote
    PeterSt
    Participant
    Master

    Hi Roberto, hello Oggy,

    The difference will be that no code was provided for the task of closing :

    https://www.prorealcode.com/topic/coding-required-trade-on-specific-day-only-via-parameter/#post-242934

    So Oggy, you must copy the snippet as provided by Roberto in that post, change all the TimeRef references in that snippet o TimeRefClose, change all the tdx variables to tdClosex variables, make a tdCondClose variable for it (instead of tdCond) and use that as the condition for closing.
    Make the time span for closing small, like a startT of 204500 and endT of 210000 (a 15 minute time span).

    Does that help ?
    Peter

    #243472 quote
    OggyFluff77
    Participant
    New

    many thanks Roberto and Peter for coming back to me,

    i will try and resolve using the new suggestions, thank you, and revert but my coding is very basic so i may have to ask for the actual code as i can probably amend to make it work but not overly confident i can write it from scratch.

    thanks

    #243473 quote
    OggyFluff77
    Participant
    New

    ok so the change to close does not work at the moment but i am possibly/probably doing something wrong.

    I am no expert but could it be that the opening time of a trade has a reference in PRT which makes it easy to define –

    ie. TimeRef = OpenTime ( I assume in PRT code language that OpenTime does exactly what it says on the tin)

    so I think the closing of a trade doesn’t work because I can’t find a PRT definable reference for Closing a trade

    so I feel like I need specific parameter code for both Open – as previous – and then additional code for closing a trade at a certain time

    does that make sense?

    or am I barking up the wrong tree?

    thanks in advance

    #243476 quote
    robertogozzi
    Moderator
    Master

    This example works like a charm:

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ONCE startT = 090000                  //from 090000
    ONCE endT   = 180000                  //to   180000
    TimeRef     = OpenTime
    DayRef      = OpenDayOfWeek
    //
    td0         = 0 AND DayRef = 0 AND TimeRef >= startT AND TimeRef <= endT //Sun
    td1         = 1 AND DayRef = 1 AND TimeRef >= startT AND TimeRef <= endT //Mon
    td2         = 1 AND DayRef = 2 AND TimeRef >= 110000 AND TimeRef <= 160000 //Tue  EXCEPTION
    td3         = 1 AND DayRef = 3 AND TimeRef >= startT AND TimeRef <= endT //Wed
    td4         = 1 AND DayRef = 4 AND TimeRef >= 093000 AND TimeRef <= 130000 //Thu  EXCEPTION
    td5         = 1 AND DayRef = 5 AND TimeRef >= startT AND TimeRef <= endT //Fri
    td6         = 0 AND DayRef = 6 AND TimeRef >= startT AND TimeRef <= endT //Sat
    tdCond      = td0 OR td1 OR td2 OR td3 OR td4 OR td5 OR td6
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ONCE ClosingTime = 200000                  //200000
    TimeRef          = OpenTime
    DayRef           = OpenDayOfWeek
    //
    tc0              = 0 AND DayRef = 0 AND TimeRef = ClosingTime //Sun
    tc1              = 1 AND DayRef = 1 AND TimeRef = ClosingTime //Mon
    tc2              = 1 AND DayRef = 2 AND TimeRef = ClosingTime //Tue
    tc3              = 1 AND DayRef = 3 AND TimeRef = ClosingTime //Wed
    tc4              = 1 AND DayRef = 4 AND TimeRef = ClosingTime //Thu
    tc5              = 1 AND DayRef = 5 AND TimeRef = 150000 //Fri  EXCEPTION
    tc6              = 0 AND DayRef = 6 AND TimeRef = ClosingTime //Sat
    tcCond           = tc0 OR tc1 OR tc2 OR tc3 OR tc4 OR tc5 OR tc6
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    Sma20 = average[20,0](close)
    // Entry
    IF close CROSSES OVER Sma20 AND Not OnMarket AND tdCond THEN
       BUY AT highest[3](high) STOP
    ELSIF close CROSSES UNDER Sma20 AND Not OnMarket AND tdCond THEN
       SELLSHORT AT lowest[3](low) STOP
    ENDIF
    //
    // Exit
    IF OnMarket AND tcCond THEN
       SELL      AT Market
       EXITSHORT AT Market
    ENDIF
    // TP & SL
    set stop   %loss   0.3
    set target %profit 0.6
    #243486 quote
    OggyFluff77
    Participant
    New

    Hi Roberto,

    thanks for that code, appreciated as always, but that doesn’t work for me unfortunately. I tried manipulating it for my code and that didn’t work and then i tried copying the whole code into a blank workspace and that didn’t work either.

    taking a step back, i have 2 issues;

    1. the opening of a trade works using a from time but not within a range such as:
      1. example “td2         = 1 AND DayRef = 2 AND TimeRef >= 110000 AND TimeRef <= 160000 //Tue  EXCEPTION”  – it opens a trade using the first TimeRef , ie after 110000, but ignores the second TimeRef – therefore continuing to put trades on all day.
    2. I would like specific code to close a trade at a certain time per day.

    any other advice or suggestions?

    Thanks in advance

    #243716 quote
    robertogozzi
    Moderator
    Master

    Post the code you are using, specifying:

    • the timeframe used
    • the instrument or asset traded
    • date and time of a trade enterd or exited incorrectly.

    If you are using my code, just tell me, but post your version in case you modified it even slightly.

    #243790 quote
    OggyFluff77
    Participant
    New

    Hi Roberto,

    thank you for all your help – your code worked, I had implemented it incorrectly. I have now fixed it.

    thank you so much for all your help, and patience.

    regards

    robertogozzi thanked this post
Viewing 10 posts - 16 through 25 (of 25 total)
  • You must be logged in to reply to this topic.

Coding required – Trade on specific day only via parameter


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 24 replies,
has 4 voices, and was last updated by OggyFluff77
1 year ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/21/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...