Add new position when + 50 points

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #175402 quote
    bullbear
    Participant
    Senior

    Hello

    I am looking for a code that means that if I am +50 points, another position is opened with 1 contract.

    But it should not be repeated more than once so max position size = 2.

    Like this maybe?

    defparam cumulateorders = true
    
    Positionsize = 1
    maxpositions = 2
    
    if ”my conditions ” and not  maxpositions and not not  shortonmarket then
    buy positionsize contract at market
    
    IF OnMarket and  PositionPrice + (50 * PositionPrice) then
    Buy positionsize contract at market
    
    ENDIF
    #175413 quote
    XORANDNOT
    Participant
    Senior
    defparam cumulateorders = true
     
    Positionsize = 1
    maxpositions = 2
     
    if ”my conditions ” and (not onmarket) then
    buy positionsize contracts at market
    endif
     
    If longonmarket and  positionprice  * positionperf >= 50 and countofposition < maxpositions then
    Buy positionsize contracts at market
    ENDIF
    

    This will buy 1 contract, when no position is open, and buy one further contract when the closing price of the first position is at least 50 points in plus. Not tested, however. Will work for indices, but I’m not sure about forex because they work with pips there.

    Nicolas and bullbear thanked this post
    #183010 quote
    bullbear
    Participant
    Senior

    Have previously asked about a new position be opened.

    But it does not work.

    It opens new positions all the time.

    I want only 1 more position to be opened when my position is +40 points.

    And the new position will be closed at the same time as the first

    Does anyone know what such a code looks like?

    #183026 quote
    JS
    Participant
    Senior

    Try: Defparam cumulateorders = false (instead of true)

    #183027 quote
    JS
    Participant
    Senior

    You can also try: abs(countofposition)

    #183029 quote
    nonetheless
    Participant
    Master

    Try this.

    At current prices, positionprice * 1.0025 on the DAX is approx a 40 point gain. You can change the multiplier depending on what instrument you want to use.

    It should make your backtest more accurate, as it keeps your gain relational to the historical index value.

    DEFPARAM CUMULATEORDERS = TRUE
    
    if not onmarket then
    flag = 1
    ENDIF
    
    // Conditions to enter long positions
    IF not longonmarket and CONDITIONS THEN
    BUY positionsize CONTRACT AT MARKET
    elsif longonmarket and CONDITIONS and flag and HIGH >= (positionprice * 1.0025) then
    BUY positionsize CONTRACT AT MARKET
    flag = 0
    ENDIF
    Midlanddave thanked this post
    #183031 quote
    bullbear
    Participant
    Senior

    Thank you n.

    The code works.

    A maximum of 2 positions are taken 🙂

    But sometimes the second position is taken at +40 points and sometimes at + 120-130 points.

    How is it that..

    #183032 quote
    nonetheless
    Participant
    Master

    What instrument are you using?

    you could try

    G = (40/close) + 1
    
    HIGH >= (positionprice * G)

    or if you don’t mind if it’s not proportional you could just use

    HIGH >= (positionprice + 40)
    #183033 quote
    bullbear
    Participant
    Senior

    Nasdaq

    #183035 quote
    bullbear
    Participant
    Senior

    I try that.

    Thanks

    #183037 quote
    bullbear
    Participant
    Senior

     

    if not onmarket then
    flag = 1
    ENDIF
    
    IF not shortonmarket and condsell THEN
    sellshort positionsize CONTRACT AT MARKET
    elsif shortonmarket and condsell and flag and HIGH >= (positionprice - 40) then
    sellshort positionsize CONTRACT AT MARKET
    flag = 0
    ENDIF
    

    And short looks like this?

    #183043 quote
    nonetheless
    Participant
    Master
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    if not onmarket then
    flag = 1
    flagS = 1
    ENDIF
    IF not shortonmarket and condsell THEN
    sellshort positionsize CONTRACT AT MARKET
    elsif shortonmarket and condsell and flagS and LOW <= (positionprice 40) then
    sellshort positionsize CONTRACT AT MARKET
    flagS = 0
    ENDIF
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Add new position when + 50 points


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
bullbear @bullbear Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by nonetheless
4 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/15/2021
Status: Active
Attachments: No files
Logo Logo
Loading...