Help identifying a mistake in this simple Forex breakout code

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38990 quote
    Juan Salas
    Participant
    Master

    Hi Colleagues,

    I am posting this strategy well known by most of you, but with some slight modifications. I would APPRECIATTE if someone could identify what is wrong.

    It seems to work but I cannot get all the conditions right in the backtest. I am new with programming, and I am frustrated with this system because I cannot get one operation everyday, or when I get it, the system is launching the orders at the same time everyday, etc.

    The system is a simple morning breakout for EUR-USD (TF: 15 min).

    1.Starts at 08:00h and collect the highest and lowest from the last 12 candlesticks (from 05:00 to 08:00h).

    2. After 08:00h, when the price breaks the highest of the channel + 3 pips, or the lowest of the channel– 3 pips, buy long or sell short (in the same candle, not at the opening of the next candle).

    3. Stops and Target Profits finish the trading.

    4. Only operates once a day, regardless if the trade was positive or negative.

    5. The system will shut down at 14:00h. Any open trade will be close at that time.

    6. I have included a NON OPERATING condition, in case the range of the channel of the 12 candlesticks is bigger than 32 pips.

    Although it seems very basic and the equity curve is not very attractive right now, I like the fact that I can control the operations once a day and limit and daily monitoring the results. It is a matter of adding other currencies everyday, and creating different schedules for US and Asian markets (i.e.- I could have 5 currencies from 0800 to 1400, 5 from 1500 to 2200, and other five overnight for Asian market). It is just a matter, once it works, to change the time in the code).

    Thanks so much in advance,

    Juan

    // FOREX BREAKOUT
    // 15 MIN
    // One trade per day, from 08:00h to 14:00. The system shuts-down at 14:00h
    // Everyday Channel formation from 0500 to 0800 (Highest-Lowest)
    // Maximum Range 32pips
    
    DEFPARAM CUMULATEORDERS = false
    
    // OPERATIONAL TIME
    DEFPARAM FLATBEFORE = 080000
    DEFPARAM FLATAFTER = 140000
    Operationaltime = TIME > 080000 AND TIME < 140000
    
    // ONE TRADE PER DAY. It resets the variable each new day
    IF INTRADAYBARINDEX = 0 THEN
    alreadytraded = 0
    ENDIF
    
    // RANGE between 0500h to 0800h
    IF TIME=080000 THEN
    channelhigh = Highest[12](high)
    channellow = Lowest[12](low)
    ENDIF
    
    // NO ACTIVITY if the range (highest-lowest)is >= 32 pips
    IF channelhigh-channellow>=32*pipsize THEN
    tradeok=0
    ELSE
    tradeok=1
    ENDIF
    
    // LONG Positions-Opening
    IF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THEN
    BUY 1 CONTRACT AT channelhigh + 3*pipsize STOP
    tradeok = 0
    alreadytraded = 1
    ENDIF
    
    // SHORT Positions-Opening
    IF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THEN
    SELLSHORT 1 CONTRACT AT channellow - 3*pipsize STOP
    tradeok = 0
    alreadytraded = 1
    ENDIF
    
    // STOP & PROFIT
    SET STOP LOSS 8*pipsize
    SET TARGET PROFIT 12*pipsize
    
    
    
     
    
    
    
    
    
     
    
     
    
    #38995 quote
    Nicolas
    Keymaster
    Master

    Your pending stop orders will only last 1 single bar in your code. Pending orders must be set each bar, because they only last 1 candlestick. In order to let the system put the STOP Orders continuously at each new bar until one of them triggered you should try this modified code instead:

    // FOREX BREAKOUT
    // 15 MIN
    // One trade per day, from 08:00h to 14:00. The system shuts-down at 14:00h
    // Everyday Channel formation from 0500 to 0800 (Highest-Lowest)
    // Maximum Range 32pips
    
    DEFPARAM CUMULATEORDERS = false
    
    // OPERATIONAL TIME
    DEFPARAM FLATBEFORE = 080000
    DEFPARAM FLATAFTER = 140000
    Operationaltime = TIME > 080000 AND TIME < 140000
    
    // ONE TRADE PER DAY. It resets the variable each new day
    IF INTRADAYBARINDEX = 0 THEN
    alreadytraded = 0
    ENDIF
    
    // RANGE between 0500h to 0800h
    IF TIME=080000 THEN
    channelhigh = Highest[12](high)
    channellow = Lowest[12](low)
    ENDIF
    
    // NO ACTIVITY if the range (highest-lowest)is >= 32 pips
    IF channelhigh-channellow>=32*pipsize THEN
    tradeok=0
    ELSE
    tradeok=1
    ENDIF
    
    // LONG Positions-Opening
    IF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THEN
    BUY 1 CONTRACT AT channelhigh + 3*pipsize STOP
    ENDIF
    
    // SHORT Positions-Opening
    IF Operationaltime AND tradeok = 1 AND alreadytraded = 0 THEN
    SELLSHORT 1 CONTRACT AT channellow - 3*pipsize STOP
    ENDIF
    
    //test if an order is on market 
    if onmarket then 
    tradeok = 0
    alreadytraded = 1
    endif 
    
    // STOP & PROFIT
    SET STOP LOSS 8*pipsize
    SET TARGET PROFIT 12*pipsize

    This is a rough and quick Sunday afternoon fix, not tested 😉

    #38997 quote
    Juan Salas
    Participant
    Master

    Hi Nicolas,

    Thanks so much for your prompt response, especially on Sunday. You are super reliable for everyone here.

    I will test it myself 😉

    Have a great day,

    Juan

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

Help identifying a mistake in this simple Forex breakout code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Juan Salas @juan-salas Participant
Summary

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

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