A function that buy when price goes down x % and the up x %

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12458 quote
    simon_json
    Participant
    Average

    Hi,

    I wish to code a function that buy when price goes down x % from the top (highest that day), and then up x % from the bottom (lowest that day) during the same day. But I can’t 🙂
    So if price goes down 0,5% it should not buy direct, but wait for a 0,1% rise from the bottom that day.
    The wait for a rise is just a try to protect from further downs –  say price falls 0,5% but then continue to 0,9%.
    Can I use DHigh(0)?
    If close < DHigh(0) – x then… ?
    if close > DLow(0) + x then
    buy at market
    endif
    Endif
    I will also probably use a time filter and maybe another price filter to determinate trend, but thats another story 🙂
    Thanks!
    All the best!
    Simon

    #12464 quote
    Nicolas
    Keymaster
    Master

    Hi Simon, you should have a look at this screener: http://www.prorealcode.com/prorealtime-market-screeners/fibonacci-61-8-retracement/

    Its code should help you how to determine retracement percentage from recent highest high and lowest low.

    #12502 quote
    simon_json
    Participant
    Average

    Thanks Nicolas! I tried this:

    DEFPARAM CumulateOrders=false
    
    if intradaybarindex = 0 then
    openbuy=0
    endif
    
    Starttime = time >090000 and time <140000
    
    Down = close < DHigh(0)*0.986
    //0.995
    // optimize mini 0.985 max 0.995 step 0.001
    
    Up = close > DLow(0)*1.005
    
    //1.001
    // optimize mini 1.001 max 1.01 step 0.001
    
    If starttime and down then
    if up and openbuy=0 then
    buy at market
    openbuy = openbuy+1
    endif
    endif
    
    If time >170000 then
    sell at market
    endif

     

    I wish to run it on 5-min. TF. Probably on DAX.
    Dose it make sense?

    Is DHigh(0) and DLow(0) calculated from 00:00 on a new day? Can I make it so it is calculated from 09.00 when market opens?

    All the best!
    Simon

    #12504 quote
    Nicolas
    Keymaster
    Master

    The daily OHLC are always calculated from the very first intraday bar.
    Of course you can calculate yourself a customized OHLC from a different start hour.

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

A function that buy when price goes down x % and the up x %


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
simon_json @simon_json Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Nicolas
9 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/30/2016
Status: Active
Attachments: No files
Logo Logo
Loading...