Quiero que realice la siguiente entrada, sólo si el precio está un 4% por debajo de mi inversión

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #173729 quote
    Lisandro77
    Participant
    Average

    Hola Roberto, nuevamente estoy intentando practicar un poco con la programación. Me sucede lo siguiente:

    1er buy  16shares x 121,90

    Total Investment = 1950.4  16shares x 121,90

    2do buy  24shares x 120,52

    Entre la primer entrada y la segunda entrada el precio ha caido solo 1,13 %. Y solo quiero que realice la siguiente entrada, sólo si el precio está un 4% por debajo de mi inversión. No me debería realizar esa 2da compra, cual es mi error..? A continuación, un resumen de mi código.

    Agradezco mucho la ayuda que me puedan dar, para desbloquearme y poder continuar aprendiendo. Muchas gracias. Saludos.

    REM SISTEMA
    DEFPARAM CumulateOrders=TRUE
    TotalInvestment = PositionPrice * abs(CountOfPosition)
    MyLimit         = TotalInvestment * (100 - (4 / 100))
    ////
    ////
    IF ONMARKET THEN
    CUENTA = 1 + CUENTA[1]
    ELSE
    CUENTA = 0
    ENDIF
    ///CONDICIONES ENTRADA
    C1 = LINEAK < SOBREVENTA
    C2 = CLOSE < MS2004HS
    C3 = LINEAK CROSSES OVER lineaD
    ///CONDICIONES SALIDA
    S1 = LINEAK CROSSES UNDER sobrecompra
    
    IF NOT ONMARKET AND ((C1 AND C2) AND C3) THEN
    buy 2000 cash at market
    CUENTA = 1
    endif
    IF ONMARKET AND ((C1 AND C2) AND C3) AND TotalInvestment < MyLimit THEN
    buy 3000 cash at market
    CUENTA = CUENTA [1] + 1
    endif
    IF S1 THEN
    SELL AT MARKET
    ENDIF
    Consulta-Entradas.png Consulta-Entradas.png
    #173733 quote
    robertogozzi
    Moderator
    Master

    Cuando se trata de un tema diferente, es bueno abrir una nueva discusión, en lugar de agregarla a las existentes. Gracias 🙂

    Lisandro77 thanked this post
    #173735 quote
    robertogozzi
    Moderator
    Master

    Pruebe esto (no lo he probado porque faltan algunas variables):

    REM SISTEMA
    DEFPARAM CumulateOrders=TRUE
    PosNumber = abs(CountOfPosition)
    IF (PosNumber > 0) AND (PosNumber <> PosNumber[1]) THEN
    TotalInvestment = PositionPrice * PosNumber
    ENDIF
    IF Not OnMarket THEN
    CUENTA = 0
    ENDIF
    //CONDICIONES ENTRADA
    C1 = LINEAK < SOBREVENTA
    C2 = CLOSE < MS2004HS
    C3 = LINEAK CROSSES OVER lineaD
    //CONDICIONES SALIDA
    S1 = LINEAK CROSSES UNDER sobrecompra
    
    IF NOT ONMARKET AND ((C1 AND C2) AND C3) THEN
    buy 2000 cash at market
    CUENTA = 1
    endif
    IF ONMARKET AND ((C1 AND C2) AND C3) AND TotalInvestment < MyLimit THEN
    buy 3000 cash at market
    CUENTA = CUENTA + 1
    endif
    IF S1 THEN
    SELL AT MARKET
    ENDIF
    //
    //Graph        TotalInvestment
    //Graph        MyLimit
    //GraphOnPrice PositionPrice coloured(0,0.255,255)

    Agregué las últimas 3 líneas. Si quita los comentarios puede ver algunos valores, tanto en el gráfico como en la ventana de variables.

    ¿Por qué agregó la variable CUENTA si no la usa?

    Lisandro77 thanked this post
    #173744 quote
    Lisandro77
    Participant
    Average

    Perfecto Roberto! me ha servido para poder desbloquearme y seguir avanzando.

    Variable CUENTA, no le hagas caso….estoy probando diferentes cosas, y a veces realizo cosas sin sentido…estoy en modo “prueba y error”, y para ir probando diferentes situaciones y entender un poco más de programación, muchas veces realizo cosas sin sentido. Muchas gracias Roberto, saludos!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Quiero que realice la siguiente entrada, sólo si el precio está un 4% por debajo de mi inversión


ProOrder: Trading Automático y Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Lisandro77
4 years, 7 months ago.

Topic Details
Forum: ProOrder: Trading Automático y Backtesting
Language: Spanish
Started: 07/17/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...