Hi all !
I’d like to create a %Stop @ -2% (like today for instance) but from the “Dopen”.
Why? Cause most of the time, the instrument bounce back a bit from the specific % amount of distribution…
It should be something like the following but I have trouble replacing the (0) by the correct value…
Any help please ?
Thank you 😉
// Conditions pour fermer une position en vente à découvert
c1 = (DOpen(0) < 0)
IF c1 THEN
EXITSHORT AT MARKET
ENDIF
Replace line 1 with:
c1 = close <= (DOpen(0) * 0.98)
Thank you Robertogozzi !
It works fine until 0.99% but then it goes blank from 1.0, 1.1 onwards…
From 1.0 onwards C1 will be false and there will be no exit due to stop loss.
I think you also added some target profit.
I am not sure I could understand what you really meant.
Hi Robertogozzi,
Thank you for your time !
Your are right, it should mostly have a second “%TP” from the “Dopen” this time !
Not a %stop cause it’s a short position :/ ! My mistake…
So the strategy should then have “technically” two %Target Profit with and IF somewhere in the middle I suppose…like and OCO order.
- (1) SET TARGET %PROFIT 1 like the code
- AND
- (2) If the TP (1) is not triggered then (2) … c1 = close <= (DOpen(0) * 2%)
Is it clearer Roberto?
Good night and thank you for your help.
IF (c1) AND (c2) AND (c3) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
SELLSHORT positionsize CONTRACT AT MARKET
ENDIF
c4 = close <= (DOpen(0) * 0.8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
//trailing stop
trailingstop = (close*0.0045)/pointsize
if not onmarket then
MINPRICE = close
priceexit = 0
endif
if shortonmarket then
MINPRICE = MIN(MINPRICE,close)
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then
priceexit = MINPRICE+trailingstop*pointsize
endif
endif
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
SET STOP %LOSS 0.5
SET TARGET %PROFIT 1
In your code this is a 20% gain on a short:
c4 = close <= (DOpen(0) * 0.8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
2% would be 0.98 as Robertogozzi already said.
This condition whether 2% or 20% will never be hit if you also have SET TARGET %PROFIT 1 in your code – which you do have.
Ok, now I got it !
Big thanks Vonasi and Robertogozzi !
FYI for you, It gives even better results…