Coding a breakout strategy for bitcoin

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #81301 quote
    ligandligand
    Participant
    Average

    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:

    DEFPARAM CUMULATEORDERS = FALSE
    
    IF PRICE CROSSES BELOW LOWEST[n](low) THEN
    IF LONGONMARKET THEN
    SELL 500 cash AT MARKET
    ENDIF
    IF NOT LONGONMARKET THEN
    SELL 250 cash AT MARKET
    ENDIF
    ENDIF
    
    IF PRICE CROSSES ABOVE HIGHEST[n](high) THEN
    IF SHORTONMARKET THEN
    BUY 500 cash AT MARKET
    ENDIF
    IF NOT SHORTONMARKET THEN
    BUY 250 cash AT MARKET
    ENDIF
    ENDIF

    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 quote
    ligandligand
    Participant
    Average

    thanks, I got an answer via prorealtime

    #83487 quote
    swappingswapping
    Participant
    Master
    DEFPARAM CUMULATEORDERS = FALSE
    
    IF PRICE CROSSES BELOW LOWEST[n](low) THEN
    IF LONGONMARKET THEN
    SELL 500 cash AT MARKET
    ENDIF
    IF NOT LONGONMARKET THEN
    SELL 250 cash AT MARKET
    ENDIF
    ENDIF
    
    IF PRICE CROSSES ABOVE HIGHEST[n](high) THEN
    IF SHORTONMARKET THEN
    BUY 500 cash AT MARKET
    ENDIF
    IF NOT SHORTONMARKET THEN
    BUY 250 cash AT MARKET
    ENDIF
    ENDIF

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

    #83489 quote
    VonasiVonasi
    Moderator
    Master

    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 quote
    ligandligand
    Participant
    Average

    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.

    DEFPARAM CUMULATEORDERS = FALSE
    
    n=5
    
    IF low < LOWEST[n](low[1]) THEN
    IF LONGONMARKET THEN
    Sell 2 contracts AT MARKET
    ENDIF
    IF NOT LONGONMARKET THEN
    Sell 1 contracts AT MARKET
    ENDIF
    ENDIF
    
    IF high > HIGHEST[n](high[1]) THEN
    IF SHORTONMARKET THEN
    BUY 2 Contracts AT MARKET
    ENDIF
    IF NOT SHORTONMARKET THEN
    BUY 1 Contracts AT MARKET
    ENDIF
    ENDIF
    #83547 quote
    VonasiVonasi
    Moderator
    Master
    DEFPARAM CUMULATEORDERS = FALSE
     
    n=5
     
    IF low < LOWEST[n](low[1]) THEN
    SellShort 1 contracts AT MARKET
    ENDIF
     
    IF high > HIGHEST[n](high[1]) THEN
    BUY 1 Contracts AT MARKET
    ENDIF
    

    BUY = enter long. Closes any short trades.

    SELL = exit long trade.

    SELLSHORT = enter short. Closes any long trades.

    EXITSHORT = exit any short trades.

    #83556 quote
    ligandligand
    Participant
    Average

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

    #85640 quote
    ligandligand
    Participant
    Average

    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 quote
    VonasiVonasi
    Moderator
    Master

    Use ‘close’ instead of ‘price’.

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

    #85653 quote
    ligandligand
    Participant
    Average

    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 quote
    VonasiVonasi
    Moderator
    Master

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

    DClose

    #85669 quote
    ligandligand
    Participant
    Average

    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 quote
    VonasiVonasi
    Moderator
    Master

    This might be of assistance regarding your last request:

    Calculating Diagonal Trend Lines Using Fractals and Trigonometry

    #85674 quote
    ligandligand
    Participant
    Average

    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 quote
    VonasiVonasi
    Moderator
    Master

    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)
  • 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

Coding a breakout strategy for bitcoin


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ligand @ligand Participant
Summary

This topic contains 15 replies,
has 3 voices, and was last updated by ligandligand
7 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/25/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...