Short code works, long code not

Forums ProRealTime English forum General trading discussions Short code works, long code not

Viewing 6 posts - 1 through 6 (of 6 total)
  • #226507

    Hi! I was wondering if anyone could help me whith this code.

    I have tested the code below on a timeperiod where
    ‘Entertrade’ and ‘Cantrade = 1’ are met at the beginning of the timeperiod,
    resulting in one trade (and I have set DEFPARAM CumulateOrders = True).

    // Trading condition with trade check
    IF not shortonmarket and EnterTrade AND CanTrade = 1 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    AveragingCount = 0
    ENDIF

    Yet when I try this (starting with the same code, and adding my averaging down logic)
    no trades happen during the same period.

    // Trading condition with trade check
    IF not shortonmarket and EnterTrade AND CanTrade = 1 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    AveragingCount = 0
    ENDIF

    // Averaging Down Logic
    IF shortonmarket AND AveragingCount = 0 AND positionprice <= (tradeprice * 0.99867) THEN
    SELLSHORT 1 CONTRACT AT MARKET
    AveragingCount = 1
    ENDIF

    // Take Profit Logic for Accumulated Position
    IF positionprice >= (tradeprice * 1.00088) THEN
    EXITSHORT AT MARKET
    ENDIF

    What could be wrong? I’m using IG as booker, if that has any impact.

    Best regards

    #226509

    I guess above is not your full code as Topic title mentions Longs and posted code does not mention Longs.

    Anyway try putting below after Defparam statements at top of your code

     

    1 user thanked author for this post.
    #226520

    Thank you for your quick response. I realize now that my title is confusing. I meant that the beginning of the code works, while the full code does not.

    I will try adding ‘once’ to the code.

     

    Best regards,

    #226521

    Adding ‘once’ made no difference. And also, I don’t see why I should add it. If the strategy enters a trade, notes that zero averaging downs has happened, and then averages down when the conditions for averaging down are met, and then exits the trade when the conditions for exiting the trade are met, it should be able to start over again when the strategy’s conditions for entering a trade are met anew, and start counting instances of averaging down again. Or am I missing something?

    #226529

    Because

    wll NEVER be true, because positionprice and tradeprice are EQUAL.

    They will only be different AFTER at least an additional position opens, which will never happen, though.

    This snippet will work:

     

     

    2 users thanked author for this post.
    #226578

    Thank you for your sollution. Yes, that works. However, I want the strategy to act as soon as the level is triggered, not wait until the bar is closed.

    1 user thanked author for this post.
Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login