Add new position

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #35137 quote
    Abz
    Participant
    Veteran

    Hello

    i want to check  my position  on market i want to add one more shares to it with seperat profit target and stop loss. for example if iam longonmarket and my position is in -20points i want to buy 5 more shares. and same for if i am short on market and the trade is against me i want to short more shares. i want seperat target and stopp loss for these ekstra  shares.

    i did try this but cant get it to work

    if longonmarket and close - tradeprice < -20*pointsize then
    buy 5 SHARES AT MARKET
    SET STOP ploss 30//20
    SET TARGET pPROFIT 20 //54
    endif
    if shortonmarket and close - tradeprice > 20*pointsize then
    sellshort 5 SHARES AT MARKET
    SET STOP ploss 30//20
    SET TARGET pPROFIT 20 //54
    endif
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATBEFORE = 170000
    DEFPARAM FLATAFTER = 220000
    
    // indicators
    PSAR = SAR[0.02,0.02,0.2]
    MA = Average[41](close)
    Rs = RSI[15](close)
    c13 = Time < 192000
    
    // Conditions to enter Long positions
    c1 = (close > PSAR)
    c2 = (close crosses over MA)
    c3 = Rs <= 60
    
    IF not onmarket AND c13 AND c1 AND c2 AND c3 THEN
    Buy 2 SHARES AT MARKET
    ENDIF
    
    // Conditions to enter Short positions
    c6 = (close < PSAR)
    c7 = (close < MA)
    c8 = Rs >= 50
    
    IF not onmarket AND c13 AND c6 AND c7 AND c8 THEN
    Sellshort 2 SHARES AT MARKET
    ENDIF
    
    SET STOP pLOSS 50
    SET TARGET pPROFIT 50
    #35140 quote
    StantonR
    Participant
    Senior

    You First need to set this to true else no new positions will be entered

    DEFPARAM CumulateOrders = True// Cumulating positions deactivated
    
    
    
    #35141 quote
    StantonR
    Participant
    Senior
    Tested on EURUSD 1h Not sure if this is what you looking for not bad results
    
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    DEFPARAM FLATBEFORE = 170000
    DEFPARAM FLATAFTER = 220000
    
    // indicators
    PSAR = SAR[0.02,0.02,0.2]
    MA = Average[41](close)
    Rs = RSI[15](close)
    c13 = Time < 192000
    
    // Conditions to enter Long positions
    c1 = (close > PSAR)
    c2 = (close crosses over MA)
    c3 = Rs <= 60
    
    IF not onmarket AND c13 AND c1 AND c2 AND c3 THEN
    Buy 2 SHARES AT MARKET
    sl = 50
    tp = 50
    ELSIF longonmarket and close - tradeprice < -20*pointsize then
    buy 5 SHARES AT MARKET
    sl = 30
    tp = 20
    ENDIF
    
    // Conditions to enter Short positions
    c6 = (close < PSAR)
    c7 = (close < MA)
    c8 = Rs >= 50
    
    IF not onmarket AND c13 AND c6 AND c7 AND c8 THEN
    Sellshort 2 SHARES AT MARKET
    sl = 50
    tp = 50
    ELSIF shortonmarket and close - tradeprice > 20*pointsize then
    Sellshort 5 SHARES AT MARKET
    sl = 30
    tp = 20
    ENDIF
    
    SET STOP pLOSS sl
    SET TARGET pPROFIT tp
    
    
    
    eurusd.png eurusd.png
    #35172 quote
    Maz
    Participant
    Veteran

    Hiya,

    Not a terrible idea here. You should probably separate indicator variables for long and short entries though.

    Obviously a good amount of work needs to be done here to make it a viable strategy in PRT (dynamic stops and targets, more filtering, proper position size management, time management etc) but for now I’ve done a little tweak for you here. The optimization may make up for PRT’s lack of multi-position management tools such as multiple stops and limits – which is what I believe you were after, @Abz.

    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions deactivated
    DEFPARAM FLATBEFORE = 160000
    DEFPARAM FLATAFTER = 210000
    
    // Variables
    once optimization = 2
    
    if optimization = 1 then // original
    rsiPeriodLongs  = 15
    rsiPeriodShorts = 15
    maPeriodLongs   = 41
    maPeriodShorts  = 41
    maType = 0
    rsiLongThresh = 60
    rsiShrtThresh = 50
    
    elsif optimization = 2 then //EUR_USD H1
    rsiPeriodLongs  = 18
    rsiPeriodShorts = 18
    rsiLongThresh = 63
    rsiShrtThresh = 49
    
    maType = 5
    maPeriodLongs  = 41
    maPeriodShorts = 30
    
    endif
    
    tradingTime = time < 182000
    
    // indicators
    PSAR     = sar[0.02,0.02,0.2]
    MALongs  = average[maPeriodLongs,  maType](close)
    MAShorts = average[maPeriodShorts, maType](close)
    rLongs   = rsi[rsiPeriodLongs](close)
    rShorts  = rsi[rsiPeriodShorts](close)
    
    // Conditions to enter Long positions
    c1 = (close > PSAR)
    c2 = (close crosses over MALongs)
    c3 = rLongs <= rsiLongThresh
    
    IF (not onmarket) AND tradingTime AND c1 AND c2 AND c3 THEN
    Buy 2 SHARES AT MARKET
    sl = 50
    tp = 50
    ELSIF longonmarket and close - tradeprice < -20*pointsize then
    buy 5 SHARES AT MARKET
    sl = 30
    tp = 20
    ENDIF
    
    // Conditions to enter Short positions
    c6 = (close < PSAR)
    c7 = (close < MAShorts)
    c8 = rShorts >= rsiShrtThresh
    
    IF not onmarket AND tradingTime AND c6 AND c7 AND c8 THEN
    Sellshort 2 SHARES AT MARKET
    sl = 50
    tp = 50
    ELSIF shortonmarket and close - tradeprice > 20*pointsize then
    Sellshort 5 SHARES AT MARKET
    sl = 30
    tp = 20
    ENDIF
    
    SET STOP pLOSS sl
    SET TARGET pPROFIT tp

     

    Note this is just very quick and rough – not for production – but do continue tweaking. This version was wrapped around EUR_USD H1 and has at least a year of spinning its wheels (take the equity curve with a pinch of salt). I have also changed timezone for my locale so do change the times to your own locale.

    Best,

    M

    sar-ma-rsi-eur_usd-h1.png sar-ma-rsi-eur_usd-h1.png
    #35197 quote
    Barney
    Participant
    Senior

    Question.

    Why do you want to add more shares to a bad position.

    It should be better to buy more shares when you are+

    #35217 quote
    Abz
    Participant
    Veteran

    hello

     

    thanks for help, but when i am testing it seems like when it is  adding a new position it close the previous one?

    #35256 quote
    Abz
    Participant
    Veteran

    i managed to get it working. Thanks for all help. i will try it on different instrument and post here if there are good results

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

Add new position


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Abz @abbas_sadiq Participant
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by Abz
8 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/10/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...