Archive for March, 2009

ISPAG – Awesome Oscillator

Poproszono mnie ostatnio o implementację niestandardowego wskaźnika do ISPAG-a (aplet wykresów) spotykanego pod nazwą Awesome Oscillator lub czasami zamiennie Elliott Wave Oscillator.

Pomyślałem, że może przydać się jeszcze komuś, więc go w tym miejscu publikuję:

/* *** ISPAG - wskaźniki użytkownika *************************************** *
 * Awesome Oscillator / Elliott Wave Oscillator                              *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Wersja: 1.0.0 (2009-03-22)                                                *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Opis:                                                                     *
 *    Implementacja  niestandardowego  oscylatora  (Awesome  Oscillator  lub *
 *    inaczej Elliott Wave Oscillator) dla apletu ISPAG 9.5.                 *
 *                                                                           *
 * Domyślne parametry:                                                       *
 *    Param(1) = 5                                                           *
 *    Param(2) = 34                                                          *
 *    Param(3) = 14                                                          *
 *                                                                           *
 * Opis parametrów:                                                          *
 *    Param(1) - liczba okresów szybkiej SMA                                 *
 *    Param(2) - liczba okresów wolnej SMA                                   *
 *    Param(3) - generowanie sygnałów kupna/sprzedaży na podstawie reguł:    *
 *       4 = Saucer                                                          *
 *       8 = Twin Peaks                                                      *
 *       6 = Zero Line + Saucer                                              *
 *       10 = Zero Line + Twin Peaks                                         *
 *       12 = Saucer + Twin Peaks                                            *
 *       14 = Zero Line + Saucer + Twin Peaks                                *
 *                                                                           *
 * Wyjaśnienie sygnałów:                                                     *
 *    http://www.metaquotes.net/techanalysis/indicators/awesome_oscillator   *
 *                                                                           *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright (c) 2009 Division Logiciel                                      *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *          Aktualna wersja: http://blog.dvl.pl/snippets/ispag               *
 *        Kontakt z autorem: karol (na) dvl (kropka) pl                      *
 * ************************************************************************* */

/* ************************************************************************* *
 * Changelog:                                                                *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * + 2009-03-22 v1.0.0                                                       *
 *   - Pierwsze wydanie                                                      *
 * ************************************************************************* */

/* ************************************************************************* *
 * License: GPL v3 or later (http://www.gnu.org/licenses/gpl.txt)            *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This program is free  software; you can redistribute  it and/or modify it *
 * under the terms  of the GNU  General Public  License as  published by the *
 * Free Software  Foundation; either  version 3 of the  License, or (at your *
 * option) any later version.                                                *
 *                                                                           *
 * This program  is  distributed  in the hope  that it  will be  useful, but *
 * WITHOUT   ANY    WARRANTY;   without   even  the   implied   warranty  of *
 * MERCHANTABILITY or FITNESS FOR A  PARTICULAR PURPOSE. See the GNU General *
 * Public License for more details.                                          *
 *                                                                           *
 * You should have received  a copy of the GNU General  Public License along *
 * with this program. If not, see .            *
 * ************************************************************************* */

/* ************************************************************************* *
 * Implementacja wskaźnika:                                                  *
 * ************************************************************************* */

/* Rysowanie wskaźnika - ze względu na brak histogramów w formie ciągłej     */ 

   var high = High();
   var low = Low();

   var median = CreateArray(high.length);

   for (var i=0; i< 0) {
            if (twinPeaks) {
               /* Twin Peaks - reset */
               lastLow  = 0;
               lastHigh = 0;
               momentum = 1;
               /* Twin Peaks - reset end */
            }
            if (zeroCross) {
               if (AO[i] > 0)
                  AddBuySignal(i);
               else
                  AddSellSignal(i);
            }
         }
      }

      if (saucer) {
         /* Saucer - odwrócenie */
         if (AO[i] > 0 && AO[i-1] > 0 && AO[i-2] > 0) {
            if (AO[i-2] < AO[i-3] && AO[i-1] < AO[i-2] && AO[i] > AO[i-1])
               AddBuySignal(i);
         }
         if (AO[i] < 0 && AO[i-1] < 0 && AO[i-2] < 0) {
            if (AO[i-2] > AO[i-3] && AO[i-1] > AO[i-2] && AO[i] < AO[i-1])
               AddSellSignal(i);
         }
      }

      if (twinPeaks) {
         /* Twin Peaks - mniejszy szczyt */
         if (AO[i] < 0) {
            if (AO[i] > AO[i-1]) {
               if (momentum) {
                  if (AO[i-1] > lastLow) AddBuySignal(i-1);
                  lastLow = AO[i-1];
                  momentum = 0;
               }
            } else {
               momentum = 1;
            }
         }
         if (AO[i] > 0) {
            if (AO[i] < AO[i-1]) {
               if (momentum) {
                  if (AO[i-1] < lastHigh) AddSellSignal(i-1);
                  lastHigh = AO[i-1];
                  momentum = 0;
               }
            } else {
               momentum = 1;
            }
         }
      }
   }
