Close at a specific time within a ONCE function

Forums ProRealTime English forum ProOrder support Close at a specific time within a ONCE function

Viewing 9 posts - 1 through 9 (of 9 total)
  • #130066

    Hi there,

    I’m stuck with below idea. Example is being made with the CAC40.

    In order to decide whether I want to go long, short or both at the same time with the same system, I would like to create a proxy of the current trend.

    The idea is this; at the open of each day, so at 9am, I calculate the ongoing trend (up or down) by applying below formula.

    It only needs to be calculated ONCE so I figure that if I code it like this:

    The only problem (if above code is correct) is that I would like to define the close of the previous day at a specific hour, in this example at 173000 (= Dclose(1)) but don’t know how to code it!
    Could anyone offer a suggestion? (Above idea is not meant to be used as an indicator!)
    I know that there is the possibility of working with a customclose by changing the hours in the chartsettings but then, you’re limited to trading only within that timeframe which is not the idea I had in mind.

    Thanks for the replies!

    #130071

    It should read:

     

    1 user thanked author for this post.
    #130075

    You don’t need to use ONCE in your code. ONCE is simply an instruction that means that anything after it is not done or read again after the very first bar the code is set running on.

    You can save a value at any time simply with the following:

    Then just use dayclose instead of Dclose(1) in your calculations.

    Obviously you have to run your strategy only on timeframes that have a 173000 candle.

    1 user thanked author for this post.
    #130093

    @Vonasi:

    Won’t there be a problem with these lines as time = 173000 is the time of the close of the previous day? And since today time = 173000 hasn’t happened yet when I use it in my formula at 9am, it would return “Idunnowhat”…

    Also, the formula (((Open Dclose(1))/Dclose(1))*100) only needs to calculated one time at 9am; the result of the formula will tell my system whether to go only long or short during that day. There are going to be multiple openings and closings of long or short positions during the day. That’s why I used a ONCE function…

     

     

    #130100

    I think you are confusing yourself! Once a variable value is set then it remains at that value until it is changed. So my code simply stores the close at 1730 everyday and the value remains fixed until the next 1730 comes along. So at 0900 the value is the close at the previous 1730.

    Add my code to Roberto’s code and add a little extra IF THEN to ensure we have had at least one 1730 close and that’s it.

     

    1 user thanked author for this post.
    #130205

    Okay, thanks a lot to both of you, it’s much appreiciated!

    #164027

    Is this code valid? What i am trying to do is store value of TAKEPROFIT=1 once after trade is entered price moves above supertrend. This is because, if trade is entered trade is closed before price moves above supertrend completely as the exit is based on supertrend itself.

    Because this code is for partial exit, I cannot return TREND>0 and trail the stop with supertrend.

    Not sure how to make this work, any help would be great

     

     

    #164035

    I don’t understand what you are trying to do but you are definitely not using ONCE as it is intended. As said before in this topic:

    ONCE is simply an instruction that means that anything after it is not done or read again after the very first bar the code is set running on.

    You cannot ever be ONMARKET on the very first bar a strategy sees so your ONCE will never ever be read on that first bar.

    #164063

    Ok thanks for clarification.

    What I am trying to achieve here is the ability to exit using say when price closes below 1HR supertrend. The entry can be before the 1HR supertrend turns bullish. Because the exit is based on close under supertrend, the exit condition is triggered in the process of price moving above supertrend after entry well before intended exit.

    The solution could be to allow the price to close above supertrend first and when price closes under supertrend after rally, exit the trade.

    I have encountered this issue in every indicator making it difficult to use them esp. when entry is before the indicator turned bullish.

     

Viewing 9 posts - 1 through 9 (of 9 total)

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