Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. solo.kirmish
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 7
    • Best 1
    • Groups 0

    solo.kirmish

    @solo.kirmish

    1
    Reputation
    1
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    solo.kirmish Unfollow Follow

    Best posts made by solo.kirmish

    • RE: Understanding Binance RSI calculation

      @run-out He, well I am very well aware that using official indicators is not a good move usually, just because too many would already be using it. This is why I too have built my past strategies on custom tailored indication and always shun away from all these "easy" make rich scheme indicators, especially RSI with its "buy 30 sell 70 be rich" lazy and untrue success formula that I see repeated everywhere.

      I am still not doing that however, but I seek to automate normalization, for which I have observed RSI is a pretty good candidate. This recent boom in BTC has caused proven strategies to be thrown out of the window, simply because interval-volume has increased more than tenfold in just a year, and thus also the turbulence has increased. I managed to devise a pretty promising strategy for the range of 1.1.21 to end of February, but the problem is, it doesn't scale back to last year at all, while of course the old strategies don't apply to this new craze.

      I have since though about a machine learning learned scaler variable plan, but it is elaborate and takes too much time to implement for now. Since the market is in motion at this very moment, I simply try to find a heuristic scaling solution, and by observing the Binance RSI with its snuggle effect around price trends independent of their actual value, I just want to fish this out in order to normalize my strategy for the broader activity-scale spectrum. Ambitious perhaps, but I will see if it is really any better than my current work.

      So be reassured that I wont do some simplistic buy/sell-margin foolishness here. ;)

      Also, the workings of the Binance RSI(6) indicator are decrypted, and there are no shenanigans in the calculation other than that it is difficult to follow up on how the implementation would work. I doubt they would ever just change that, but even if, the fear that any strategy would collapse because of that change is unfounded I think, since I don't extract their indicator, but replicated it. So if whatever I do with it works out, I will just keep it no matter what Binance does later on.
      Now what they do with RSI(12) and RSI(24) is still a mystery, but if knew, I reckon it would play out the same.

      posted in General Discussion
      S
      solo.kirmish

    Latest posts made by solo.kirmish

    • RE: Understanding Binance RSI calculation

      @run-out He, well I am very well aware that using official indicators is not a good move usually, just because too many would already be using it. This is why I too have built my past strategies on custom tailored indication and always shun away from all these "easy" make rich scheme indicators, especially RSI with its "buy 30 sell 70 be rich" lazy and untrue success formula that I see repeated everywhere.

      I am still not doing that however, but I seek to automate normalization, for which I have observed RSI is a pretty good candidate. This recent boom in BTC has caused proven strategies to be thrown out of the window, simply because interval-volume has increased more than tenfold in just a year, and thus also the turbulence has increased. I managed to devise a pretty promising strategy for the range of 1.1.21 to end of February, but the problem is, it doesn't scale back to last year at all, while of course the old strategies don't apply to this new craze.

      I have since though about a machine learning learned scaler variable plan, but it is elaborate and takes too much time to implement for now. Since the market is in motion at this very moment, I simply try to find a heuristic scaling solution, and by observing the Binance RSI with its snuggle effect around price trends independent of their actual value, I just want to fish this out in order to normalize my strategy for the broader activity-scale spectrum. Ambitious perhaps, but I will see if it is really any better than my current work.

      So be reassured that I wont do some simplistic buy/sell-margin foolishness here. ;)

      Also, the workings of the Binance RSI(6) indicator are decrypted, and there are no shenanigans in the calculation other than that it is difficult to follow up on how the implementation would work. I doubt they would ever just change that, but even if, the fear that any strategy would collapse because of that change is unfounded I think, since I don't extract their indicator, but replicated it. So if whatever I do with it works out, I will just keep it no matter what Binance does later on.
      Now what they do with RSI(12) and RSI(24) is still a mystery, but if knew, I reckon it would play out the same.

      posted in General Discussion
      S
      solo.kirmish
    • RE: Understanding Binance RSI calculation

      Just to report back, I had success!
      The theory was correct in that there is actually this smoothing "step 2" RSI as I found out it is called, which was calculated somewhat similar to the formula above. However, it was very nebulous how it would exactly be implemented, so I had to do a full day of trial, error and horror.

      Well, I was able to reproduce the Binance RSI(6) now, with values matching to the T. This is already pretty much enough for me, though I have to wonder whatever these other values, RSI(12) and RSI(24) of Binance are. Certainly that number doesn't reference the time period anymore, since I can't get even remotely the same values using the same method I employed for RSI(6). In fact, even just increasing the smoothing period to 7 causes my RSI to sometimes overshoot over Binance RSI(12), and in some cases even RSI(24)!
      An actual period of 24 generates in fact so much smoothing that the RSI is barely making it out of the 40-60 range most of the time.

      If someone has an idea what is going on, and why the RSI(12) and RSI(24) would be calculated so differently, I am open to suggestions.
      One of my guesses is that they might in some way reduce the relevance of values beyond t=6, so maybe 7-12 only applies at half value, and 13-24 might only be used at 25% or something in that direction.

      Btw., I find it markedly difficult to find any information about these topics, not just with Binance. There aren't really many forums, even stackoverflow-clones and such around to ask these questions, and in the few that exist, there is somehow near 0 activity.
      Maybe I am just in the wrong place asking these specifics in this forum, but out of the list of options, it simply appears the most professional in approach. If you however have knowledge about a place where my question would be better off, please don't hesitate to tell me, - I won't be insulted, because I am actually searching for a place to talk about this too.

      posted in General Discussion
      S
      solo.kirmish
    • RE: Understanding Binance RSI calculation

      The more I look into it, the more it becomes obvious that the Binance RSI is no RSI at all, but some other undisclosed type of measurement. I see it being at odds at every value with both talib and my implementation, but what strikes most is that the Binance (so called) "RSI" is much more stable for some reasons.
      For evidence, let's look at this:
      alt text

      In the marked section from 15:55 to 16:45 the Binance RSI(12) peaks exactly at the high 15:55 candle with just about 60, then declines gradually in a linear fashion.(with the exception of that one tiny uptick at the exact only green candle in this decline) The RSI reaches its lowest point exactly at the price local lowest point.

      Now in contrast talib RSI:
      alt text
      These measurements are intentionally offset by +5min since they are meant to be fed into decision making for the current candle, but you can see a similar high at 16:00 (which is the 15:55 RSI) of 59.65. Some critical difference with it not reaching 60, but so far so good. What is most striking however, is that the talib RSI (and mine) actually take up during the price decline.
      This is caused by the moving average "forgetting" reference to the extreme negative candles to the far left, while still holding on to the powerful green uptick in the middle left, so the slow decline after the 15:55 peak is actually not judged as being weighty enough.

      That of course is a stark contrast to the, again, linear decline of Binances so called "RSI" that snuggles its ups and downs completely around the general price trend. Thus, the conventional wisdom RSI and what Binance calls RSI cannot be the same thing, since the RSI formula would have to be changed in ways that completely distance it from the original purpose to achieve this effect.

      If anything, this reminds me more of the Exponentially Weighted Average from machine learning, where you would essentially just take a percentage of the last, say, RSI, and then add the remaining percentage of the current RSI to get some slight but not overshadowing shift.
      Like this (0<=Beta<=1):
      alt text

      The RSI right would be the known formula, but the displayed "RSI", the Binance-RSI, would be a moving average, which would probably work in this snuggle and flattening effect.

      What do you people say? Is this known?

      posted in General Discussion
      S
      solo.kirmish
    • RE: Understanding Binance RSI calculation

      @run-out Thank you for the tip. Sadly, that only makes the RSI even higher to 15-something, so this isn't it.

      posted in General Discussion
      S
      solo.kirmish
    • Understanding Binance RSI calculation

      Hello, though this is not directly related to Backtrader anymore, but to the same data gathering+evaluation I figured someone here might be proficient in: I am having trouble replicating the exact way in which Binance calculates their RSI. Take this date as an example:
      alt text

      My backtest bought in at the 4 o'clock candle, because the 3:55 one had a really low RSI. Binance says the RSI(12) was 9.47, while my function returned a 14.63 for the same intervals. I checked those intervals via printout and even calculated the RSI by hand, getting 14.63 as well.
      alt text
      Then I researched the problem and found someone mentioning that Binance might use some exponential average instead, and that using "talib" solved that problem. So I got talib running and through much more unwieldy and inefficient code.(numpy array conversion. then output is a list of measurements instead of the one RSI I only need at the end)

      ...Well, the result is exactly the same, 14.63 for that test score, and also identical for all other ones, so either there is no other RSI method, or talib requires some other leavers be pulled to get Binances different results. I tried finding that in the documentation, but was unsuccessful.

      You can see the list of values in question in the second screenshot printed before the first date. How can this be mixed towards a RSI of 9.47?
      This is important for me to replicate, since I use the graphical interface of Binance to come up with strategy hypotheses, so if the indicator values don't match up, my own backtest can't properly act those strategies out, leaving them unvetted.

      posted in General Discussion
      S
      solo.kirmish
    • RE: Buying and Selling at a fixed, virtual price

      @run-out said in Buying and Selling at a fixed, virtual price:

      @solo-kirmish Options are restricted to simulate real world conditions, or results are useless. Could you provide an example of what you are looking to accomplish? We may be able to help. Thanks.

      I don't think a full example would help much, but it something like this:

      if self.dataclose[0] >= self.dataclose[-1]*1.01:
                      buyDecide += 1
                      buyPrices.append(self.dataclose[-1]*1.01)
      

      So here it would just look whether a candle closed at or higher than 1% over the last. Since my actual(/non-backtest) code would grab the stock at +1% over last close, even when the current candle hasn't closed yet, the real buying price I'd need to register is obviously [lastClose]*1.01

      Later, if buy- or sellDecide > 0 because one of the various conditions has been satisfied, it should select the best price out of the appended price-list and commit the action. E.g.:

      if buyDecide > 0:
                      price = min(buyPrices)
                      print('registered buy price %.2f' % price)
                      orderSize = cerebro.broker.get_cash() / price  * 0.99
                      self.order = self.buy(size=orderSize, price=price, exectype=bt.Order.Limit)
      

      Yet, this doesn't always work, especially for sell.
      I get that the ability to simulate real market is useful, but sometimes you just want to run a dry simulation, so it rather disappoints me to learn that it can't be rigged for a true virtual simulation. What a bummer.

      @ab_trader:
      I will try the StopLimit shortly, though it sounds like it would just be a patch. I need this to work on large data without a chance of misfiring, so if I can't really trust the result to the t, it will most likely not suffice.

      Well, if this really can't work with Backtrader, I might be better of just learning to process my raw Csv vault and going through the candlesticks in some simple looping. I don't actually need the real market simulation that comes attached here, just some results to my code.

      posted in General Code/Help
      S
      solo.kirmish
    • Buying and Selling at a fixed, virtual price

      Hello,
      I am new here and currently using Backtrader to test out a complex strategy that requires me to actively listen to a candle and make selling decisions should it suddenly explode or decline. The issues I have run into with Backtrader then, is that it doesn't actually allow you to pick an artificial price,(at least as far as I can see) and will instead opt to just use the next "open", which is of course too late for my purposes.
      The "price" parameter is completely ignored on market type buys and sells, so I switched it to limit orders. But now I have the problem that Backtrader actually takes this limit seriously and will sometimes not buy, and almost always not sell at all, because it seems to wait for some price fluctuation to satisfy the condition.(presumably just another useless candle-close)

      I have looked through the documentation and screened this forum through duckduckgo, but I can't seem to find any option to just dictate a virtual "always accepted" pricetag. (independent of what the grainy/unreal candle data purports to allow)

      It has to be possible somehow, right? This is all a simulation anyway, so options couldn't be restricted so much.

      posted in General Code/Help
      S
      solo.kirmish