Customized Trading session

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #99319 quote
    solar
    Participant
    Senior

    Hi everyone,

    I am new to prorealcode.

    I have an strategy which trades on price levels using previous trading session’s open, high, low, close. The CFD market may trade 24hrs a day, yet i would only use price information between 0915-0100 (1 complete session)to calculate my price levels.

    I wonder if there is anyway on coding that could help me automatically store the values using the concept of “previous session”and tackle the issues during weekend(price level on monday would be based on Friday’s OHLC)

    #99320 quote
    jebus89
    Participant
    Master

    U can alter the time-data in “Platform options”..

    #99324 quote
    solar
    Participant
    Senior

    I am sorry. is the coding charts based? which means if I display 0915-0100 on the chart then my orders would only be able to execute during 0915-0100?

    If so the next question are there any keywords/ functions (e.g.similar to dhigh[0]) for me to store previous 0915-0100 session’s OHLC.

    Many thanks!

    #99330 quote
    Vonasi
    Moderator
    Master

    Do you want this as an indicator or as part of a auto strategy?

    I have moved your topic to the ProOrder forum which is for auto-trading questions. You posted in the General Trading Discussion forum which is not the right place for these sort of questions. Please try to post in the correct forum with future topics. 🙂

    #99335 quote
    solar
    Participant
    Senior

    It is a part of the auto-trading.

    I am sorry for any inconvenience caused.

    #99348 quote
    Vonasi
    Moderator
    Master

    You can do something like:

    starttime = 091500
    endtime = 130000
    
    if time = starttime then
    op = open
    lo = low
    hi = high
    endif
    
    if time = endtime then 
    lastop = op
    lastcl = cl
    lasthi = hi
    lastlo = lo
    cl = close
    endif
    
    if time >= starttime and time < endtime then
    hi = max(hi,high)
    lo = min(lo,low)
    endif
    
    

    Not tested.

    Use lastop, lastcl, lasthi and lastlo in your code to get the open, close, high and low for the previous session.

    make sure the chart you use has candles that represent any time that you choose. So you need a 15 minute chart or faster to see 0915.

    #99405 quote
    solar
    Participant
    Senior

    Thanks for your idea.

    However, when a new trading day begins (i.e. 0915), lastop, lasthi, lastlo, lastcl would be replaced by new OHLC of the new trading day.

    Let’s say the market run from 0915-0100 the next day, from  monday to  saturday, and let’s call monday 0915-tuesday 0100 as day1, …., until friday 0915 – saturday 0100 as day 5.

    What I want to do is:

    day2 would trade on OHLC of day1

    day3 would trade on OHLC of day2

    day4 would trade on OHLC of day3

    day5 would trade on OHLC of day4

    day1 would trade on OHLC of previous day5

    in this case I need a set of functions to read OHLC of the previous “day”.

    #99406 quote
    Vonasi
    Moderator
    Master

    Which is exactly what the code I wrote should do. At the endtime it stores the sessions OHLC as lastop, lastcl, lasthi, lastlo whereas op, cl, hi and lo are the current sessions OHLC.

    It needs just a small modification to be certain that it avoids any Sunday data but if your start time does not exist on a Sunday chart then it will ignore them any way.

    I’ve not tested it but I can’t see any reason why it would not be doing what you want.

    #99680 quote
    Vonasi
    Moderator
    Master

    I finally had a chance to test it and there was a minor error. This code does what you asked for:

    starttime = 090000
    endtime = 130000
    
    if opentime = starttime then
    op = open
    lo = low
    hi = high
    endif
    
    if opentime = endtime then
    lastop = op
    lasthi = hi
    lastlo = lo
    lastcl = close
    endif
    
    if opentime >= starttime and opentime < endtime then
    hi = max(hi,high)
    lo = min(lo,low)
    endif
    
    buy at -close stop
     
    graphonprice lastop as "open"
    graphonprice lastcl as "close"
    graphonprice lasthi as "high"
    graphonprice lastlo as "low"
    

    Remove the ‘buy at -close stop’ when you adapt it for your strategy as that code is just for testing to prove the values are correct.

    solar thanked this post
    #99686 quote
    solar
    Participant
    Senior

    hi 

    Thanks a lot for your effort. I will definitely try it out.

    However I want to catpure the price movement (OHLC) from 915am to 1am the next day . On this regard , line 17 would not function as time could not be larger than 091500 and smaller than 010000 at the same time . Any solution to it ?

    Many thanks !

    #99688 quote
    robertogozzi
    Moderator
    Master

    Replace AND with OR.

    solar thanked this post
    #99736 quote
    solar
    Participant
    Senior

    It works well. Thanks a lot for your help.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Customized Trading session


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
solar @fatlung Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by solar
6 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/24/2019
Status: Active
Attachments: No files
Logo Logo
Loading...