Add position when price drops 0.3%

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #115923 quote
    Fran55
    Participant
    Veteran

    I have a position bought, and i want when the price drops by 0.3% to buy another position.

    Ive tried this code and the like but they dont work.

    Screenshot_1.png Screenshot_1.png
    #115926 quote
    Vonasi
    Moderator
    Master

    I’ve changed your topic title as your title was meaningless. Please use topic titles that actually mean something in your future topics.

    Also post the actual code using the ‘Insert PRT Code’ button rather than post a screenshot as that makes it much easier for others to help you.

    Your percentage calculation is incorrect. A 0.3% drop would be:

    drop = 0.3
    if longonmarket and close <= positionprice * (1-(drop/100))
    #115932 quote
    Fran55
    Participant
    Veteran

    Ok Vonasi, thanks!!!

    Other question:

    If i want two positions?

    The first position when price go down 0.3%, and the second position when price go down 1%.

    Complete Code please… And more thanks!!!

    #115934 quote
    Vonasi
    Moderator
    Master

    Use COUNTOFPOSITION in your conditions. If it equals 0.5 then you have one position open. If it equals 1 then you have 2 x 0.5 long positions open.

    #115936 quote
    Fran55
    Participant
    Veteran

    WoW!!!

    You are fast and furious!!!

     

    So mucho thanks!!!

    #115966 quote
    Fran55
    Participant
    Veteran

    Hi!!!

     

    Ive Tried several ways and i cant find the right way.

    IF CONDBUY THEN
    ONCE Positionsize = 0.5
    buy positionsize contract at market
    SET TARGET %PROFIT 2
    SET STOP %LOSS 1.3
    ENDIF
    drop = 0.3
    If longonmarket and close <= positionprice * (1-(drop/100)) THEN
    ENDIF
    #115976 quote
    Vonasi
    Moderator
    Master

    Also post the actual code using the ‘Insert PRT Code’ button

    Hi!!! I’ve tidied up your post for you!!!

    #115977 quote
    Vonasi
    Moderator
    Master
    Positionsize = 0.5
    
    IF CONDBUY THEN
    buy positionsize contracts at market
    ENDIF
    
    If countofposition = positionsize and close <= positionprice * (1 - 0.003) THEN
    buy positionsize contracts at market
    firstprice = positionprice
    ENDIF
    
    If countofposition = positionsize * 2 and close <= firstprice * (1 - 0.01) THEN
    buy positionsize contracts at market
    ENDIF
    
    SET TARGET %PROFIT 2
    SET STOP %LOSS 1.3
    #115997 quote
    Fran55
    Participant
    Veteran

    Hi boys!!!

    The Code is good… But i have new problems.

    The system of trailing stop only Affect to the first position, the idea is Affect to all positions.

    I go Up one post of code today.

    #116021 quote
    Vonasi
    Moderator
    Master

    There is no trailing stop in your code?

    If you open several positions then it is easy to treat them as a whole. That is combined number of contracts at the average bought price. If we wanted to code separate trailing stops for every individual time a position is opened then we would need to store a lot of individual information about each position. Arrays (which we don’t currently have in PRT) would be useful for this but without them we would have to run individual trailing stop codes for each open position. Possible for a limited number of open positions but not the work of a moment. I’ve not found much or any benefit to trailing stops so I’ll leave coding that to someone else rather than spend lots of time on something that I’ll never use!

    #116026 quote
    Fran55
    Participant
    Veteran

    Yes, is this the problem…

    The first operation: stop 1.3% and profit 2%.

    The second operation: stop 1% and profit 2.3%.

    The third operation: stop 0.3% and profit 3%.

    And for all positions the same trailing stop.

    #116238 quote
    Fran55
    Participant
    Veteran

     

    //Tamaño, Profit y Stop de la posicion
    Positionsize = 0.5
    
    IF CONDBUY THEN
    buy positionsize contract at market
    SET TARGET %PROFIT 2
    SET STOP %LOSS 1.3
    ENDIF
    If countofposition = positionsize and close <= positionprice * (1 - 0.003) THEN
    Buy positionsize contract at market
    firstprice = positionprice
    SET TARGET %PROFIT 2.3
    SET STOP %LOSS 1
    ENDIF
    If countofposition = positionsize * 2 and close <= firstprice * (1 - 0.01) THEN
    Buy positionsize contract at market
    SET TARGET %PROFIT 3
    SET STOP %LOSS 0.3
    ENDIF
    
    //TRAILING STOP
    //Variables de trailing stop
    once enablets=1
    once displayts=0
     
    if enablets then
    once steps=0.05
    once minatrdist=3.3
    once atrtrailingperiod    = 25   // atr parameter value
    once minstop              = 0   // minimum trailing stop distance
     
    if barindex=tradeindex then
    trailingstoplong     = 5.1   // trailing stop atr relative distance
    trailingstopshort    = 5   // trailing stop atr relative distance
    elsif prezzouscita>0 then
    if longonmarket then
    if trailingstoplong>minatrdist then
    if prezzouscita>prezzouscita[1] then
    trailingstoplong=trailingstoplong
    else
    trailingstoplong=trailingstoplong-steps
    endif
    else
    trailingstoplong=minatrdist
    endif
    endif
     
    if shortonmarket then
    if trailingstopshort>minatrdist then
    if prezzouscita<prezzouscita[1] then
    trailingstopshort=trailingstopshort
    else
    trailingstopshort=trailingstopshort-steps
    endif
    else
    trailingstopshort=minatrdist
    endif
    endif
    endif
    //
    atrtrail=averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000
    trailingstartl=round(atrtrail*trailingstoplong)
    trailingstarts=round(atrtrail*trailingstopshort)
    tgl=trailingstartl
    tgs=trailingstarts
    //
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then//or (longonmarket and condsell) or (shortonmarket and condbuy) then
    maxprice=0
    minprice=close
    prezzouscita=0
    endif
    //
    if longonmarket then//and not condsell then
    maxprice=max(maxprice,close)
    if maxprice-tradeprice(1)>=tgl*pointsize then
    if maxprice-tradeprice(1)>=minstop then
    prezzouscita=maxprice-tgl*pointsize
    else
    prezzouscita=maxprice-minstop*pointsize
    endif
    endif
    endif
    //
    if shortonmarket then//and not condbuy then
    minprice=min(minprice,close)
    if tradeprice(1)-minprice>=tgs*pointsize then
    if tradeprice(1)-minprice>=minstop then
    prezzouscita=minprice+tgs*pointsize
    else
    prezzouscita=minprice+minstop*pointsize
    endif
    endif
    endif
    //
    if onmarket and prezzouscita>0 then
    exitshort at prezzouscita stop
    sell at prezzouscita stop
    endif
    if displayts then
    graphonprice prezzouscita coloured(0,0,255,255) as "trailingstop atr"
    endif
    endif
    #116239 quote
    Fran55
    Participant
    Veteran

    Okay guys.

    What i have so far is this.

    I need trailing stop affect all 3 positions when they enter the market… now it only affect the first position.

    And only the first stop and profit of the first position works… i need the stops and profits of the other position to works.

    #116241 quote
    Fran55
    Participant
    Veteran

    These are the results go far in two years.

    Im sure youre not interested Vonasi???

    Screenshot_2-1.png Screenshot_2-1.png
    #116266 quote
    Vonasi
    Moderator
    Master

    Every time your code reads a SET TARGET or SET STOP order it changes the exit orders for all open positions to the distance shown. To have different levels you need to place STOP and LIMIT orders at every bar close to partially close a position at different levels. Partial closure is not possible in live trading using PRT at the moment so this code could end up being a lot of work for no benefit.

    Your trailing stop code as it is will only trail a stop from the last opening position price.

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

Add position when price drops 0.3%


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Fran55 @fran55 Participant
Summary

This topic contains 17 replies,
has 3 voices, and was last updated by Fran55
6 years, 1 month ago.

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