How to buy/sell at Close of a day?

Forums ProRealTime English forum ProBuilder support How to buy/sell at Close of a day?

Viewing 15 posts - 1 through 15 (of 17 total)
  • #6364

    Hi,

    Looking for help with code.

    How to buy/sell on Close of a day? for forex, which 24hrs trading.

    I saw we can execute at a specific time (23hrs 30min 00sec), so used below code, but did not work.

    IF time >=233000 THEN

    SELL AT MARKET
    ENDIF

     

    Thanks in advance,

    Karun

    #6365

    Also saw a changelog on https://www.prorealtime.com/en/trading-system-programming-changelog

    the following instructions have been removed:

    • ThisBarOnClose
    • TodayOnClose
    • TomorrowClose

    How do we accomplish similar operations? sell/buy at a specific time?

     

    #6377

    Hi Karun, if you mean exit all positions at the end of the day, you can use the FlatAfter instruction:

    Is that what you were looking for?

     

     

    #6393

    Hi Nicolas,

    Thanks for your help.

    But I am looking for something like this.

    IF MyCondition AND time > 233000 THEN

    SELL AT MARKET

    ENDIF

     

    When I trade manually, I check for MyCondition 30 min before market and close my position manually, so want to do the same in backtesting.

     

    #6396

    Ok, so there may be something wrong into your “MyCondition” statement? Because “time>233000” is ok.

    And “SELL AT MARKET”, close the actual buy conditions on market.

    #6397

    Here is my code. made it simple, condition to be when closes above MA5. May be I shouldn’t take close of day and close of MA, right?

    // Conditions to exit long positions
    indicator2 = close
    indicator3 = ExponentialAverage[5](close)
    LongExitCondition = (indicator2 >= indicator3)

    IF LongOnMarket AND LongExitCondition AND TIME > 233000 THEN
    SELL AT MARKET
    ENDIF

    #6398

    How do I get price and Average[5] at a specific time (233000)?

    #6402

    You are already doing it right. On which timeframe do you use this strategy?

    #6403

    Daily. Below code does not work. It does not close at specified time. What am I doing wrong here?

    // Conditions to exit long positions

    indicator2 = close

    indicator3 = ExponentialAverage[5](close)

    LongExitCondition = (indicator2 >= indicator3)

    IF LongOnMarket AND LongExitCondition AND TIME > 233000 THEN

    SELL AT MARKET

    ENDIF

    #6405

    That’s why it doesn’t work I think. It’s because you are testing an hour that it is never met on the daily bar. Because 00.00.00 hour is not superior to 23.30.00.

     

    #6406

    So how do I fix it?

     

    #6408

    Hi Nicolas,

    I wrote some basic code to test this, hope you can help me. I wrote an indicator “InsideBar”, which is a bar inside previous bar.

    Then I wrote backtest for it. We buy the open of next day after an Insidebar indicator, and only thing I need is the exit of position on same day at 30 min before close.

    We can test this on any stock, and below code exits on next day after entry day,

    I want the entry and exit on SAME DAY, entry on open of day and exit at 30 min before market close.

    Hope you can help me.

     

    #6409

    Attaching screenshot….

    #6414

    Ok, with the whole code it is much clear now 🙂

    You should trade the strategy on intraday timeframe and use the daily candlesticks informations with DHIGH and DLOW.

    I rewrote the whole code to be more compliant with what you got in mind:

    So do your tests on 5 or even 1 minute timeframe for better prices executions.

    #6416

    Hi Nicolas,

    Thanks for your help and quick reply. Now I see the exit is happening at 153000 but the entry has issue.

    I debugged more and found the inside bar code you gave is behaving different in different time frames. I tested the same code on daily and hourly and see it’s giving false signals in hourly. Attached screenshot.

    This is what I have in code:

    REM inside bar

    c1= Dhigh(0) < Dhigh (1)
    c2= Dlow(0) > Dlow(1)

    insidebar= c1 and c2

    return insidebar

Viewing 15 posts - 1 through 15 (of 17 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login