Coding a breakout strategy for bitcoin

Forums ProRealTime English forum ProOrder support Coding a breakout strategy for bitcoin

Viewing 15 posts - 1 through 15 (of 16 total)
  • #81301

    Hi,

    I’m new to programming and have problems with the following idea (and I hope that I’m at the right place here):

    Start: Buying one share on breakout above the highest of the preceding n bars.

    Selling 2 shares on breakout below the lowest of the preceding n bars- then again buying two shares above the breakout and so on.

    This means to be invested with one share all of the time.

    Code:

    Problems: 1. This gives no results for different n on backtesting

    2. What  is the correct term for Bitcoin/USD (cash, share, unit…)?

    3. On IG, the spread for BTCUSD is 50 USD presently. Does this mean I have to type in 50 for the spread?

    Thanks a lot if someone could help, it’s driving me crazy.

    ligand

    #83485

    thanks, I got an answer via prorealtime

     

    #83487

    Hello, the [Insert PRT Code] is your friend 🙂

    #83489

    Hello, the [Insert PRT Code] is your friend

    Thanks swapping – I have tidied up the post to make it easier for others to read 🙂 ligand – please use the ‘Insert PRT Code’ button in your future posts. 🙂

    #83546

    Sorry, thanks. I hope it’s alright now.

    Here is the improved code from prorealcode. Backtesting shows this code to perform trades only in one direction.

    Therefore it doesn’t work in the way I hoped it would. I’d like to be always in the market: buy, when the price breaks above the highest of the last n bars and sell  when it breaks below the lowest of the last n bars. Therefore the first buy (or sell) is with 1 share or contract, and every following trade with 2 shares or contracts and always in the opposite direction.

    If someone could help, it would be very nice.

     

    #83547

    BUY = enter long. Closes any short trades.

    SELL = exit long trade.

    SELLSHORT = enter short. Closes any long trades.

    EXITSHORT = exit any short trades.

    #83556

    Thanks Vonasi, that’s very helpful… I’ll check it out over the weekend.

    #85640

    Hi, one more question regarding realtime data please, since the helpful code above refers to data from the last days:

    What is the right coding word for “the present price”? For example:

    If xxxx crosses over highest[1] then

    buy 1 contract

    The phrase “price” for xxxx is not accepted. Tanks!

    #85652

    Use ‘close’ instead of ‘price’.

    ‘close’ is the price at the close of any candle which is when all strategy decisions are made.

    #85653

    Thank you very much for the quick response!

    So if I’d like to code a system which trades on a hourly basis using a signal on a daily basis – for example buy if the price crosses over the last day’s close – it would be best to code using two timeframes?

     

    #85655

    MTF would work or you could just use DClose(1)

    https://www.prorealcode.com/documentation/dclose/

    #85669

    Thanks a lot. In one of the advanced videos it is shown how to define a line through 2 defined points (e.g. local lows). If I want to code a system to buy if the close crosses a line like that, how can I describe this line in code, please?

    #85670
    #85674

    Hi Vonasi,

    I’m just a physician but if I calculate right and if I know two points defining a line (x1/y1) and (x2/y2) this line is

    y=mx+b

    with

    m=(y2-y1)/(x2-x1) and

    b=y1-((y2-y1)x1/(x2-x1))

    and the line is therefore: y=((y2-y1)/(x2-x1))x + y1-((y2-y1)x1/(x2-x1))

    Given my little knowledge of coding I couldn’t find anything in your link (except of the basal equation) which helped me to force the above equation in code. Could you please show me how this definition of a line is done, if possible?

     

    #85676

    I’m afraid that you might be asking the wrong person! The last time I played with trigonometry calculations was when I was at school – and I ruled out using any form of trend line in my trading a long time ago so I have never coded anything myself with any form of trend line calculations.

    Maybe Nicolas or juanj will join this topic and help you out with your request.

Viewing 15 posts - 1 through 15 (of 16 total)

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