Coding a breakout strategy for bitcoin
Forums › ProRealTime English forum › ProOrder support › Coding a breakout strategy for bitcoin
- This topic has 15 replies, 3 voices, and was last updated 6 years ago by ligand.
-
-
09/25/2018 at 8:04 PM #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:
12345678910111213141516171819DEFPARAM CUMULATEORDERS = FALSEIF PRICE CROSSES BELOW LOWEST[n](low) THENIF LONGONMARKET THENSELL 500 cash AT MARKETENDIFIF NOT LONGONMARKET THENSELL 250 cash AT MARKETENDIFENDIFIF PRICE CROSSES ABOVE HIGHEST[n](high) THENIF SHORTONMARKET THENBUY 500 cash AT MARKETENDIFIF NOT SHORTONMARKET THENBUY 250 cash AT MARKETENDIFENDIFProblems: 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
10/25/2018 at 5:59 AM #8348510/25/2018 at 6:22 AM #8348712345678910111213141516171819DEFPARAM CUMULATEORDERS = FALSEIF PRICE CROSSES BELOW LOWEST[n](low) THENIF LONGONMARKET THENSELL 500 cash AT MARKETENDIFIF NOT LONGONMARKET THENSELL 250 cash AT MARKETENDIFENDIFIF PRICE CROSSES ABOVE HIGHEST[n](high) THENIF SHORTONMARKET THENBUY 500 cash AT MARKETENDIFIF NOT SHORTONMARKET THENBUY 250 cash AT MARKETENDIFENDIFHello, the [Insert PRT Code] is your friend 🙂
10/25/2018 at 7:16 AM #83489Hello, 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. 🙂
10/25/2018 at 7:08 PM #83546Sorry, 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.
Breakout code lowest/highest of n bars in both directions - always in the market123456789101112131415161718192021DEFPARAM CUMULATEORDERS = FALSEn=5IF low < LOWEST[n](low[1]) THENIF LONGONMARKET THENSell 2 contracts AT MARKETENDIFIF NOT LONGONMARKET THENSell 1 contracts AT MARKETENDIFENDIFIF high > HIGHEST[n](high[1]) THENIF SHORTONMARKET THENBUY 2 Contracts AT MARKETENDIFIF NOT SHORTONMARKET THENBUY 1 Contracts AT MARKETENDIFENDIF10/25/2018 at 7:20 PM #835471234567891011DEFPARAM CUMULATEORDERS = FALSEn=5IF low < LOWEST[n](low[1]) THENSellShort 1 contracts AT MARKETENDIFIF high > HIGHEST[n](high[1]) THENBUY 1 Contracts AT MARKETENDIFBUY = enter long. Closes any short trades.
SELL = exit long trade.
SELLSHORT = enter short. Closes any long trades.
EXITSHORT = exit any short trades.
10/26/2018 at 6:32 AM #8355611/24/2018 at 5:09 PM #85640Hi, 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!
11/24/2018 at 9:16 PM #8565211/24/2018 at 10:23 PM #85653Thank 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?
11/24/2018 at 10:41 PM #85655MTF would work or you could just use DClose(1)
11/25/2018 at 9:37 AM #85669Thanks 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?
11/25/2018 at 10:59 AM #85670This might be of assistance regarding your last request:
https://www.prorealcode.com/topic/calculating-diagonal-trend-lines-using-fractals-and-trigonometry/
11/25/2018 at 2:17 PM #85674Hi 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?
11/25/2018 at 3:09 PM #85676I’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.
-
AuthorPosts
Find exclusive trading pro-tools on