Merging alerts of two pinscript indicators - alerts

I have a ema crossover alert from 1 indicator and RSI crossover in the second alert. From 2nd indicator. I need that one indicator 1 activates the strategy and 2nd alert fulfils it out confirms it. I don't need alert on indicator 1 but i need alert as both of the conditions are filled. Especially for indicator2. I need an alert which had met alert 1 criteria already. Let's say the inductor 1 conditions are
Buy=crossover (x,y)
Sell=crossunder(y, x)
After 4 candles the condition is
Bull=crossover (g, h)
Bear=crossunder(h, g)
Alert condition (buy and bull, signal message)
But buy has happened 4 candles back. Alert will ring only if these both conditions fulfil in 1 bar. But how to get alert on indicator where buy condition came 4 bars back.

Related

Rank players based on their selections

I am working on a game where I am giving every player a set of statements with each statement having 3 different options. Every player is asked to select one of the 3 options for each statement. Now, based on the options that the user has selected and based on what others have selected, I am trying to rank them.
Now, the problem is that I am unable to come up with a fair ranking algorithm. I am sure this problem would have already been solved by someone in one way or other so looking for an existing method/algorithm that can be used to rank people.
Example,
Lets say Q1 have 3 options namely op1, op2 and op3. Based on the existing records, op1 is selected by 38%, op2 is selected by 42% and op3 is selected by 30%. Now a new user (lets call him player1) is playing the game and he selected op2. How should I assign points to him such that I can build a leader board of all the people. What if, later equation changes and op1 becomes 50%, op2 becomes 10% and op3 becomes 40%. Do I need to update the scores of player1 ?

Turn all bulbs ON with a window of 3 bulbs

I am working on building up my problem-solving approach and came across this problem.
We have N bulbs, randomly turned OFF, and ON. The objective is to turn them ON in minimum toggle iterations.
We have to choose a set of 3 consecutive buttons at a time to toggle them.
Example(1-Bulb ON, 2-Bulb OFF):
00010110 can be turned all ON as
00010110 -> 11110110
11110110 --> 1111000
1111000 --> 1111111
OR mention if It is not possible to turn them all ON.
I can't seem to get started with it.
Can someone please help me share an intuition on how to go about this?
Just need some inputs to get started, Not a complete solution.
Is this a specific category of problem? What is that category called?
I am open to reading material et all.
EDIT:
Can we have some optimization if we genralize the question for K consecutive buttons?
Let's number the bulbs from left to right, as #1 through #n.
Some initial observations:
It only matters which triples you toggle, not what order you toggle them in.
There's never any point in toggling a given triple more than once: toggling it twice is equivalent to not having toggled it even once. Due to the previous point, this is true no matter what other togglings happen in between.
There's only one triple that includes bulb #1: namely, the triple consisting of bulbs #1-3. Therefore, if bulb #1 is initially OFF, then you know you have to toggle that triple.
For any given bulb #i in the range [2, n-2], there's only one triple that contains that bulb without containing the bulb to its left.
So:
Go through each bulb #i in order from #1 to #n.
If the bulb is currently OFF:
If i is less than or equal to n-2:
Toggle bulbs #i to #i+2.
Otherwise:
Return "sorry, can't be solved!".

iBeacons: distance between bluetooth devices in iOS

I am working on an app that displays notification when user enters a particular area and exits from the area.
I am using 3 beacons for my app. When user is in between second and third Beacon I need to notify the user that he is inside the premises and when user has crossed the first beacon I need to notify him that he is outside the premises.
Till some extent I am able to achieve this by using the beacons accuracy property as distance between the user's device and all three beacons, but the time to display an alert to the user is more about 30 sec to one minute, but it should be instant.
It is important to understand that the CLBeacon accuracy property, which gives you a distance estimate in meters, lags by up to 20 seconds behind a moving mobile device. The same is true with the proximity property, which is derived from accuracy. This lag may be causing the delays you describe.
Why does this lag exist? Distance estimates are based on the bluetooth signal strength (rssi property) which varies a lot with radio noise. In order to filter this noise, iOS uses a 20 second running average in calculating the distance estimate. As a result, it tells you how far a beacon was away (on average) during the last 20 second period.
For applications where you need less lag in your estimate, you can use the rssi property directly. But be aware that due to noise, you will get a much less accurate indication of your distance to a beacon from a single reading.
Read more here: http://developer.radiusnetworks.com/2014/12/04/fundamentals-of-beacon-ranging.html
There are 2 questions you are trying to ask here. Will try to address them seperately.
To notify when you are in between 2 beacons - This should be pretty straightforward to do using "accuracy" and/or the "proximity" property of both the beacons.
If you need a closer estimate, use distance. pseudo code -
beaconsRanged:(CLBeacon)beacon{
if(beacon==BEACON1 && beacon.accuracy > requiredDistanceForBkn1)
"BEACON 1 IN REQUIRED RANGE"
if(beacon==BEACON2 && beacon.accuracy > requiredDistanceForBkn2)
"BEACON 2 IN REQUIRED RANGE"
}
Whenever both the conditions are satisfied, you will be done. Use proximity if you don't want fine tuning.
Code tip - you can raise LocalNotifications when each of these conditions are satisfied and have a separate class which will observe the notifications and perform required operation.
Time taken to raise alert when condition is satisfied - Ensure that you are raising alert on the main thread. If you do so on any other thread it takes a lot of time. I have tried the same thing and it just takes around a second to raise a simple alert.
One way I know of to do this -
dispatch_async(dispatch_get_main_queue(), ^{
//code
}

card game : win play

I'm currently developing a card game using Actionscript 3, and I was wondering how to be sure that there at least one win possibility.
The game has similar gameplay to this one :
https://play.google.com/store/apps/details?id=com.gameduell.cleopatraspyramidnew&hl=en
https://itunes.apple.com/us/app/cleopatras-pyramid/id401141292?mt=8
Player has to play a card that matchs the previous or the next value of the presented cards.
I tried different methods, but still not satisfied.
What I wanted to know, is how to be sure that in the hidden cards, there is at least one winning game, and so the player will have the possibility to win.
thanks
Given all the cards are pre-placed, you can do the following:
Get a clear board. Pair up your set of cards, to get a set of pairs
Get one pair out of remaining set of pairs. If set is empty, provide filled board as the algorithm result.
Place both cards into your board to the next available positions, so that both places are available to pickup in the gameplay phase. If no places are available, this means you've placed previous pair(s) wrongly, so you have to retrack - pop state from stack, attempt another placement at that state.
Push state to stack.
Go to 2.
The trick is, you start with a board being won, and add a layer (a pair) so that removing this pair will lead to a winnable condition, by state sequence construction. Apparently, you can add random pairs to random available locations in your pyramid, and occasionally the random will be so that, for example, the last 2 places will not be both available to pick up during actual gameplay, and this is a situation to retract previous placement, maybe not just one. You can remedy this situation by giving depth value to grid spaces, and if max depth of free spaces equals the number of unplaced pairs, the deepest places are occupied instead of random.
If your game involves playing one card at a time, then an additional check should be performed at picking the next card - if the remaining set of cards becomes unconnected, e.g. you've picked all the 4's and there are both 3's and 5's left in unpicked set. This means you have to retract to select another card at previous stage. An algorithm can be like this:
Prepare empty grid, prepare set of cards to place.
Recursion entry point. If passed -1 (first time), select a full set of available cards. If not the first time, select a set of valid cards based on previously selected one (e.g. there was a 4, select all 3's, select all 5's, select all 4's if allowed). Shuffle the set.
If the set is empty, and all available cards set is also empty, return from recursion with true, otherwise return false.
Select next card from the set. If none remain, fall back out of recursion with failure.
Check if removal of current card discontinues the remaining set of unplaced cards. If yes, go to 3.
Select an empty available place in the grid, place selected card there.
Enter recursion (save state, go to 2) with current card's value, updated grid and reduced set of unplaced cards.
If recursion result is false, retract action in 5, and go to 3. If true, leave recursion with true.

Need help in building efficient exhaustive search algorithm

There are a 10 buttons. These buttons can unlock the lock if pressed in correct order (5 presses in sequence). Every button press triggers unlock check.
Example: "password" is 123456 and I press buttons 0 1 2 3 4 5 6 I unlock the lock from 6th button press.
I need to design algorithm that tries all possible combinations in the most efficient way (i.e. minimum amount of buttons should be pressed).
I can interpret button number as digit and number of pressed button in sequence as digit position and then try all 99999 combinations in attempt to unlock the lock but I feel that there is a more efficient algorithm to do that.
Is there something I can do to optimize this search?
To optimize a brute-force attack on a lock, you can use De Bruijn sequences.
The sequence can be used to shorten a brute-force attack on a PIN-like code lock that does not have an "enter" key and accepts the last n digits entered. For example, a digital door lock with a 4-digit code would have B(10, 4) solutions, with length 10,000. Therefore, only at most 10,000 + 3 = 10,003 (as the solutions are cyclic) presses are needed to open the lock. Trying all codes separately would require 4 × 10,000 = 40,000 presses.

Resources