Long bar Mean reverting code help

Forums ProRealTime English forum ProOrder support Long bar Mean reverting code help

Viewing 6 posts - 1 through 6 (of 6 total)
  • #82452

    Hi All,

     

    I would be very grateful for any help with this small sell side code.

    The idea is for shorter time frames which I use for day trading but struggling to automate it.

    Principles as below. Sell side only in this case.

    1. Two longer than average bars become the new ‘range’
    2. The middle of this range is the ‘mean’ for buying back.
    3. Once the range is set every new bar triggers a sell unless its low crosses below the mean
    4. At the ‘mean’ all shorts are bought back and the trade ends

    Questions are one

    1. Is this code ok as I cannot backtest it because I dont know how to (2)
    2. How do I set a MAX position

       

    Many thanks in advance

    #83368

    Is there anyone out there? 🙂

    #83374

    Your code looks OK.

    To back test just press the ‘ProBacktest my system’ button.

    Screenshot_2-2

    If by MAX position you mean that you want to set a limit to the number of positions opened then you can do this with a condition based on COUNTOFPOSITION or by adding 1 to a variable IF ONMARKET and then resetting that variable IF NOT ONMARKET and then use that variable quantity in your conditions as to whether to put a sellshort order on the market.

    1 user thanked author for this post.
    #83400

    Hi Vonasi,

     

    Many thanks for your reply.

    I have tried the back test but the problem I have is the position becomes to large.

    I have 2 questions

    1. Is there a way to code maximum position size ie. Sell every bar until position reaches 10 lots.
    2. Also If I want to set a buy level at say the low[1] before the first lots is sold, how would I code this, as currently each new sell creates a new buy back level!

    Once again this beginner really appreciates your time!

    #83413
    I’m not sure I fully understand question 2. Maybe this works as it fixes the levels until you have no trades on the market:

     

     

    1 user thanked author for this post.
    #83645

    Perfect. Problem solved. If it works I’ll post the full code. Thanks again

Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login