using arrays in ProOrder
Forums › ProRealTime English forum › ProOrder support › using arrays in ProOrder
- This topic has 14 replies, 7 voices, and was last updated 2 months ago by juld63.
-
-
04/01/2024 at 12:02 PM #230827
Hi everyone, I have programmed an array that stores past supports and resistances and I would like to use them as conditions for triggering orders. A simple example would be that way:
in my current strategy a “buy” order is triggered if condition A is fulfilled. I would like to restrict it the the case when condition A is fulfilled AND the price crosses over (or under) any value of the resistance (or support) array.
Of course I can’t just write it
IF conditionA=true AND close crosses over $res
because “$res” is the name of the array ; I can’t write
IF conditionA=true AND close crosses over $res[a] (with a being any value)
because I have to define “a” beforehand
I could write
123456789101112FOR a=ArrayMin($res) to ArrayMax($res) DOIF conditionA=true AND close crosses over $res[a] THENBUY SHARE AT MARKETBREAKELSECONTINUEENDIFNEXTBut I’m unsure whether it is the most straightforward thing to do. Any ideas? Thanks!
04/01/2024 at 2:55 PM #230846This will do:
123456FOR a = 0 TO lastset($res) DOIF conditionA AND close crosses over $res[a] THENBUY SHARE AT MARKETBREAKENDIFNEXT1 user thanked author for this post.
04/01/2024 at 11:45 PM #23086404/02/2024 at 8:56 PM #230934Is this what you mean?
123456789101112131415161718IF Not OnMarket THENFlag = 0FOR a = 0 TO lastset($res) DOIF conditionA AND close crosses over $res[a] THENBUY SHARE AT MARKETFlag = 1BREAKENDIFNEXTIF Flag = 0 THENFOR a = 0 TO lastset($sup) DOIF conditionB AND close crosses under $sup[a] THENSELLSHORT SHARE AT MARKETBREAKENDIFNEXTENDIFENDIF04/02/2024 at 9:11 PM #230938More or less, yes. I’d rather have it scan the array from ArrayMax to ArrayMin for supports and from ArrayMin to ArrayMax for resistances so that it tests the values in the order it should be encountering them, rather than in the historical order they are stored, so as to make the code more efficient. I just wonder if there wouldn’t be a simpler way.
04/03/2024 at 9:11 AM #230959You can use the arraysort command to reorder your array if you wish:
https://www.prorealcode.com/documentation/arraysort/
1 user thanked author for this post.
04/09/2024 at 6:53 PM #231325Hello everyone,
I have coded and array indicator that gives me past supports and resistances not engulfed by subsenquent ranges. It works in Probuilder, meaning it displays as it should.
Now that this is done, I want to be able to call the values in this array to test if my remarkable candle shapes intersect with any of those values or not.
However, I have absolutely idea of how to call an array, its the various $array[n] … Of course I can just duplicate the whole indicator into the trading system’s code, but it becomes cumbersome.
This is what I have down the line, if only I can manage to call $res and $sup (“candlenb” being used for identifying how many candles make up a shape)
1234567891011FOR a=ArrayMin($res) TO ArrayMAX($res) DOIF (candlenb=1 AND open<=a AND close>=a) OR (candlenb=2 AND highest[2](high)>=a AND lowest[2](low)<=a) OR (candlenb=3 AND highest[3](high)>=a AND lowest[3](low)<=a) OR (candlenb=4 AND highest[4](high)>=a AND lowest[4](low)<=a) OR (candlenb=5 AND highest[5](high)>=a AND lowest[5](low)<=a) OR (candlenb=6 AND highest[6](high)>=a AND lowest[6](low)<=a) THENresres=1BREAKELSIF (candlenb=1 AND close<a+1) OR (candlenb=2 AND highest[2](high)<a+1) OR (candlenb=3 AND highest[3](high)<a+1) OR (candlenb=4 AND highest[4](high)<a+1) OR (candlenb=5 AND highest[5](high)<a+1) OR (candlenb=6 AND highest[6](high)<a+1) THENresres=0BREAKELSECONTINUEENDIFNEXTAny help will be much appreciated !
04/09/2024 at 10:00 PM #231328Also, to avoid scanning the whole array if the candle(s) is(are) between two values in the array, after it has failed to check if value “a” is inside a candle or group of candles, I want it to check whether it doesn’t reach the next value of the array in increasing order. My poor attempt is writing this value as “a+1” but of course it will return the value of “a” plus 1 point, not, if we’re starting from ArrayMin($res), the second smallest value of the array. Any idea how to get this, the nth smallest (or biggest) value of a given array beyond the absolute smallest (ArrayMin) and the absolute biggest (ArrayMax)? Thanks !
04/10/2024 at 7:08 AM #231329Hi,
You can use “ArraySort”, for example “ArraySort($Res,Descend)…
The entire array is now sorted from highest to lowest, so your highest value is now $Res[0] and the next highest values are: $Res[1], $Res[2], $Res[3], and so on
The number between the bracket of the array is always the index of the array (not the value of the array)…
04/10/2024 at 8:29 AM #23133404/10/2024 at 8:53 AM #23133704/10/2024 at 11:40 AM #231343Hi.. As far as I know you can not ‘call’ an array as a whole entity, with the call function from another file.
Below is 1 example of what you can do.
Example builds a replica array in the ‘Main’ file from values fetched from the ‘data’ file with the call instruction.
It does this replication on the first bar, fetching each array elements value individually.
For this to work, the index value for the required value is sent with the ‘call’ which means that variable ‘ idx’ requires setting up as a dynamic variable in the ‘data’ file.
The return value is stored in ‘Main’ in local array at same index. The local array accessed as required via a index value … arr [idx].
Also if you add additional res/sup lines to the ‘data’ arrays, since the size is calculated from how elements exists, these should ripple through to main, in indicators, not sure what effects with proOrder/bot. Not tried!
#JS brings up a good point, if you sort the array in ascending or descending order, then finding the ‘nth’ highest/ lowest, would be easy to determine from chosen array index value.
Also in practise you really probable only need to know if you have reached the next higher or lower res line from last position, you then could use a narrow loop range rather than looking through whole array.
druby
lineMain123456789101112131415161718192021222324252627282930313233// lineMainif barindex = 0 then //build local array on/at bar 0// get size of arraysize, ignore = CALL "lineData"[0]// fetch 'call'ed values and store in local arrayfor i = 0 to size //loop!// fetch val'ue pointed to by indexed 'i'idx = iignore, val = CALL "lineData"[idx]// store in local array at same index$res[i] = valnextendif// loop to create an 'index' value to access local array elementsfor i = 0 to lastset($res)res = $res[i] // put indexed value in a variable// display array as listdrawtext("#i# #res#",0,0 - (i*15))anchor(middle,xshift,yshift)nextdrawtext("i res",0,20)anchor(middle,xshift,yshift)returnlineData123456789101112131415161718192021222324// lineData// dynamic variable(s) to setup!// 'idx' ... integer ... default = 0 ... positive// array data$res[0] = 10$res[1] = 20$res[2] = 30$res[3] = 40$res[4] = 50$res[5] = 60$res[6] = 70$res[7] = 80// determine size of arraysize = lastset($res) // size = (arrayElements - 1), 0 to 'n'// fetch indexed value refered by 'idx'res = $res[idx]return size, res04/11/2024 at 2:31 PM #231413Hello,
Thanks for your help. In the meanwhile I’ve found a simpler way around: in the indicator where the array is calculated I call the other indicator and have it code whether the candle shapes are across a value of the array, and then I call the results of the array indicator not as array values but as a simple boolean operator, and then I can just call the value of this operator in my robot with a CALL instruction.
2 users thanked author for this post.
09/19/2024 at 11:40 PM #237851Hello, juld63,
I’m still learning to code, and so wondered if you would be kind enough to share the code of your ‘simpler way round’, as I believe it will solve a problem I have of a similar nature.
With thanks in advance…
09/20/2024 at 9:02 AM #237856Sure! Here’s how I finally managed to write it
past supports and resistances12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273ONCE myindexres=1ONCE myindexsup=1//10PM is when we fill and filter the arraysif opentime=220000 Then//add highest and lowest since yesterday 10PM$res[myindexres] = highest[period](high)$sup[myindexsup] = lowest[period](low)//reset all past resistance values that are engulfed by the last 24h highest and lowestFOR a=0 to myindexres-1 DOIF $res[a]<$res[myindexres] AND $res[a]>$sup[myindexsup] THEN$res[a]=0CONTINUEENDIFNEXT//reset all past support values that are engulfed by the last 24h highest and lowestFOR a=0 to myindexsup-1 DOIF $sup[a]<$res[myindexres] AND $sup[a]>$sup[myindexsup] THEN$sup[a]=0CONTINUEENDIFNEXT//reset the index count for the next dayIF IsSet($res[myindexres])=1 THENmyindexres=myindexres+1ENDIFIF IsSet($sup[myindexsup])=1 THENmyindexsup=myindexsup+1endifENDIFresres=0ressup=0//sort the resistance values in ascending orderArraySort($res,ascend)FOR a=1 TO LastSet($res)DOIF $res[a]=0 THEN //this avoids a bug that takes into account empty cells as 0scontinueELSIF YOURCONDITIONMET=1 AND low<=$res[a] AND high>=$res[a]) THENresres=1 // your signal candle intersects with a resistanceBREAKELSIF YOURCONDITIONMET=1 AND low>$res[a] AND high<$res[a+1]THENresres=0 // your signal candle intersects is between two resistance linesBREAKELSECONTINUEENDIFNEXT//sort the support values in ascending orderArraySort($sup,descend)FOR a=1 TO LastSet($sup) DOIF $sup[a]=0 THEN //this avoids a bug that takes into account empty cells as 0scontinueELSIF YOURCONDITIONMET=1 AND low<=$sup[a] AND high>=$sup[a] THENressup=1 // your signal candle intersects with a supportBREAKELSIF YOURCONDITIONMET=1 AND high<$sup[a] AND low>$sup[a+1] THENressup=0 your signal candle is between two support linesBREAKELSECONTINUEENDIFNEXT2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on