Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Console]::BackgroundColor = 'Black'
- [Console]::ForegroundColor = 'White'
- $Username = 'blah@gmail.com'
- $Password = 'lol'
- $S2Ourl = 'https://www.stock2own.com'
- $LoginUrl = "$S2Ourl/Investor/Login_AJAX"
- $StockUrl = "$S2Ourl/StockAnalysis/Stock"
- $Stocks = @('US/ACIA'
- 'US/AAPL'
- 'US/TSLA'
- 'US/GILD'
- 'US/NFLX'
- 'US/GOOGL'
- 'US/AMZN'
- 'US/BIDU'
- 'US/GRMN'
- 'US/COH'
- 'US/CTSH'
- 'US/DLB'
- 'US/EBIX'
- 'US/FB'
- 'US/LULU'
- 'CA/WEED'
- 'CA/RCH'
- )
- $Colors = @{
- Buy = 'Green'
- AlmostBuy = 'Blue'
- Mixed = 'Yellow'
- Hold = 'Yellow'
- AlmostSell = 'DarkYellow'
- Sell = 'Red'
- Avoid = 'Red'
- Bear = 'Red'
- Bull = 'Green'
- Unknown = 'White'
- }
- $Results = @()
- Function Get-IndicatorsLegend {
- $Indicators = @()
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = 'AlmostBuy'
- Description = 'Some of the charts moved to the "positive" area'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = 'AlmostSell'
- Description = 'Some of the charts moved to the "negative" area'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = ' Hold'
- Description = 'No indicator changed direction. If you have an open long position, you would better keep it, there is no reason to sell'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = ' Mixed'
- Description = 'Alert is unknown: some indicators suggest buy, others suggest sell. So, be ready to act'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = ' Buy'
- Description = 'All charts moved to the "positive" area'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = ' Sell'
- Description = 'All charts moved to the "negative" area'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = ' Avoid'
- Description = 'Pretty obvious what to do with this plague of a stock'
- }
- $Indicators += New-Object -TypeName PSObject -Property @{
- Indicator = ' Stay Away'
- Description = 'No indicator changed direction. However, technical indicators recommend that you should not have an open long position'
- }
- Return $Indicators
- }
- Write-Host "Logging into '$LoginUrl'"
- Try {
- $Login = Invoke-WebRequest -Uri $LoginUrl -Method Post -Body @{UserName = $Username; Password = $Password} -SessionVariable S2OSession
- $LoginResult = $Login.Content | ConvertFrom-Json
- } Catch {
- Write-Host "`tFailed to log into '$LoginUrl'" -ForegroundColor Red -BackgroundColor Black
- Exit
- }
- If ($LoginResult.Error) {
- Write-Host "`tFailed to log into '$LoginUrl'" -ForegroundColor Red -BackgroundColor Black
- Exit
- } ElseIf ($LoginResult.success) {
- Write-Host "`tSuccessully logged into '$LoginUrl'" -ForegroundColor Green -BackgroundColor Black
- }
- Write-Host 'Looping through $Stocks' -BackgroundColor Black
- ForEach ($symbol in $Stocks) {
- ## Reset variables each iteration
- $trend = $Null
- $ti = $Null
- Write-Host "`tGetting '$StockUrl/$symbol'"
- Try {
- $getStock = Invoke-WebRequest -Uri "$StockUrl/$symbol" -Method Get -WebSession $S2OSession
- $stock = $getStock.Content
- } Catch {
- Write-Host "`t`tFailed to get '$StockUrl/$symbol'" -ForegroundColor Red -BackgroundColor Black
- Continue
- }
- If ($stock.IndexOf('TI Alert:') -eq -1) {
- Write-Host "`t`tFailed to retrieve the TIs (Technical Indicators) of stock '$symbol', skipping this stock" -ForegroundColor Yellow -BackgroundColor Black
- Continue
- }
- If ($stock.IndexOf('Relative Strength Index (RSI) is') -eq -1) {
- Write-Host "`t`tFailed to retrieve the RSI (Relative Strength Index) of stock '$symbol', ignoring this error" -ForegroundColor Yellow -BackgroundColor Black
- }
- $stock2 = $stock ## Copy var so we can process it for TSI too
- $stock = $stock.SubString($stock.IndexOf('TI Alert:'))
- $stock = $stock.SubString(0, $stock.IndexOf('</span>')) ## Do this in 2 stages so the initial search point is reset
- ## Figure out if this overall market is going up (Bull) or going down (Bear)
- If ($stock.indexOf('bear') -ne -1) {
- $trend = 'Bear'
- } ElseIf ($stock.indexOf('bull') -ne -1) {
- $trend = 'Bull'
- } Else {
- $trend = $Null
- }
- $stock = $stock.SubString($stock.IndexOf('" /> ') + $('" /> '.Length))
- $ti = $stock.Replace(' ', '') -replace("`r", '') -replace("`n", '')
- $stock = $stock2 ## Restore variable contents
- $stock = $stock.SubString($stock.IndexOf('Relative Strength Index (RSI) is '))
- $stock = $stock.SubString(0, $stock.IndexOf('.')) ## Do this in 2 stages so the initial search point is reset
- $stock = $stock.SubString($stock.IndexOf('Relative Strength Index (RSI) is ') + $('Relative Strength Index (RSI) is '.Length))
- $tsi = $stock.Replace(' ', '') -replace("`r", '') -replace("`n", '')
- $Results += New-Object -TypeName PSObject -Property @{
- Symbol = $symbol
- Trend = $trend
- TechnicalIndicator = $ti
- TechnicalStrength = $tsi
- MarketPricePerShare = ''
- }
- }
- ## Sort the results
- $Results = $Results | Sort-Object TechnicalIndicator, Trend, TechnicalStrength
- ## Loop through the results and display them to console
- Write-Host "`nDisplaying Results" -BackgroundColor Black
- ForEach ($stock in $Results) {
- Write-Host "'" -BackgroundColor Black -NoNewline -ForegroundColor White
- If ($Colors.$($stock.TechnicalIndicator) -eq 'Green' -and $Colors.$($stock.Trend) -eq 'Green') {
- Write-Host $stock.Symbol -BackgroundColor Black -NoNewline -ForegroundColor Green
- } Else {
- Write-Host $stock.Symbol -BackgroundColor Black -NoNewline
- }
- Write-Host "'`t" -BackgroundColor Black -NoNewline -ForegroundColor White
- Write-Host $stock.TechnicalIndicator -BackgroundColor Black -NoNewline -ForegroundColor $Colors.$($stock.TechnicalIndicator)
- Write-Host ' (' -BackgroundColor Black -NoNewline -ForegroundColor White
- Write-Host $stock.trend -BackgroundColor Black -NoNewline -ForegroundColor $Colors.$($stock.Trend)
- Write-Host ')' -BackgroundColor Black -NoNewLine -ForegroundColor White
- Write-Host "`t" -BackgroundColor Black -NoNewline -ForegroundColor White
- Write-Host "RSI($($stock.TechnicalStrength))" -BackgroundColor Black
- }
- Get-IndicatorsLegend | Format-Table -AutoSize -Wrap Indicator, Description
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement