trying to identify one bar to the left and one bar to right of a selected bar using input.time in pinescript - label

hoping someone can help me with what should be simple but I can't seem to find a solution.
Using input.time/confirm=true, i select a bar on the chart
I would like to print a label on the selected bar, on the bar to the left and on the bar to the right.
The issue I think is that input.time is not compatible with a simple +/-1 so I think it needs to be converted to a bar index. I've tried doing that in the code below but it still doesnt seem to work
The reason for creating this code is to ultimately get the system to determine if the selected bar is a pivot and then based on that do other things. This was just the first step so I can understand what I'm doing wrong.
Any assistance appreciated!
//#version=5
indicator("My script", overlay = true)
start_time = input.time(timestamp("20 Jan 2021"), "Start Calculation", confirm=true)
start_bar = bar_index[start_time]
// Add label above the selected bar
label.new(x=start_time, y=high[start_bar], text='Selected bar', color=color.white, xloc=xloc.bar_time, yloc=yloc.abovebar)
// Add label above the bar to the left of the selected bar
label.new(x=time[start_bar-1], y=high[start_bar-1], text='Bar left', color=color.white, xloc=xloc.bar_time, yloc=yloc.abovebar)
// Add label above the bar to the right of the selected bar
label.new(x=time[start_bar+1], y=high[start_bar+1], text='Bar right', color=color.white, xloc=xloc.bar_time, yloc=yloc.abovebar)
using this code the selected bar correctly display's its label - but the left and right bars are completely off ...
enter image description here

Like this:
//#version=5
indicator("My script", overlay = false)
start_time = input.time(timestamp("8 Jan 2023"), "Start Calculation", confirm=true)
var int barStart = 0
if time == start_time
barStart := bar_index
if barStart
var l1 = label.new(x=barStart, y=high, text='Selected bar', color=color.white)
// Add label above the bar to the left of the selected bar
var l2 = label.new(x=barStart-1, y=high, text='Bar left', color=color.white)
// Add label above the bar to the right of the selected bar
var l3 = label.new(x=barStart+1, y=high, text='Bar right', color=color.white)
If you need time coordinate, then you can use timeframe.in_seconds() with current chart's timeframe, and then add resulted value to the start_time, so it will be +1 bar.

Related

SwiftUI UI Test How To Display Dynamic Buttons Text Values in an app.scrollViews?

How To Display Dynamic Buttons Text Values in an app.scrollViews?
I would like to able to tap the button inside first row in the scrollViews, but not sure what the index of the button is. I tried the 1, 2 and 3 with no luck.
let scrollViewsQuery = app/*#START_MENU_TOKEN#*/.scrollViews/*[[".otherElements[\"Tabbar\"].scrollViews",".scrollViews"],[[[-1,1],[-1,0]]],[0]]#END_MENU_TOKEN#*/
let elementsQuery = scrollViewsQuery.otherElements
elementsQuery.buttons.element(boundBy: 0).tap() //
print("----------------------------------------------")
var i = 0
for element in elementsQuery.buttons.allElementsBoundByIndex{
i += 1
print(i)
print(element) //How To Display the Button Text here?
// print( elementsQuery.buttons.element(boundBy: i))
}
Assuming you only have one scrollView present, the code to tap the first button in it would be the following:
let myScrollView = app.scrollViews.firstMatch
let myScrollViewsButtons = myScrollView.buttons
let myScrollViewsFirstButton = myScrollViewButtons.firstMatch
myScrollViewsFirstButton.tap()
A button in this context is an XCUIElement, not something that is particularly printable. Buttons do have label attributes that are generally the text displayed on them...

Xcode UITest scrolling to the bottom of an UITableView

