TAKE PROFIT when 2 EMA crosses

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #182355 quote
    pmattez
    Participant
    New

    Hi everyone, I’m new with coding and I would appreciate your support.

    I have defined a rule to buy/sell based on some conditions:

    IF NOT LongOnMarket and plage and condition1 THEN
    BUY 1 CONTRACTS AT MARKET

    ENDIF

    I would like to add that Take Profit will be done as soon as 2 EMAs are crossing under

    AND

    I would like to define the Stop Loss at the most recent Lowest price

     

    Could you help ?

    Thanks a lot,

    Patrice.

    #182363 quote
    robertogozzi
    Moderator
    Master

    For the SL, the most recent low is that of the current bar, when the strategy places the opening order of an operation:

    Set Stop Loss abs(close - low)

    TP can be detected at this bearish crossover:

    IF average[10,0](close) CROSSES UNDER average[100,0](close) THEN
       SELL AT MARKET
    ENDIF
    #182367 quote
    pmattez
    Participant
    New

    Thanks. I have tried the following but it is not behaving at all as expected.

    Instead of Average I would like as well to work with exponential average.

    Here is the code I used which is not working correctly:

    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket and condition THEN
    BUY 1 CONTRACTS AT MARKET
    IF average[8](close) CROSSES UNDER average[20](close) THEN
    SELL AT MARKET
    ENDIF
    ENDIF

    // Conditions pour ouvrir une position en vente à découvert
    IF NOT ShortOnMarket and condition THEN
    SELL 1 CONTRACTS AT MARKET
    IF average[8](close) CROSSES OVER average[20](close) THEN
    BUY AT MARKET
    ENDIF
    ENDIF

     

    Thanks a lot for your help

    #182368 quote
    nonetheless
    Participant
    Master
    IF average[8,1](close) CROSSES UNDER average[20,1](close) THEN

    this will give you EMA

    #182369 quote
    JS
    Participant
    Senior

    EMA => Average[8,1](Close) or Average[20,1](Close)

    For short positions use SellShort instead of Sell

    Sell will only close a long (Buy) position

    Buy versus Sell

    SellShort versus ExitShort

    #182371 quote
    pmattez
    Participant
    New

    Thanks to all working fine now 🙂

    #182636 quote
    pmattez
    Participant
    New

    Hi

    I have still an issue with my code. The code enter the market according to the condition defined. no problem.

    Stop loss is ok but Target profit is not taken based on the condition. Could you help ? Many thanks

    indicateur2= ExponentialAverage[20](close)

    indicateur5= ExponentialAverage[8](close)

    c9short= (indicateur5 < indicateur2)

    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket and plage and c1long and c1longbis and c1longtiers and c4long and c8long and c9long and c10long THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP LOSS 20
    IF c9short THEN
    SELL 1 CONTRACTS AT MARKET
    ENDIF
    ENDIF

    Thanks again

    #182640 quote
    robertogozzi
    Moderator
    Master

    Move the last ENDIF to immediately BEFORE IF c9short THEN.

    #182642 quote
    pmattez
    Participant
    New

    many thanks 🙂

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

TAKE PROFIT when 2 EMA crosses


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
pmattez @pmattez Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by pmattez
4 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/26/2021
Status: Active
Attachments: No files
Logo Logo
Loading...