set profit or stop loss after 3 bars

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #10002 quote
    lebloe
    Participant
    Junior

    is it possible to  set profit or stop loss if the trade is 3 bars in market ?

    this doesn`t work

    IF ONMARKET AND (BarIndex - TradeIndex) >= 3 THEN
    
    SET TARGET PPROFIT 20
    
    ENDIF
    
    
    IF ONMARKET AND (BarIndex - TradeIndex) >= 3 THEN
    
    SET STOP PLOSS 20
    
    ENDIF
    #10013 quote
    Nicolas
    Keymaster
    Master

    Yes it would be possible, could you change and test your code with:

    IF ONMARKET AND (BarIndex - TradeIndex(1)) >= 3 THEN
     SET TARGET PPROFIT 20
     SET STOP PLOSS 20
    ENDIF

    Please let me know if it doesn’t work either.

    #10016 quote
    lebloe
    Participant
    Junior

    Hi Nicolas,

    thanks for reply.

    In Backtest it doesn´t work, i´ll give it a try in live trading.

    #10019 quote
    Nicolas
    Keymaster
    Master

    Do your orders are “on market” ones and not pending stop or limit ones?

    #10020 quote
    lebloe
    Participant
    Junior

    The ordertyp is pending stop

    #10022 quote
    Nicolas
    Keymaster
    Master

    Ok, but do you want your pending orders to have these TP/SL values after they have been placed for at least 3 bars or do you want the TP/SL to be set on these orders that have been triggered by price already (so now on market)?

    #10025 quote
    lebloe
    Participant
    Junior

    My first idea was, ich used it first for better backtest Results.. So, that the trades are Minimum 2 candles in the market..second idea is, the Orders geht This Stop after they become triggerd.. Tanks for your Patient..

    #10027 quote
    Nicolas
    Keymaster
    Master

    If I asked you the question about kind of trades you’d like to have this condition met, it’s because pending orders can’t have more than 1 bar old : they are deleted and re-placed at each bar (as long as you put them on).

    Ok, so the code I gave you should work for orders at market. Without your whole code strategy, I can’t be sure why it doesn’t work, so you can share me your code and I’ll be glad to debug it! 🙂

    #10032 quote
    Nicolas
    Keymaster
    Master

    Hmm I get a clue from someone already affected by this.

    Setting takeprofit and stoploss must be made before 3 bar elapsed, so I suggest this code instead:

    IF ONMARKET AND (BarIndex - TradeIndex(1)) >= 3 THEN
     SET TARGET PPROFIT 20
     SET STOP PLOSS 20
    ELSE
     SET TARGET PPROFIT 0
     SET STOP PLOSS 0
    ENDIF
    

    Which should resolved the problem I believe.

    #10033 quote
    lebloe
    Participant
    Junior

    thanks a lot .. i will test it.

    and this is the code without all the filters, this works on dax 15 min ..

    a = 39
    b = 7
    Upper1 = HIGHEST[a](HIGH[1])
    Lower1 = LOWEST[a](LOW[1])
    Tenkan = (Upper1 + Lower1) / 2
    
    Upper2 = HIGHEST[b](HIGH[1])
    Lower2 = LOWEST[b](LOW[1])
    Kijun = (Upper2 + Lower2) / 2
    
    asien = ( TIME < 080000 )
    m = 8
    HOCH1 = highest[m](high)
    HOCH2 = highest[m](high)
    if asien then
    HOCH = HOCH2
    else
    HOCH = HOCH1
    endif
    
    ichi = Kijun crosses over Tenkan
    
    buy1 = HOCH[1]
    
    if ichi then
    BUY 1 CONTRACT AT HOCH stop
    endif
    if ichi[1] then
    BUY 1 CONTRACT AT buy1 stop
    endif
    
    IF (BarIndex - TradeIndex(1)) >= 3 THEN
    SET TARGET PROFIT 20
    SET STOP PLOSS 40
    ENDIF
    #10035 quote
    Nicolas
    Keymaster
    Master

    Thanks for the code. I spotted some kind of “mistakes”, but don’t take it bad.

    1/ HOCH1 and HOCH2 are the same variable (they return the same value).

    2/ You can’t buy at a stop level of HOCH because it is the actual highest high and it’s currently moving if the price goes up. You should refer to HOCH[1] instead.

    3/ As I told you already in my previous post, you need to set up your stop order at each bar because IG delete pending order at each new bar (because of no expiration possible). So when you place your pending orders into a conditional statement like you made from line 28 to 30, your order only last 1 bar (because your condition ichi[1] only occurred one time) which maybe not sufficient for them to trigger.

    4/ Replace lines 32 to 35 with the code snippet I gave you.

    #10037 quote
    lebloe
    Participant
    Junior

    both solutions did not work.

    whatever market entrance i try, direct trade openings with on market nor on stop buy orders.

    #10041 quote
    lebloe
    Participant
    Junior
    1. yes they are the same, in my system a add somme different pips to it
    2. in Realtime trading it works, hmm, i will try hoch[1]
    3. in Realtime trading i put this one in a if Statement with some filters, and the system open on every new bar a new stop buy orde
    #10370 quote
    James B Eddon
    Participant
    New

    Hello Guy I’m looking for a similar code which is: after 3 bars from market open / set stop at market entry . If you can give me any help thanks James.

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

set profit or stop loss after 3 bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
lebloe @lebloe Participant
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by James B Eddon
9 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/29/2016
Status: Active
Attachments: No files
Logo Logo
Loading...