I am writing an UI test case, in which I need to perform an action, and then on the current page, scroll the only UITableView to the bottom to check if specific text shows up inside the last cell in the UITableView.
Right now the only way I can think of is to scroll it using app.tables.cells.element(boundBy: 0).swipeUp(), but if there are too many cells, it doesn't scroll all the way to the bottom. And the number of cells in the UITableView is not always the same, I cannot swipe up more than once because there might be only one cell in the table.
One way you could go about this is by getting the last cell from the tableView. Then, run a while loop that scrolls and checks to see if the cell isHittable between each scroll. Once it's determined that isHittable == true, the element can then be asserted against.
https://developer.apple.com/documentation/xctest/xcuielement/1500561-ishittable
It would look something like this (Swift answer):
In your XCTestCase file, write a query to identify the table. Then, a subsequent query to identify the last cell.
let tableView = app.descendants(matching: .table).firstMatch
guard let lastCell = tableView.cells.allElementsBoundByIndex.last else { return }
Use a while loop to determine whether or not the cell isHittable/is on screen. Note: isHittable relies on the cell's userInteractionEnabled property being set to true
//Add in a count, so that the loop can escape if it's scrolled too many times
let MAX_SCROLLS = 10
var count = 0
while lastCell.isHittable == false && count < MAX_SCROLLS {
apps.swipeUp()
count += 1
}
Check the cell's text using the label property, and compare it against the expected text.
//If there is only one label within the cell
let textInLastCell = lastCell.descendants(matching: .staticText).firstMatch
XCTAssertTrue(textInLastCell.label == "Expected Text" && textInLastCell.isHittable)
Blaines answer lead me to dig a little bit more into this topic and I found a different solution that worked for me:
func testTheTest() {
let app = XCUIApplication()
app.launch()
// Opens a menu in my app which contains the table view
app.buttons["openMenu"].tap()
// Get a handle for the tableView
let listpagetableviewTable = app.tables["myTableView"]
// Get a handle for the not yet existing cell by its content text
let cell = listpagetableviewTable.staticTexts["This text is from the cell"]
// Swipe down until it is visible
while !cell.exists {
app.swipeUp()
}
// Interact with it when visible
cell.tap()
}
One thing I had to do for this in order to work is set isAccessibilityElement to true and also assign accessibilityLabel as a String to the table view so it can be queried by it within the test code.
This might not be best practice but for what I could see in my test it works very well. I don't know how it would work when the cell has no text, one might be able to reference the cell(which is not really directly referenced here) by an image view or something else. It's obviously missing the counter from Blaines answer but I left it out for simplicity reasons.

KendoSortable placeholder does not appear when item is dragged diagonally upwards

I've got two kendo sortable list wherein I can drag the multi-selected items left to right. All looks good but I experienced this weird behavior. The second time I drag diagonally upwards (north east), the placeholder "Drop here" will not appear until you move the mouse downward a little.
Start dragging "Strawberries" then "Pinapples" to the right list. Remember that your cursor should move north east until you reach the below of "Strawberries"
Is this a limitation of kendo drag and drop?
Here is the Dojo that I am using.
So, I looked the the kendo source code and used your code in a local project with a bunch of console.log()'s and here's what I found:
(The methods of interest are _drag() and _movePlaceholder() of the Sortable class)
This is how kendo is deciding whether or not to show the placeholder(call _movePlaceholder()) inside _drag():
if (axisDelta.y < 0 && (moveOnDragEnter || offsetDelta.top < 0)) {
direction = 'prev';
} else if (axisDelta.y > 0 && (moveOnDragEnter || offsetDelta.top > 0)) {
direction = 'next';
}
While you are moving the cursor upwards over the right-side dropzone:
axisDelta.y is -1(moving up) AND offsetDelta.top > 0(you are below the top of the drop area)
So neither case is true.
The instant you drag 1 pixel down:
axisDelta.y is 1(you are moving down) AND offsetDelta.top > 0(still below the top of the drop area)
So you fall into the direction = 'next'; and _movePlaceholder() will get called since direction is set and the "Drop Here" appears in the "next" spot(below the last item).
If you drag from the top of the drop area, you would hit the direction = 'prev'; case and the "Drop Here" appears in the "prev" spot(above the first item).
The moveOnDragEnter variable seems to be an undocumented option that you can set to true on your sortable init to override the offsetDelta check BUT if you set it, it will cause the "Drop Here" to appear immediately upon entering the drop area BUT it will appear on the top of the list if you enter dragging up and it will appear on the bottom of the list if you enter dragging down...which is not what you want.
Whew!
So....no, with the current logic there is no way to be dragging upwards AND get the "Drop Here" to appear on the bottom of the list and it is a limitation of the sortable.
Now, if you like, you could probably edit the source code to add more cases to the logic to check for more condition combinations, i.e:
if (I'm anywhere in the drop area) {
figure out if the cursor position is above the first item or below the last item and set direction accordingly so that _movePlaceholder() will get called
}
...or just accept the limitation.

how to know which Search Bar is Active?

