Exemple #1
0
    //Check to see that OandaWrap is setup correctly.
    //Arg1 can be 'Demo', 'Live', or Sandbox;
    if (OandaWrap::setup('Demo', $apiKey, $accountId) === FALSE) {
        throw new Exception('contact Tavurth@gmail.com to submit a bug report.');
    }
    //Html initiation
    echo '<html>';
    echo '<body>';
    //Style our body
    echo '<style> 
	
		body { font-size: 18px; color:#222222; }
		p { position:relative; left:10%; margin: 0; padding: 0; } 
		p.indent { position:relative; left:30%; }
	
	</style>';
    //Our header
    echo '<p><h2>OandaWrap quotes test:</h2></p>';
    //Save the requested pairs as an array
    $pairs = array('EUR_USD', 'EUR_AUD', 'EUR_JPY', 'EUR_CAD');
    //Loop through the array
    foreach ($pairs as $pair) {
        //Check for valid quote
        if ($quote = OandaWrap::price($pair)) {
            echo '<p>Price of ' . $pair . ' is: </p><p class="indent"> ' . $quote->bid . ' => ' . $quote->ask . '</p>';
        }
    }
    //End the html
    echo '</body>';
    echo '</html>';
}
Exemple #2
0
 /**
  * Runs the analysis and returns a recommendation.
  * @return Array $recommendation
  * [BOOL trade, instrument, side, entry, stopLoss, rr]
  */
 public function analyse()
 {
     // we need a min of 5 candles for this pattern
     $values = [];
     $trade = false;
     $values['trade'] = $trade;
     $values['instrument'] = '';
     $values['side'] = '';
     $values['entry'] = '';
     $values['stopLoss'] = '';
     $values['rr'] = 1;
     $values['gran'] = 'D';
     $values['expiry'] = 0;
     // first find if we need 2 or three in our flag pole
     $polecandles = $this->args['noOfPoleCandles'];
     // TODO this code only checks for 1 breather candle!
     $maxBreatherCandles = $this->args['maxBreatherCandles'];
     $breatherCent = $this->args['percentBreatherSize'];
     $strong = $this->args['strongPoleCandleCent'];
     $buffer = $this->args['entryBufferPips'];
     $maxValid = $maxBreatherCandles;
     for ($i = 0; $i < $maxValid; $i++) {
         // find pattern  ------------------------------------------------------------------
         $pattern = false;
         if ($this->direction($i + 1) == $this->direction($i + 2) && $this->direction($i) != $this->direction($i + 1)) {
             if ($polecandles == 2) {
                 $pattern = true;
             } elseif ($polecandles == 3) {
                 if ($this->direction($i + 2) == $this->direction($i + 3)) {
                     $pattern = true;
                 }
             }
         }
         if (!$pattern) {
             continue;
         }
         // check size of breather  ---------------------------------------------------------
         if ($this->range($i) / $this->totalRange($i + 1, $i + 1 + $polecandles) > $breatherCent) {
             continue;
         }
         // check pole is strong  -----------------------------------------------------------
         $strongPoles = true;
         for ($j = 1; $j < $polecandles; $j++) {
             $perCentBody = $this->body($j) / $this->range($j);
             if ($perCentBody < $strong) {
                 $strongPoles = false;
             }
         }
         if (!$strongPoles) {
             continue;
         }
         // does the breather breach the pole?
         if ($this->poleBreach($i)) {
             continue;
         }
         // probably got a valid signal.
         //$validPatternShift = $i;
         $breatherDirection = $this->direction($i);
         $trade = true;
         if ($breatherDirection == 'BEAR') {
             $values['entry'] = max($this->high($i), $this->high($i + 1)) + $buffer;
             $values['stopLoss'] = $this->low($i) - $buffer;
             $values['side'] = 'buy';
         }
         if ($breatherDirection == 'BULL') {
             $values['entry'] = min($this->low($i), $this->low($i + 1)) - $buffer;
             $values['stopLoss'] = $this->high($i) + $buffer;
             $values['side'] = 'sell';
         }
         break;
     }
     if ($trade) {
         $values['trade'] = $trade;
         $values['instrument'] = $this->candles[0]['instrument'];
         $values['rr'] = 1;
         $values['gran'] = $this->candles[0]['gran'];
         $granTime = \OandaWrap::gran_seconds($values['gran']);
         $values['expiry'] = time() + $granTime;
     }
     return $values;
 }
Exemple #3
0
 public static function nav_account_set($accountId)
 {
     //Set our environment variable $account
     return self::valid(self::$account = self::account($accountId));
 }
Exemple #4
0
    //Format a class to html code
    function format_string($var)
    {
        ob_start();
        print_r($var);
        $varString = ob_get_contents();
        ob_clean();
        return str_replace(str_split("\n()"), str_split(" {}"), nl2br($varString, TRUE));
    }
    //Format a class to HTML code and echo the output in human readable format
    function format($var)
    {
        echo '<pre>' . self::format_string($var) . '</pre>';
    }
    //Include OandaWrap
    require '../OandaWrap.php';
    require 'config.php';
    //Check to see that OandaWrap is setup correctly.
    //Arg1 can be 'Demo', 'Live', or Sandbox;
    if (OandaWrap::setup('Demo', $apiKey, $accountId) === FALSE) {
        throw new Exception('Contact Tavurth@gmail.com to submit a bug report.');
    }
    echo '<h3><b>Buy with a market order and included stopLoss:<br></h3></b>';
    format(OandaWrap::buy_market(10, 'EUR_USD', array('stopLoss' => 1.0243)));
    echo '<h3><b>Set buy limit order with included takeProfit:<br></h3></b>';
    format(OandaWrap::buy_limit(10, 'EUR_USD', 1.0243, OandaWrap::expiry_day(10), array('takeProfit' => 1.032)));
    echo '<h3><b>Set market if touched buy order with included trailingStop of 10 pips:<br></h3></b>';
    format(OandaWrap::buy_limit(10, 'EUR_USD', 1.0243, OandaWrap::expiry_hour(), array('trailingStop' => 10)));
    echo '<h3><b>Buy at market, limiting size so that 2% of account is risked over 20 pips, the set stop 20 pips from current price:<br></h3></b>';
    format(OandaWrap::buy_bullish('EUR_USD', 2, 20));
}
/*
  Copyright 2015 William Whitty
  Tavurth@gmail.com
  Licensed under the Apache License, Version 2.0 (the 'License');
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an 'AS IS' BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
if (defined('TAVURTH_OANDAWRAP_EXAMPLE_STREAMING') === FALSE) {
    define('TAVURTH_OANDAWRAP_EXAMPLE_STREAMING', TRUE);
    //This example should be run from a console.
    //HTML will not show the output without a flush command
    //Include OandaWrap
    require '../OandaWrap.php';
    require 'config.php';
    //Check to see that OandaWrap is setup correctly.
    //Arg1 can be 'Demo', 'Live', or 'Sandbox';
    if (OandaWrap::setup('Live', $apiKey, $accountId) === FALSE) {
        throw new Exception('contact Tavurth@gmail.com to submit a bug report.');
    }
    function callback_func($jsonObject)
    {
        var_dump($jsonObject);
    }
    OandaWrap::stream(callback_func, array('EUR_USD'), array('AN ACCOUNT ID'));
}