===== Pruebas de note plugin ===== This is my note ! Remember it !! Warning ! You're about to lose your mind ;-) The clues are in the images. Beware of the dog when you open the door !! ===== Pruebas de box plugin ===== HOla Mundo Hola Pancho '¡¡ Parameters Dim Periodo As Long '60 Dim numContratos As Double '1 Dim TipoStop As Double '1 Dim RangoStop As Double '40 Dim Intradiario As Integer '1 Dim FinSesion As Integer '1730 'Parameters !! Const Data As Long = 0 Dim Precio As Double Dim nBarras As Double Dim TipoOperacion As Double ' Compra=1 Venta=-1 Dim OrigenDato As Price 'Price 'Dim FinSesion As Integer ' valor de la hora a la que salgo del sistema Dim Indicador As Long Dim Operando As Double Dim FactorCorrector As Double ' Factor corrector del Trailing Stop Dim ESTADOACTIVO As Boolean Option Explicit Public APP As SysUserApp Implements System Public Sub System_OnInitCalculate() With APP OrigenDato = PriceClose '0 'LongAverageDataSource = PriceClose Indicador = .GetIndicatorIdentifier(BASICREPULSE, Data, Periodo, OrigenDato) .StartBar = 0 TipoOperacion = 0 Operando = 0 FactorCorrector = 1 End With End Sub Public Sub System_OnCalculateBar(ByVal Bar As Long) With APP '¡¡ compra si el indicador corta el cero hacia arriba y vende si corta hacia abajo Operando = .GetMarketPosition(0) 'Almacena el precio para el que salta el stop en la primera barra If .GetBarsSinceEntry = 1 Then If TipoOperacion = 1 Then Precio = APP.GetEntryPrice(0) - RangoStop ElseIf TipoOperacion = -1 Then Precio = APP.GetEntryPrice(0) + RangoStop End If FactorCorrector = 1 End If If (Intradiario = 1 And .Time < FinSesion) Then ESTADOACTIVO = True If Operando = 0 And ESTADOACTIVO Then If .GetIndicatorValue(Indicador) > 0 And .GetIndicatorValue(Indicador, 1) < 0 Then .Buy AtClose, numContratos TipoOperacion = 1 ElseIf .GetIndicatorValue(Indicador) < 0 And .GetIndicatorValue(Indicador, 1) > 0 Then ' vende en caso contrario .Sell AtClose, numContratos TipoOperacion = -1 End If Else 'Condiciones de salida por tiempo en una sesión If Intradiario = 1 And .Time >= FinSesion Then .ExitLong AtClose, numContratos .ExitShort AtClose, numContratos Else TrailingStop 'llama al trailing Stop End If End If End With End Sub Private Sub TrailingStop() 'me gustaria incorporar un filtro temporal 'que segun pasasen las barras ajustara más aún el trailingStop With APP If .GetBarsSinceEntry > 5 Then FactorCorrector = FactorCorrector - 0.05 If .CurrentBar >= nBarras Then If TipoOperacion = 1 Then If TipoStop = 1 Then If .Close >= (Precio + RangoStop) Then Precio = .Close - (RangoStop * FactorCorrector) End If Else If .Close >= (Precio + (Precio * RangoStop) / 100) Then Precio = .Close - (.Close * RangoStop * FactorCorrector) / 100 End If End If .ExitLong AtStop, numContratos, Precio, Label:="StopL" Else If TipoOperacion = -1 Then If TipoStop = 1 Then If .Close <= (Precio - RangoStop) Then Precio = .Close + (RangoStop * FactorCorrector) End If Else If .Close <= (Precio - (Precio * RangoStop) / 100) Then Precio = .Close + (.Close * RangoStop * FactorCorrector) / 100 End If End If .ExitShort AtStop, numContratos, Precio, Label:="StopL" End If End If End If End With End Sub Public Sub System_OnSetParameters(ParamArray ParamList() As Variant) '¡¡ Parameters initialization Periodo = ParamList(1) numContratos = ParamList(2) TipoStop = ParamList(3) RangoStop = ParamList(4) Intradiario = ParamList(5) FinSesion = ParamList(6) 'Parameters initialization !! End Sub Public Sub System_OnCalculateRange(ByVal StartBar As Long, ByVal FinalBar As Long) Dim i As Long i = APP.StartBar If StartBar > i Then i = StartBar End If While Not APP.ShouldTerminate And i <= FinalBar APP.CurrentBar = i System_OnCalculateBar i i = i + 1 Wend End Sub Private Sub SysUserAppInstance_OnConnection(ByVal Application As SysUserApp, ByVal MTDllInst As Object, Custom() As Variant) Set APP = Application End Sub