/*::~ EOF */

Co do skuteczności samego wskaźnika nie będę się wypowiadał, bo nie miałem go okazji testować w praktyce.

Z zasadą działania można się zapoznać na następujących stronach:

Awesome Oscillator (ang.)

Elliott Wave Oscillator (ang.)

Zastosowanie Awesome Oscillator w ramach wskaźnika Accelerator/Decelerator (pol.)

Jako że jest to pierwsza wersja implementacji, błędy są jak najbardziej możliwe. Prosiłbym o kontakt w przypadku ich wykrycia. Ze względu na ograniczenia ISPAG-a wskaźnik nie ma charakteru histogramu, ale oscylatora ciągłego. Poza aspektem graficznym nie wpływa to jednak na funkcjonalność.

Wersja wskaźnika w pliku tekstowym do pobrania dostępna jest w ramach repozytorium: http://blog.dvl.pl/snippets/ispag/

Reverse shell access

Problem

In my case this was a weird situation. I had a server I had to administer remotely [server C in the image] set up with some paranoid network security settings (no open remote SSH access). The only way to get to the sshd services was to use a special dedicated proxy [server B in the image] whose static IP address was excluded from the firewall list on the destination server (thus establishing a theoretically more secure SSH tunnel on some not so common port).

rrs.gif

The main problem was the latency resulting from such a construction. My route to the destination server [C] was only a few hops away and direct communication (ICMP) was always less than 20 ms. But the route via B was horrible, very unstable (some high-traffic node so latency spikes occurred every now and then). Normal SSH session got some 100-200 ms delay which meant usable, though not too comfy. But the spikes (2-3 seconds) utterly blighted any more complicated tasks being done on the server.

Solution

As I had a dynamic IP there was no easy way to grant me direct access to the machine in question. But I found a very interesting program, which enabled me to bypass the constraints established by the paranoid firewall setup.

Reverse Remote Shell by Michel Blomgren (Cycom AB) supports inverse SSH-like (OpenSSL) connections established between remote host [C] and the listener [my workstation - A]. As remote outgoing connections are fully accepted by the firewall on machine [C], I only had to set up a listener on my computer, connect through the old method (via tunnel) to the remote server and issue a reverse connection request to my current dynamic IP. When the connection got accepted, my listener transformed into a full-blown remote shell client and I could disconnect the tunnelled session enjoying near local latency of a direct connection.

Reverse Remote Shell is distributed under the MIT License and runs smoothly under Linux and BSD-family systems.

To make it as seamless as possible, I made a quick connection script for Linux.

First make a main connection script (something like ~/start.sh):

#!/bin/sh
# Establish a new screen session
killall screen
screen -dmS remoteShell
sleep 1
# Connect to the server via tunnel, when the session is completed - exit screen
screen -S remoteShell -p 0 -X stuff "~/connect.sh &amp;&amp; exit^M"
sleep 1
# This gets executed on the remote server - request a connection to the listener
screen -S remoteShell -p 0 -X stuff "~/remote.sh &amp;&amp; exit^M"
# Turn on listening on local side
~/listen.sh

You will also need a tunnel connection script (connect.sh). This can be something so trivial as:

#!/bin/sh
/usr/bin/ssh -p 22 -i ~/.ssh/myIdentityFile user@example.com

The remote part (remote.sh) is something like this:

#!/bin/sh
/bin/sleep 1
# Check your rrs location here, 12345 is a port of the listener
# and dynamic.example.com is a dynamic hostname for the listener (client)
~/rrs --daemon --ssl --pem ~/rrs.pem --timeout 15 dynamic.example.com 12345

And the last part – listener (listen.sh):

#!/bin/sh
~/rrs --listen --ssl --pem ~/rrs.pem --port 12345

This way a lot of paranoid firewall setups can be penetrated. Be aware, however, that this would probably need some reworking for corporate scenarios (even more strict as they are) and could potentially lead to some serious security level degradation. Notwithstanding, Reverse Remote Shell can be a really useful tool in such situations, so big thanks goes to Michel Blomgren for that kind of unique application.

Download

Author’s website: http://www.cycom.se/dl/rrs

Mirrored file: http://blog.dvl.pl/files/rrs-1.70.tar.gz

MD5: b400d03c0e39e3e78a7327ba78f789f0