now I have 2 search bar at one page
the first problem is How can I make a search button always show although no text at searchbar.text?
the second problem is, I have a Table View that Will show a different list expend which search bar I choose, how can I do it well?
I can set a variable that change everytime the search bar is active. However is there a way to see which search bar is currently the active search bar?
The simplest way to check which view are you working with, is assigning the tag property:
firstSearchBar.tag = 100;
secondSearchBar.tag = 200;
You can easily check it:
if(searhBar.tag == 100) {
// it is first search bar
} else if(searchBar.tag == 200) {
// it is second search bar
}
Now, the second part. If you want to show cancel button, you can do it in this way:
searchBar.showsCancelButton = YES;
If you want to show scope bar:
searchBar.showsScopeBar = YES;
If you want to show search results button:
searchBar.showsSearchResultsButton = YES;
EDIT: If you wish to show Search keyboard button even if there's no text entered, you can do it in this way:
UITextField *searchField = (UItextField *)[[searchBar subviews] objectAtIndex:0];
[searchField.enablesReturnKeyAutomatically = NO;
I recommend you reading UISearchBar's documentation.

DataGridView: how to make scrollbar in sync with current cell selection?

I have a windows application with DataGridView as data presentation. Every 2 minutes, the grid will be refreshed with new data. In order to keep the scroll bar in sync with the new data added, I have to reset its ScrollBars:
dbv.Rows.Clear(); // clear rows
SCrollBars sc = dbv.ScrollBars;
dbv.ScrollBars = ScrollBars.None;
// continue to populate rows such as dbv.Rows.Add(obj);
dbv.ScrollBars = sc; // restore the scroll bar setting back
With above codes, the scroll bar reappears fine after data refresh. The problem is that the application requires to set certain cell as selected after the refresh:
dbv.CurrentCell = dbv[0, selectedRowIndex];
With above code, the cell is selected; however, the scroll bar's position does not reflect the position of the selected cell's row position. When I try to move the scroll bar after the refresh, the grid will jump to the first row.
It seems that the scroll bar position is set back to 0 after the reset. The code to set grid's CurrentCell does not cause the scroll bar to reposition to the correct place. There is no property or method to get or set scroll bar's value in DataGriadView, as far as I know.
I also tried to set the selected row to the top:
dbv.CurrentCell = dbv[0, selectedRowIndex];
dbv.FirstDisplayedScrollingRowIndex = selectedRowIndex;
The row will be set to the top, but the scroll bar's position is still out of sync. Not sure if there is any way to make scroll bar's position in sync with the selected row which is set in code?
I found an answer to resolve issue. As I mentioned that the control does not have methods or properties to set the correct scroll bar value. However, the scroll bar and the DatagridView content will display correct if there is an interaction directly towards to the UI such as touch the scroll bar or grid cell. It looks like that the control needs to be refocused and a repaint.
Simply use the following codes does not cause the scroll bar reset:
dgv.Select();
// or dbv.Focuse();
The way I found is that I have to make the DatagridView control disappear to back again. Fortunately, I have a tab control with several tabs. Then I switch the tab to get scroll bar reset:
int index = myTabCtrl.SelectedIndex;
if (index == (myTabCtrl.TabCount)) {
dgv.SeletecedIndex = 0;
}
else {
dgv.SelectedIndex = index + 1;
}
myTabCtrl.SelectedIndex = index;
If you don't have any way to hide the DatagridView on your form, you could simply minimize the form and then restore it back.
The problem is that there will be a fresh on the UI.
It seems, TAB, SHIFT+TAB, END keys don't always bring last column into the visible view.
The following code inside the CurrentCellChanged event handler seems to fix this issue (vb.net):
If Me.MyDataGridView.CurrentCell IsNot Nothing Then
Dim currentColumnIndex As Integer = e.MyDataGridView.CurrentCell.ColumnIndex
Dim entireRect As Rectangle = _
Me.MyDataGridView.GetColumnDisplayRectangle(currentColumnIndex, False)
Dim visiblePart As Rectangle = _
Me.MyDataGridView.GetColumnDisplayRectangle(currentColumnIndex, True)
If (visiblePart.Width < entireRect.Width) Or (entireRect.Width = 0) Then
Me.MyDataGridView.FirstDisplayedCell = Me.MyDataGridView.CurrentCell
'OR Me.MyDataGridView.FirstDisplayedScrollingColumnIndex = currentColumnIndex
End If
End If

Resources