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.
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))
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!!!
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.
WoW!!!
You are fast and furious!!!
So mucho thanks!!!
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
Also post the actual code using the ‘Insert PRT Code’ button
Hi!!! I’ve tidied up your post for you!!!
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
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.
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!
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.
//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
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.
These are the results go far in two years.
Im sure youre not interested Vonasi???
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.