Adolfo

Dynamic StopLoss following an indicator

Category: Strategies By: Adolfo Created: April 28, 2016, 3:33 PM
April 28, 2016, 3:33 PM
Strategies
6 Comments
Dynamic StopLoss following an indicator

Hi everybody!

In this example we are following a position with Parabolic SAR indicator.

Each new candle will be updating STOPLOSS to the new Parabolic SAR position.

REM INDICATOR
mySAR = SAR[0.02,0.02,0.2]


REM CONDITIONS
c1 = mySAR >= High
c2 = mySAR <= Low

IF Not OnMarket THEN
 IF c1 THEN
  BUY 1 CONTRACT AT mySAR STOP
 ENDIF
 IF c2 THEN
  SELLSHORT 1 CONTRACT AT mySAR STOP
 ENDIF
ENDIF


IF LongOnMarket THEN
 mySTOP = mySAR
  IF Close >= TradePrice(1) THEN
   mySTOP = mySAR
   SELL AT mySTOP STOP
  ELSE
   SELL AT mySTOP STOP
 ENDIF
ENDIF

IF ShortOnMarket THEN
 mySTOP = mySAR
  IF Close <= TradePrice(1) THEN
   mySTOP = mySAR
   EXITSHORT AT mySTOP STOP
  ELSE
   EXITSHORT AT mySTOP STOP
  ENDIF
ENDIF

 

Download
Filename: Dynamic-StopLoss-SAR.itf
Downloads: 406
Adolfo
Adolfo Senior
A ProRealTrader. I'm here to learn as much as I can, and improve my skills every single day!
Author’s Profile

Comments

David Black
6 years ago
#

#gm74 Did you ever get this figured out? gm74

denmar
9 years ago
#

Testing email notification to Denmar

denmar
9 years ago
#

Hi Could somebody please enlighten me how this code operates. I wish to use the code (is this an indicator?) as a mechanism to automatically adjust my stop once in a trade. Can one invoke this once one has opened a position manually? If so, how is this done. Is it simply a matter of attaching the "indicator" [My experience is limited to Metatrader where there was a difference between indicator and things called scripts] This being the case could I split the code and have one for long - including lines 19 -27 and one for short - including lines 29-37. Thank you

Madrosat
10 years ago
#

Quelqu'un pourrait il répondre à cette question restée sans suite???

gm74
10 years ago
#

I might have spoken too soon. Could you possibly shed some light? 

I am wanting to set dynamic stop losses based on my profit. In effect a highly customisable trailing stop.

Take the following for example. if the trade is 250 points in profit, I would like to set a stop loss at 100 points profit. Look at the following example for if I were in a short trade:

//Current trade points in profit 
profits=positionperf*tradeprice if shortonmarket then if profits>250 then exitshort at tradeprice-100 stop endif
if profits>400 then
exitshort at tradeprice-350
endif
endif

However, this does not give me the desired result. Do I also have to open the short in the same way? As I am currently opening the short as follows: 

sellshort at market

I do not wish to use trailing stops, as I want the freedom to adjust the stop trailing steps at various intervals. Ie, if 250 points in profit, exit if drop to 100 BUT if 400 points in profit, exit if drop to 350.

 

Any help would be appreciated. 

gm74
10 years ago
#

This has changed my life. Thank you!!!!!

ProRealCode ProRealCode
Loading...