Simple example needed: Buy / Sell (max 2 positions)

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #81737 quote
    J Hancock
    Participant
    New

    Hi, I’m struggling to pick up the lingo – mainly the financial stuff as I’ve got programming experience (but not been trading much). Apologies therefore for some stupid questions.

    I’m looking for a very simple example that I can build on, e.g.:
    1. Open 2 positions: BUY and SELL
    2. If the BUY price goes up by X% compared to the opening rate, close the BUY position and then open another
    3. If the SELL price goes down by X% compared to the opening rate, close the SELL position and then open another
    4. If either position goes into the red by Y%, close it and then open another in the same direction

    I only want one open position in each direction at any given time to limit exposure.

    I tried the below but it didn’t seem to work (opened too many positions?):

    Defparam cumulateorders = false
    
    n = 50 // Number of shares
    x = 10 // Profit
    y = 20 // Max loss
    
    // Only ever have one position open in each direction
    IF NOT LONGONMARKET THEN
        buy n shares at market
    ENDIF
    IF NOT SHORTONMARKET THEN
        sellshort n shares at market
    ENDIF
    
    // Close at profit or loss
    set target %profit x
    set stop %loss y

    A few questions also:
    a) Is the order fee taken into account for profit or loss (the last two lines in my example)?
    b) I also can’t figure out why, when I use the ProBacktest, the timescale resolution drives the number of positions that get opened? I only want two (one in each direction) at any given time. What settings should I use to simulate this?
    c) Do I need to set restrictions around trading days, e.g. not to buy/sell on Saturdays or Sundays or will orders for these days just be ignored?

    Many thanks in advance for any pointers! Once I get up to speed I will of course share my success (fingers crossed) 🙂

    #81749 quote
    Nicolas
    Keymaster
    Master

    a) No, orders in backtests are sent at mid level, order fees are added in the settings window manually.

    b) It is not possible to hedge order with a contrarian one with ProBacktest/ProOrder. You can only buy or sell at the same time in the same strategy. Code is also read once per bar, at its Close.

    c) Yes, with Date & Time instructions.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Simple example needed: Buy / Sell (max 2 positions)


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
J Hancock @j_hancock88 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
7 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/02/2018
Status: Active
Attachments: No files
Logo Logo
Loading...