Trading two timeslots per day

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #200654 quote
    VogeltjeVogeltje
    Participant
    New
    I would like to trade around the time Europe opens  (say 8.30 – 11.00 West-European time) and around the time the US opens (say 15.00 – 16.30 in West European time) I can write: DEFPARAM FLATBEFORE = 083000 DEFPARAM FLATAFTER = 110000 and that works fine for that timeslot. But when I double this to DEFPARAM FLATBEFORE = 083000 DEFPARAM FLATAFTER = 110000 DEFPARAM FLATBEFORE = 150000 DEFPARAM FLATAFTER = 163000 things go wrong. How to write two timeslots per day? Thanks!
    #200658 quote
    JSJS
    Participant
    Master
    Hi @Vogeltje You can try this…
    TimeSlot1 = 0
    TimeSlot2 = 0
    
    If OpenTime >= 083000 and OpenTime <= 110000 then
    TimeSlot1 = 1
    ElsIf OpenTime >= 150000 and OpenTime <= 163000 then
    TimeSlot2 = 1
    EndIf
    Vogeltje thanked this post
    #200673 quote
    NicolasNicolas
    Keymaster
    Legend
    So it means also, that if you are not in any of the time slot, you have to force exit orders (and not put any new pending ones), like the FLATBEFORE and FLATAFTER are used for.
    JS and Vogeltje thanked this post
    #200792 quote
    VogeltjeVogeltje
    Participant
    New
    Thanks JS and Nicolas. I have added a condition and written as the code: //two timeslots TimeSlot1 = 0 TimeSlot2 = 0 If OpenTime >= 083000 and OpenTime <= 110000 then TimeSlot1 = 1 ElsIf OpenTime >= 150000 and OpenTime <= 163000 then TimeSlot2 = 1 EndIf //Condition timeslots c1= TimeSlot1 = 1 OR TimeSlot2 = 1 Working with this condition works just fine. By the way, I tried skipping: TimeSlot1 = 0 TimeSlot2 = 0 but then it is not working. I do not really understand why TimeSlot1 = 0 is necessary. I think Prorealcode does not need to declare a variable. So, why is it not enough to declare If OpenTime >= 083000 and OpenTime <= 110000 then TimeSlot1 = 1 ? I see a lot of examples where a variable is first declared 0,  so this is not clear to me….
    #200803 quote
    JSJS
    Participant
    Master

    If you do not set the variable (TimeSlot) to zero (0) at the beginning of your code, then once True (1), it will always remain True (1).

    When the “TimeSlot” meets the correct times, it is set to 1 (True) and if not, it is reset (at the beginning of the code) to 0 (False)

    1 = True

    0 = False

    So, you could also write your condition like this:

    C1 = TimeSlot1 or TimeSlot2

    Vogeltje thanked this post
    #200805 quote
    VogeltjeVogeltje
    Participant
    New
    A ha great JS, that is really helpful. I think now I can use this kind of setup myself more often!
    JS thanked this post
    #202907 quote
    VogeltjeVogeltje
    Participant
    New
    Hi JS, the ProRealTime Programming guide writes ( page 15): IF Close > Average[20](Close) THEN Result = 1 ENDIF and comments: IF Price > 20-period moving average then Result is 1, otherwise Result = 0. The way I read it, the Result is always put back to 0 . Why is this wrong?
    #202909 quote
    VogeltjeVogeltje
    Participant
    New
    If have written the code for using two timeslots to trade and two other slots to end the trade. This code works. // Twee timeslots om te handelen TimeSlot1 = 0 TimeSlot2 = 0 TimeSlot3 = 0 TimeSlot4 = 0   If OpenTime >= 083000 and OpenTime < 110000 then TimeSlot1 = 1 ElsIF OpenTime >= 110000 and OpenTime < 150000 then TimeSlot2 = 1 ElsIf OpenTime >= 150000 and OpenTime < 163000 then TimeSlot3 = 1 ElsIf OpenTime >= 163000 and OpenTime <= 220000 then TimeSlot4 = 1 EndIf   //Conditie timeslots c1 = TimeSlot1 = 1 OR TimeSlot3 = 1 c2 = TimeSlot2 = 1 c3 = TimeSlot4 = 1   For opening a long or shorttrade the c1 is added. For closing the positions when the time is finished add c2 OR c3 to the exitcode.
    #202910 quote
    robertogozzirobertogozzi
    Moderator
    Legend
    That statement is incorrect, that code will only set RESULT to 1 when the condition is evaluated true, otherwise RESULT will remain unchanged. Set RESULT=0 before that code snippet.
    Vogeltje thanked this post
    #203325 quote
    VogeltjeVogeltje
    Participant
    New
    I have no idea what you are saying Roberto. The above code from day 10/21 is working. It does not speak about a RESULT. And what means “before that snippet”?
    #203327 quote
    JSJS
    Participant
    Master

    Hi @Vogeltje

    Roberto’s comment was about your previous statement.

    If Close > Average[20](Close) then

    Result = 1

    EndIf

    It was about “automatically” restoring Result = 1 to Result = 0

    As you probably already know, the restore is not “automatic” but you have to reset the result to 0 yourself before the start of your code (code snippet) with for example:

    Result = 0

    If Close > Average[20](Close) then

    Result = 1

    EndIf

    …

    …

    Vogeltje and robertogozzi thanked this post
    #203473 quote
    VogeltjeVogeltje
    Participant
    New
    a ha! Thanks JS, great!
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Trading two timeslots per day


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Vogeltje @vogeltje Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by VogeltjeVogeltje
3 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/12/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...