Called once for each instrument which has an existing position, the Adjust Instrument Risk script can be used to adjust stops and reduce or exit positions based on portfolio-level risk as computed in the Compute Risk Adjustment script.

 

The Total Risk Limiter block uses this script to move stops or reduce positions based on the reductionPercent computed in the Compute Risk Adjustment script:

 
VARIABLES: quantity, reductionQuantity TYPE: Integer
VARIABLES: risk TYPE: Floating
VARIABLES: newStop TYPE: Price
 
' If we need to reduce risk
IF reductionPercent > 0.0 THEN
 
  IF reductionAlgorithm = REDUCE_POSITIONS THEN
      ' Reduce the position by this amount.
      broker.AdjustPositionOnOpen( 1.0 - reductionPercent )
  ENDIF
   
  IF reductionAlgorithm = MOVE_STOPS THEN
   
      IF instrument.position = LONG THEN
          ' Adjust the stops for each unit.
          FOR index = 1 to instrument.currentPositionUnits
           
              ' Determine the current risk.
               risk = instrument.close -
                      instrument.unitExitStop[index]
               
              ' Determine the stop that corresponds with
              ' the reduced risk.
               newStop = instrument.close -
                      ((1 - reductionPercent) * risk)
               
              ' Set the new stop.
              instrument.SetExitStop( index, newStop )
              broker.ExitUnitOnStop( index, newStop )
          NEXT
      ENDIF ' Long

       
      IF instrument.position = SHORT THEN
          ' Adjust the stops for each unit.
          FOR index = 1 to instrument.currentPositionUnits
           
              ' Determine the current risk.
               risk = instrument.unitExitStop[index] -
                      instrument.close
               
              ' Determine the stop that corresponds with
              ' the reduced risk.
               newStop = instrument.close +
                      ((1 - reductionPercent) * risk)
               
              ' Set the new stop.
              instrument.SetExitStop( index, newStop )
              broker.ExitUnitOnStop( index, newStop )
          NEXT
      ENDIF ' Short
  ENDIF ' Algorithm Move Stops
ENDIF ' There is a reduction required

 

 


Edit Time: 9/25/2017 09:09:58 AM


Topic ID#: 130

 

Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software