Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Solved- WVAD strategy using custom factors, it fails!

Its my first time wrote a strategy that actually runs, but it went wrong and I have no idea where its not right.
Its using the WVAD indicator to buy and sell stocks: https://www.mql5.com/en/code/23467
WVAD = (Close- Open)/ (High - Low) / Volume
basically when WVAD above 0, it buy and below 0 it close all the positions
I would really appreciate if someone would take a look at my code.
Thanks!

7 responses

Use [-1] instead of [0]. When window_length=10 and you specify [0], it will take 10 days old values. Unless the intention is to use 10 days old values.

class WVAD(CustomFactor):  
    # wrote a custom factors calculating the WVAD  
    inputs = [USEquityPricing.high,  
              USEquityPricing.low,  
              USEquityPricing.open,  
              USEquityPricing.close,  
              USEquityPricing.volume]  
    # here is the equation  
    def compute(self, today, assets, out, high, low, open, close, volume):  
        out[:] = ((close[-1]-open[-1]) / (high[-1]-low[-1])) * volume[-1]  

I have fixed this issue of using future data. But, it doesn't seem to fix this code.
This code seems somehow shorting all the stocks, which I have no idea.
I think its probable with my CustomFactor that while I was trying to initialize the Factor using 'my_wvad = WVAD(window_length = 1) ', it didn't run.
Instead, I probably need using my_wvad = WVAD.compute() ', but then, it ask for all the inputs. Now i'm struggle how do I put these inputs there, not sure if this the problem.

it seems i have fixed some of the issue.
I shouldn't let the inputs directly in the CustomFactors, It should go to the make_pipeline().

But still, while checking on the backtesting positions, it appears that its continues to short the two stocks, which I have no idea why.
There are no part of the code would have it to short it? How did that even happen?

I'm a newby as well, but it seems to work like you want...

@ZT YE,

Backtesting this kind of strategy is much easier without a pipeline.
Here's my implementation of WVAD strategy using Larry Williams Variable Accumulation Distribution indicator.

@Pavel Marek, why is our back-testing have different result? Yours looks a lot normal.
@Valdimir, wow, I am really over complicating things, your code is so concise and efficient.

I got another one which i posted on another post.
Its...more complicated...and yield a bizarre result, but the code pick the stock it self. I no longer need to provide the pre-defined stock.
Take a look if you want. I still feel weird about this one. Something not right here.

I have fixed it! its the open order problem. there are unfilled the orders that keeps leverage way out of hand .
So i added an open order control + long_only. Now its normal.

Thanks for all the helps! Its a great hands on learning experience!