candlestick rsi: not working
Forums › ProRealTime English forum › ProBuilder support › candlestick rsi: not working
- This topic has 15 replies, 5 voices, and was last updated 7 years ago by Alberto Menichetti.
-
-
08/28/2017 at 11:28 AM #44741
Hi guys,
someone could tell me why the following code doesn’t work?
123456789101112131415161718192021222324252627282930once cbidx=-1once orsi=-1once crsi=-1once lrsi=-1once hrsi=-1curr = rsi[period](close)if BarIndex = cbidx thencrsi = currif curr>hrsi thenhrsi = currelsif curr<lrsi thenlrsi = currendifelsecbidx = BarIndexorsi = currcrsi = currhrsi = currlrsi = currendifif crsi>orsi thendrawcandle(orsi,hrsi,lrsi,crsi) coloured(0,200,0)elsedrawcandle(orsi,hrsi,lrsi,crsi) coloured(200,0,0)endifRETURN 20 as "20", 80 as "80"It was supposed to graph rsi as candlestick, instead it only graphs a single dash of current value. I didn’t expect it to work in already completed bars (because I imagine for that bars only ohlc are available), but I don’t understand why it doesn’t work in real-time bars.
Thanks,
Alberto
08/28/2017 at 11:58 AM #44747Before debugging your code, please have a look at this version I made months ago for another member of the forum: RSI with candlesticks
08/28/2017 at 12:05 PM #44749Hi Nicolas,
your code has a different logic: your ohlc values are calculated applying rsi() on different price series; instead, I always use the close price.
It seems that even if the variables are declared as ONCE their prev value is lost.
08/28/2017 at 12:25 PM #44751That’s right, I get the same behaviour, even with my own version:
1234567891011121314151617181920212223242526defparam drawonlastbaronly=truemrsi = rsi[14](close)if lastopen<>open[0] thenlastopen=open[0]hh=0ll=mrsio=mrsiendifc=mrsihh=max(hh,mrsi)ll=min(ll,mrsi)if o>c thenr=0g=255elser=255g=0endifdrawcandle(o,hh,ll,c) coloured(r,g,0)return //lastopen// barindex//o,hh,ll,c08/28/2017 at 12:47 PM #44757I really don’t understand how the code is evaluated; does the code is executed every tick?
The following code should plot a line with constant value of 1 (only on the first tick of each bar it should switch to 0), instead it’s always 0
1234567891011once cbidx=-1once rval=1if BarIndex = cbidx thenrval = 1elserval = 0cbidx = BarIndexendifRETURN rvalAm I missing something or could it be a bug?
08/28/2017 at 2:06 PM #44758IT IS POSSIBLE BARINDEX=-1?
08/28/2017 at 3:09 PM #44767No, it wouldn’t.
According to documentation, BarIndex is a monothonically increasing value starting from 0
08/28/2017 at 9:38 PM #447841234567891011once cbidx=-1once rval=1// beginning of condition checkif BarIndex = cbidx then // it is never -1 cause it starts with 0, sorval = 1 // the plotted val will never be 1else // but insteadrval = 0 // the plotted val will be 0cbidx = BarIndex // and cbidx is set to the current BarIndexendif // end of condition checkRETURN rval // condition examined, result found and plottedAs far as I see it, you have a condition which is checked and a result is found and plotted. There is nowhere something telling the program to repeat the condition check.
08/28/2017 at 9:52 PM #44785Hi AVT,
I totally agree with you during the first execution of the code; that body is from a dummy indicator I wrote to reproduce the issue. Being an indicator, I expect that body will be executed for every tick; from the second execution onward cbidx won’t never be -1, it will be most of the time equal to BarIndex (except during the first tick of a new bar). So, most of the time the result should be 1.
Being delcared as “once” (that from what I understood from doc is somewhat similar to “static” keyword in classical programming languages) the previous values of cbidx and rval should be kept.
08/29/2017 at 1:12 PM #44844Hi guys,
I’m sorry to bother you (again) with this issue, but really I don’t understand the code execution logic behind an indicator. Another example:
<pre class=”lang:probuilder decode:true “>once cbidx=0
once a=0a = BarIndex-cbidx
cbidx = BarIndexreturn a
1234567once cbidx=0once a=0a = BarIndex-cbidxcbidx = BarIndexreturn aThe returned value, a, is always 1.
I really don’t understand how is that possible!!!! The only way for “a” to be always 1 is that my code is executed only when a new bar is formed (more specifically, on the first tick of every new bar). But looking at other indicators I can see their values changing every tick, so the indicator has to be executed every tick. I checked the official doc again but it’s quite useless.
08/29/2017 at 1:55 PM #44849Live calculation of an indicator for an on-going candle is at every tick, so yes a=1. The only way I would understand the question and why you think a=1 is impossible would be in case you had a different understanding for “once” of what it really does, and would be expecting a to remain =0?
If that’s the case, what “once a=0” does is to perform a=0 just once at first candle, it’s a line not read at following candles, and it doesn’t prevent either other calculations to be made for “a” in the code. It means “read this line just once at the beginning of the history”, it doesn’t mean “this is the value of a once and for all”.
If this wasn’t the problem, sorry I completely misunderstood the question…
08/29/2017 at 2:16 PM #44852Noobywan,
I’m sorry but english not being my language maybe I can’t explain my thoughts clearly.
I’ll try one more attempt; lets see these two lines of code:
12a = BarIndex-cbidxcbidx = BarIndexFrom my understanding, BarIndex is an increasing counter counting the bars processed in the graph. If you agree with that, so the value of BarIndex will change every first tick of a new bar; said in another way, all the ticks of the same bar will have the same value of BarIndex.
If what I just said is true, so the variable “a” should always be 0, except for every first tick of a new bar.
Suppose that the code is evaluating the last tick of bar 1000; the variables are
a = 1000-1000 = 0
cbidx = 1000
The next tick will be the first tick of bar 1001; so the variables will be
a = 1001 – 1000 = 1
cbidx = 1001
Again, the second tick of bar 1001; the variables will be
a = 1001 – 1001 = 0
cbidx = 1001
Third tick of bar 1001; the variables will be
a = 1001 – 1001 = 0
cbidx = 1001
…and so on…
First tick of bar 1002; the variables will be
a = 1002 – 1001 = 1
cbidx = 1002
08/29/2017 at 2:31 PM #44855ok I think I see what you mean, it implies you consider cbidx would change value at first tick and keep it in memory for second tick of same bar, but what the code does is reevaluate at each tick what the latest close price mean for all variable values compared with previous bar’s values, not with previous tick values of current bar… so in other words, if cbidx is calculated on a tick which is not the last of the candle, then its calculation is “forgotten” for this tick and “remade” at next tick starting again from values at close of previous candle, and only calculation of last tick of a candle is then kept for calculations of next candle
08/29/2017 at 2:48 PM #44856Really? So there is no way to keep a value from tick to tick? Only from bar to bar?
08/29/2017 at 3:03 PM #44858Values that can change from tick to tick within the same bar are stored in platform reserved keywords, like high or low. But for a user-created variable inside a probuilder personal code, within a given timeframe, I am not aware of any way to store in memory all the diffrenent values such a variable went through at ticks before the last one inside a same candle. Even using a drawcandle command to display the range an indicator value would have to happen by calculation at last tick from price open,high,low,close of cnadle rather than intermediate-tick memory storing… Nicolas might correct me when he’s back if I’m wrong…
-
AuthorPosts
Find exclusive trading pro-tools on