webrobert's avatar

Sanity Check...

I'm building a trading algo and I'm currently working on the scanner bit. It checks $periods/$candles. Seems there are two approaches to dealing with indicators...

  1. Pass all the needed candles to each Indicator.
  2. Boot each Indicator in the Scanner and give the Indicator one period at a time (as I'm already dealing with each period) and let the Indicator manage its own data.

The latter is what I'm beginning to implement. Am I missing something? Does this make sense?

    protected $indicators = [
        BullishEngulf::class,
        BearishEngulf::class,
        PriceClosedHigherForTwoDays::class,
        PriceClosedLowerForTwoDays::class, 
		...
    ];

    public function __construct()
    {
        $this->indicators = collect($this->indicators)
             ->transform( fn($indicator) => app($indicator));
    }

    public function check($period)
    {
        return $this->indicators
            ->map( fn ($indicator) => $indicator->check($period) )
            ->filter()
            ->toArray();
    }

So if a particular Indicator needs two periods or three periods the Indicator can manage its own rolling two periods.

Edit: mainly I'm after the ease of management, and performance... naturally.

0 likes
2 replies
kevinbui's avatar
kevinbui
Best Answer
Level 41

So what exactly is your question? That's a clean design btw.

Please or to participate in this conversation.