How to use Array variables
Forums › ProRealTime English forum › ProBuilder support › How to use Array variables
- This topic has 29 replies, 5 voices, and was last updated 7 months ago by PeterSt.
-
-
06/19/2022 at 5:15 AM #195537
Hi all,
How do I use Array variables within the same candle?
For example: how do I store $lastprice as a array variable and continuously compare it with latest price in same current candle?
Many thanks in advance?
06/19/2022 at 9:26 AM #195542Try this one (not tested):
123456i = i + 1IF OpenTime <> OpenTime[1] THENUnset($lastprice)i = 0ENDIF$lastprice[i] = closeyou can then compare two prices when i > 0 (there are at least two elements to be compared).
06/19/2022 at 9:28 AM #195546If you plan to use it in a Daily TF, replace line 2 with:
1IF OpenDay <> OpenDay[1] THEN06/19/2022 at 10:33 PM #195584Tnx Rob.
Before I test it, 2 more things:
1 – Would using “if islastbarupdate then” be the same as using “IF OpenTime <> OpenTime[1] THEN”
2 – How would I then compare two prices when i > 0? what would be the sample code for example?
06/19/2022 at 11:53 PM #195587IslastBarUpdate identifies the current bar, sonit’s always true.
You have i+1 elements with elementbi being the last one. You can compare il with the previous one or against any other one of your choice.
06/20/2022 at 1:01 PM #195623So do I need to also add to the code “<span class=”crayon-st”>if</span> <span class=”crayon-st”>islastbarupdate</span> <span class=”crayon-st”>then” or your code is enough?</span>
also how would I use your code to compute exponential average of the last 10 price changes in the same bar?
06/20/2022 at 3:19 PM #195660also how would I use your code to compute exponential average of the last 10 price changes in the same bar?
I think Roberto is missing your “in the same candle / bar” request.
Personally I am not so sure whether what you want (if I interpret it correctly) is possible. Theoretically it should be, but …
(but from 100 more things I would say that they are possible in indicator code – but they can not be accomplished and answers to questions mostly remain unanswered)06/20/2022 at 5:18 PM #195668Inside Candle12345678910111213141516DefParam DrawOnLastBarOnly = TrueTimeFrame(10 minutes,UpdateOnClose)TimeFrame(Default)UnSet($InsideCandle)N = 10$InsideCandle[0] = closeFor i = 1 to N$InsideCandle[LastSet($InsideCandle)+1] = Close[i]ExpAvg = ExponentialAverage[N](Close)DrawPoint(BarIndex[i],$InsideCandle[i],2)DrawSegment(BarIndex[i-1],$InsideCandle[i-1],BarIndex[i],$InsideCandle[i])NextReturn ExpAvg as "Exponential Average"What you could do:
Suppose your time frame is 10 minutes and you want 10 (inside) prices of 1 minute, then take 1 minute as the default time frame (or any other combination).
06/21/2022 at 12:32 AM #195684Tnx JS but your code returns a standard expaverage formula of the last 10 bars. you did not use the stored arrays to return the expaverage of the last 10 price changes within the same current bar price action
I will clarify what I want the code to do in lament terms:
Suppose I am looking at a live chart and the price action changes of the current Bar.
Suppose the following occurs:
Price change 1 = 6490
Price change 2 = 6491
Price change 3 = 6493
Price change 4 = 6492
Price change 5 = 6491
Price change 6 = 6490
Price change 7 = 6489
Price change 8 = 6490
Price change 9 = 6491
Price change 10 = 6492
I want the code to:
- Store and continuously keep storing above last 10 readings in an array
- Plot and continuously keep plotting the exp average of the above array
All within the same most current bar. This means if current bar closes and new bar starts, the code plots exp average of 1st price change of the new bar and last 9 price changes of the previous bar, then first 2 price changes of current bar + 8 price changes of the previous bar etc etc until 10 price changes are recorded in current bar and so forth…
I hope above is clear.
Can Prorealcode do this or just too complex?
06/21/2022 at 5:42 AM #195689What I was trying to tell you is that if your time frame is, for example, 10 minutes, you can use a second time frame of 1 minute as an alternative to the inside prices in these 10 minutes. So you have 10 “inside” prices of 1 minute in a time frame of 10 minutes. Or when your time frame is 1 minute you can use 1 second as a second time frame and you have 60 “inside” prices of which you can use the last 10.
Hope it’s clear now…
06/21/2022 at 5:44 AM #195690answers to questions mostly remain unanswered
That was a nice one. And is was my best English. 🙁
Anyway what I wanted to say is that questions remain unanswered, and this is often because of the question did not come across. Like in your case @IG_CFD_Trader. And the fact that someone (could be me) got it after all, does not mean that he has the time to work it out. Also, as you have seen, I will not claim that it is impossible but as long as I don’t work it out, the question remains … well, unanswered. And this does not mean it is not possible.
(anything else ? 😉 )Right.
I tested a few things – it is not possible. It is not that it is too complicated … it is just not possible. **
I had high hopes, but Indicators are strange beasts (as how all has been set up in PRT) and what seems obvious for “should work”, does not once again.
So you are stuck at the bar level, hence updates once per bar. That leaves something JS was doing and which indeed can be done without arrays. If you really want to use arrays then I think you will find that the time spent on that is useless (because not necessary and redundant).Sorry …
**): I really hope someone can find a trick after all.
07/08/2022 at 9:09 PM #197021Hi… Been looking at this problem , can you clarify a few things. May look like stupid questions but bare with me.
Price Change…
When you talk of ‘Price Change’ and ‘Price Action Changes’, your earlier example doesn’t literally specify at what resolution you require, and from the ‘Inside Candle’ code posted by ‘JS’ gives me the impression that your concerns were focused on the array/EMA calculation, than the difference in price action values generated on a 1min for 10min chart.
Also, you gave an example of price change’s which were all integers, does this mean your minimum Price Action is ‘1’, or decimals, and to how many decimal places.
So…my guess is,
A price change is at the ‘tick’ level and, is represented by two value which are different from each other. And that 6000.00000 and 6000.00001 is a price change. Maybe not, read on…
Averages
When you calculate a, SMA, yes SMA, you take the sum of a ‘number of values’ and divide by the ‘number of values’ used, SMA = ((Vo+V1+Vn)/n). Let V0 be the current candle and V1 be the previous and,Vn other previous values and so on. Note that each SMA value calculated is going to be on a different set of ‘V’ values, based on ‘n’ value used as the bar position shifts.
But when you calculate the EMA you, don’t just do it in a slightly different but similar way. The big difference’s are that you only use one ‘V’ value, ‘ Vo’ , the previous ema, EMA[1], ‘n’ and some math magic. EMA = Vo * k+ EMA[1] * (1-k) where k=2/(n+1).
Now, just imagining what the stock EMA will do on the current candle, in real time. If price action ‘is’ constantly changing, it ‘will’ use the price change value, you want, but not an EMA of the previous change but one for the previous bar. And, that’s not even thinking what happens when, or after no change . So, is this why you wan’t the EMA to be calculated on a set of previous price changes.
It’s become evident by, how the EMA is calculated that you only need ‘1’ price change value to calculate it. This could negate the need for an array since you only need the last price change.
Compare prices…
Also, ive just remember, as i’m writing, your first post talked about comparing the ‘$lastPrice’ with the ‘latest price’ in the same candle. I’m assuming that the $lastPrice is the last Price change in the array, and the latest price is…. We’ll a bit of confusion… at tick level, the latestPrice, if different to the $lastPrice would get shoved into the array as a new $latestPrice and if no change, the difference would equate to zero.
Note to self… if a<>b = true then not( (a = b) = 0) = false
If your still following me, there needs to be some measurable values, which could/are ‘different’ to the stored Price Changes in the array, for you to compare, without themselves being shoved into the array. However logic say’s if there is a difference, store in array. Seems like one of those scenario’s where you can’t have it both ways, if you see my drift.
I’ve not thought this through yet, since you mentioned ‘in the same candle’ we must be talking about a higher timeframe, what timeframe are you talking about and what is the significance of comparing the two prices.
Summary
There has to be different values between the price action values which go in the array, to the ones for a comparison to equate a difference. This is looking like the array value must be generated from a higher timeframe and the ticks in between them are the other ones you compare. Or at least two different timeframes, one for the array and one with the compare values in between.
File below, 1st just compares a stock ema with manually calculated one. And 2nd one compares an SMA and EMA manually calculated on the price changes only, if used on 1 tick, and an EMA from the current close. I haven’t tested them just used to sus stuff out etc.
From the beginning the ‘Book’ said ‘No’, i’ve read the book and think its 99.9% right, but in trying several different things and refining the spec, were at 99.8%, there maybe a very small remote chance of coming up with a solution. Whether its going to be usable or useful, we’ll, well after wait and see.
Best regards
07/08/2022 at 10:36 PM #197027Hi Druby,
Price change example I used is for ASX200 index. The price of the index changes in 1 point spread during trading hour using 1 decimal point pricing (example last trade was buy 6,701.7 and sell 6,700.7.
Also the rest of your queries do not really matter, what really matters is the following simple question: is it possible to create an array that continuously stores the values of the last Buy price numbers of an instrument? if yes, then one can perform any calculations to these stored numbers i.e. subtraction, averaging etc…
Regards
07/09/2022 at 1:02 AM #197028Not been at this long, you’ve exceeded my trading knowledge, however breaking your simple question down, I can see you want to put some values in an array and what you want to do with them. However if I ask you this simple question, ‘Have you got access to theses values’ from a code point of view and your answer is no or, that’s what you asking you! I still think the answer is no.
From a indicator point of view the only access to data I’ve seen is the OHLC , volume, date and time and some of the others constants/indicator are just calculations based off of those.
In the Backtest code, which I have not been using, I think there is one command I’ve seen which may give you the value of previous trades, but I don’t think your talking about your trades. And I’ve heard of proScreener!
On the off chance your referring to the market BUY and SELL prices, I not seen any access to those either, but my knowledge is limited. So, I don’t think i’m gonna be any help to you on this one.
regards
07/09/2022 at 1:34 AM #197029what really matters is the following simple question: is it possible to create an array that continuously stores the values of the last Buy price numbers of an instrument?
It is not even really about that. It merely is about what you see changing on the indicator’s value throughout the life of this one (last) bar drawing (always changing !), like can I do something with those ever changing values in Indicator code …
(like store the seen changes in an array)
The answer is : No.So you can act upon its changed value like changing the colour of the plot (which is about new ticks hence occurred trades all right), but you can’t do anything “explicit” with it, like store the changed (in-bar !!) value in an array.
sadly -
AuthorPosts
Find exclusive trading pro-tools on