Exit trade just before the close for the day

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #167702 quote
    erike
    Participant
    Junior

    Hi,
    I have need to test a strategy that close an open trade just before (say 17:20 when the session close at 17:30) close of the 5th day.
    Do anyone have a code snippet for this?

    #167704 quote
    nonetheless
    Participant
    Master

    this should do it:

    if CurrentDayOfWeek = 5 and time = 172000 then
    sell at market
    exitshort at market
    endif
    Midlanddave thanked this post
    #167705 quote
    Vonasi
    Moderator
    Master

    When using the example given by nonetheless you have to ensure that the chart you are using the strategy on has a 172000 candle. So you must run it on  a TF of  10 minutes or faster.

    nonetheless and erike thanked this post
    #167708 quote
    erike
    Participant
    Junior

    Thank you

    I guess I was a bit unclear about the day of exit. I meant 5th day after entry not day of week.
    Do I have to choose a time unit in backtesting that correspond to time? In the this case 1 hour of less?
    In this strategy I have only daily bars. Does that mean I can’t solve my need?

    #167712 quote
    erike
    Participant
    Junior

    @Vonasi: You answered one of my question before I had written it 😉

    #167720 quote
    nonetheless
    Participant
    Master

    In this strategy I have only daily bars

    Sorry Erike, when you mentioned 17:20, I assumed you were working with a short time frame. I may be wrong but I don’t think you can close in the middle of a daily candle without using MTF

    erike thanked this post
    #167745 quote
    erike
    Participant
    Junior

    No problems @nonetheless .
    I guess I have to read up on MTF. Any suggestions were to start?

    #167750 quote
    nonetheless
    Participant
    Master
    #167761 quote
    robertogozzi
    Moderator
    Master

    There you go (not tested):

    Timeframe(Daily,UpdateOnClose)
    Once Count = 0
    Count = Count + OnMarket
    If MyLongConditions and Not OnMarket then
       Buy 1 contract at Market
       Count = 1
       Set Target pProfit 500
       Set Stop   pLoss   250
    Endif
    If MyShortConditions and Not OnMarket then
       Sellshort 1 contract at Market
       Count = 1
       Set Target pProfit 500
       Set Stop   pLoss   250
    Endif
    //
    Timeframe(default)
    If Count = 5 and Time = 172000 Then
       Sell      at Market
       Exitshort at Market
    Endif
    

    You need to run this strategy from a 10-minute (or lower) chart.

    Midlanddave and erike thanked this post
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Exit trade just before the close for the day


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
erike @erike Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by robertogozzi
4 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/21/2021
Status: Active
Attachments: No files
Logo Logo
Loading...