help for a newby Time specific actions

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #41507 quote
    Bob Harris
    Participant
    Average

    Hi,

    I have written a script that is intended to run once a day at a specific time,

     

    //Testing if it’s time to wake up !

    IF (CurrentTime = 120101)AND not DaysForbiddenEntry THEN

    ///get entry for current candle – variable B
    B = (Open[0])

    //// get entry possition for previou candle – variable A
    A = (Open[1])

     

    When I try to backtest no positions are opened, is this because you cant backtest a specific time, or is there a fault else-ware in the code?

     

    thanks

    #41512 quote
    JC_Bywan
    Moderator
    Master
    Hi, Can’t say why a backtest doesn’ take positions without seeing the full code with instructions “buy” or “sellshort”, but assuming the rest of this unseen backtest is based on presented time condition only, in case it helps, a common beginner confusion about time in PRT is to assume “time” should return the same value as your watch. But “Time” in PRT is not pure current time, it is the closing time of a candle. For example, when you’re looking at an instrument in a 1h timeframe, a 1h candle starting at 14h would see its “time” value be 15h regardless of when between 14h and 15h you look at it (well, 150000 rather, because of format, but you get the idea). Consequently, any test of a candle “time” being compared to 120101 would work only for timeframes in x seconds having candles in its history finishing at 12h01mn01s exactly, but wouldn’t work with any “x minutes” or “x hour” timeframes which couldn’t possibly finish at 12h01mn01s. (further details on temporal constants p.8-9 https://www.prorealtime.com/en/pdf/probuilder.pdf

    >> Please update your country flag by choosing a location in your profile settings. Thank you 🙂 <<

    #41520 quote
    robertogozzi
    Moderator
    Master
    Noobywan is right, to do what you want you should use a 1-sec Timeframe or wait for the multitimeframe feature that is rumoured to be released by the end of this year.
    #41596 quote
    Bob Harris
    Participant
    Average
    Thank you for your help, you really  helped, But as always one solution highlights the next issue when i place a trade, is there any way I can stop a subsequent trade being place for a set period of time, I’m using DEFRARM CumulateOrders = False to stop orders in the same direction from being placed, but if the market moves against me it tries to place an order in the opposite direction and effectively closes the position.   any pointers gratefully received Thanks
    #41605 quote
    robertogozzi
    Moderator
    Master
    DEFPARAM CumulateOrders = ....
    is only evaluated when the strategy is launched and cannot be modified at runtime. To achieve your goal you have to  use
    time
    to allow trading or not, as follows:
    DEFPARAM CumulateOrders = FALSE
       .
       .
       .
    IF time >= 100000 AND time <= 160000 then
       IF (long conditions) THEN
          BUY 1 CONTRACT AT MARKET
       ENDIF
       IF (short conditions) THEN
          SELLSHORT 1 CONTRACT AT MARKET
       ENDIF
    ENDIF
    If that is what you mean.
    #41634 quote
    Bob Harris
    Participant
    Average
    Thank you for that. I have solved the opening in a time window issue but it has highlighted a second issue But I don’t think I expressed my problem very well For an example, The conditions are set up to go long and it opens a position. I want that position to stay open until either the stop-loss is hit or profit is triggered (hopefully the profit). As it stand currently if, while the position is open, the conditions to ‘go short’ are met it trues to open a short position and effectively closes my trade early. is there any way that, while any position is open it cant place any further trades until the current position closes by hitting the profit target or the stop loss. Thanks
    #41666 quote
    JC_Bywan
    Moderator
    Master
    “onmarket” should be the useful keyword to avoid “take and reverse” when you want the existing trade to go all the way not stopped prematurely by opposite entry conditions being met (p.17 https://www.prorealtime.com/en/pdf/probacktest.pdf ) Would use it by adding the condition “if not onmarket” to your existing entry conditions, so that it considers a new entry only if onmarket=0, then it shouldn’t open any opposite direction trade while there’s one still ongoing
    if not onmarket and [add here your long order entry conditions] then
    buy etc...
    
    if not onmarket and [add here your short order entry conditions] then
    sellshort etc...
    #41676 quote
    robertogozzi
    Moderator
    Master
    Sorry for not being able to insert code because I’m over my phone till friday. DEFPARAM FlatAfter=hhmmss should not be used in your case, ’cause it closes any open trade at that specific time. DEFPARAM CumulateOrders=True should not be used ’cause it allows more than one trade open at the same time. So the solution is to ban more than one trade and let it run till a SL or TP is hit. In case some conditions, the other way round, arise you may test LONGONMARKET to close any long trade open and then start a new SHORT trade. Test SHORTONMARKET, instrad, to close short trades and then go Long. Roberto
    #41767 quote
    Bob Harris
    Participant
    Average
    Brilliant, Thanks for that, the script works perfectly in back testing   Now to see if it work’s in the real world   Thank you to all who helped
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

help for a newby Time specific actions


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
Bob Harris @bob_harris Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by Bob Harris
8 years, 6 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 07/24/2017
Status: Active
Attachments: No files
Logo Logo
Loading...