Add position when price drops 0.3%
01/05/2020 at 2:05 PM #11592301/05/2020 at 2:19 PM #115926
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:12drop = 0.3if longonmarket and close <= positionprice * (1-(drop/100))01/05/2020 at 3:16 PM #11593201/05/2020 at 3:20 PM #11593401/05/2020 at 3:27 PM #11593601/05/2020 at 9:02 PM #115966
Ive Tried several ways and i cant find the right way.123456789IF CONDBUY THENONCE Positionsize = 0.5buy positionsize contract at marketSET TARGET %PROFIT 2SET STOP %LOSS 1.3ENDIFdrop = 0.3If longonmarket and close <= positionprice * (1-(drop/100)) THENENDIF01/05/2020 at 10:43 PM #11597601/05/2020 at 10:53 PM #1159771234567891011121314151617Positionsize = 0.5IF CONDBUY THENbuy positionsize contracts at marketENDIFIf countofposition = positionsize and close <= positionprice * (1 - 0.003) THENbuy positionsize contracts at marketfirstprice = positionpriceENDIFIf countofposition = positionsize * 2 and close <= firstprice * (1 - 0.01) THENbuy positionsize contracts at marketENDIFSET TARGET %PROFIT 2SET STOP %LOSS 1.301/06/2020 at 9:49 AM #11599701/06/2020 at 11:28 AM #116021
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!01/06/2020 at 12:03 PM #116026
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.01/08/2020 at 7:48 PM #116238Code of stops and profits for three positions... and code of trailing stop123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102//Tamaño, Profit y Stop de la posicionPositionsize = 0.5IF CONDBUY THENbuy positionsize contract at marketSET TARGET %PROFIT 2SET STOP %LOSS 1.3ENDIFIf countofposition = positionsize and close <= positionprice * (1 - 0.003) THENBuy positionsize contract at marketfirstprice = positionpriceSET TARGET %PROFIT 2.3SET STOP %LOSS 1ENDIFIf countofposition = positionsize * 2 and close <= firstprice * (1 - 0.01) THENBuy positionsize contract at marketSET TARGET %PROFIT 3SET STOP %LOSS 0.3ENDIF//TRAILING STOP//Variables de trailing stoponce enablets=1once displayts=0if enablets thenonce steps=0.05once minatrdist=3.3once atrtrailingperiod = 25 // atr parameter valueonce minstop = 0 // minimum trailing stop distanceif barindex=tradeindex thentrailingstoplong = 5.1 // trailing stop atr relative distancetrailingstopshort = 5 // trailing stop atr relative distanceelsif prezzouscita>0 thenif longonmarket thenif trailingstoplong>minatrdist thenif prezzouscita>prezzouscita thentrailingstoplong=trailingstoplongelsetrailingstoplong=trailingstoplong-stepsendifelsetrailingstoplong=minatrdistendifendifif shortonmarket thenif trailingstopshort>minatrdist thenif prezzouscita<prezzouscita thentrailingstopshort=trailingstopshortelsetrailingstopshort=trailingstopshort-stepsendifelsetrailingstopshort=minatrdistendifendifendif//atrtrail=averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000trailingstartl=round(atrtrail*trailingstoplong)trailingstarts=round(atrtrail*trailingstopshort)tgl=trailingstartltgs=trailingstarts//if not onmarket or ((longonmarket and shortonmarket) or (longonmarket and shortonmarket)) then//or (longonmarket and condsell) or (shortonmarket and condbuy) thenmaxprice=0minprice=closeprezzouscita=0endif//if longonmarket then//and not condsell thenmaxprice=max(maxprice,close)if maxprice-tradeprice(1)>=tgl*pointsize thenif maxprice-tradeprice(1)>=minstop thenprezzouscita=maxprice-tgl*pointsizeelseprezzouscita=maxprice-minstop*pointsizeendifendifendif//if shortonmarket then//and not condbuy thenminprice=min(minprice,close)if tradeprice(1)-minprice>=tgs*pointsize thenif tradeprice(1)-minprice>=minstop thenprezzouscita=minprice+tgs*pointsizeelseprezzouscita=minprice+minstop*pointsizeendifendifendif//if onmarket and prezzouscita>0 thenexitshort at prezzouscita stopsell at prezzouscita stopendifif displayts thengraphonprice prezzouscita coloured(0,0,255,255) as "trailingstop atr"endifendif01/08/2020 at 7:55 PM #116239
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.01/08/2020 at 7:59 PM #11624101/09/2020 at 8:40 AM #116266
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.