예제 #1
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;
 }