Break of Opening 5 min bar

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #14679 quote
    Dymjohn
    Participant
    Senior

    Hi Nicolas

    I’ve written a strategy to take the break of the first 5 minute candle on the DAX with a couple of other criteria. It is very similar to something already in the database.
    I’m happy to share on the database but not sure if it will add anything.
    I am trading live and although testing works well with good profits in live it sometimes falls over because I’ve specified a “BuyPrice” or “SellPrice” of zero.
    If I change these prices to day 10 it will not work properly and takes trades at other times. I want it to always use the 5 minute candle that starts at 8:00 UK time. Note also that entry should be 2 points above or below the opening candle as this is not working properly either.
    The code is as follows so if you can help can you give me a price please to complete the work if necessary.
    //-------------------------------------------------------------------------
    // Main code : JAP Breakout 5 min open
    //-------------------------------------------------------------------------
    // JAP Breakout 5min
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    DEFPARAM FLATAFTER = 162000
    DEFPARAM PRELOADBARS = 500
    LastEntryTime = 083000
    //market analysis starts at the 5 min. candle which closes at 8:00
    StartTime = 080000
    //ignore saturday and Sunday trading TD=Trading Day
    if DayOfWeek = 6 OR DayOfWeek = 7 THEN
    TD = 0
    else
    TD = 1
    endif
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    endif
    // Money Management
    Capital = 4000
    Risk = 0.03
    StopLoss = 45 // VARY TO DETERMINE RISK
    //Calculate contracts
    equity = Capital + StrategyProfit
    maxrisk = round(equity*Risk)
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    if PositionSize >= 10 Then
    PositionSize = 10
    endif
    // variables set t personal preferences
    OrderDistance = 2
    //initialize variable once at beginning of trading system
    ONCE StartTradingDay = -1
    //The variables which can change during the day are initialized
    //at the beginning of each new trading day
    If (Time <= StartTime AND StartTradingDay <> 0) OR IntradayBarIndex = 0 THEN
    BuyPrice = 0
    SellPrice = 0
    StartTradingDay = 0
    ELSIF Time >= StartTime AND StartTradingDay = 0 AND TD = 1 THEN
    //We store the index of the first bar of the trading day
    IndexStartDay = IntradayBarIndex
    StartTradingDay = 1
    ELSIF StartTradingDay = 1 and Time <= LastEntryTime THEN
    IF BuyPrice = 0 OR SellPrice = 0 THEN
    UpperLevel = Highest[IntradayBarIndex - IndexStartDay +1] (High)
    LowerLevel = Lowest [IntradayBarIndex - IndexStartDay +1] (Low)
    endif
    BuyPrice = UpperLevel + OrderDistance*PointSize
    SellPrice = LowerLevel - OrderDistance*Pointsize
    endif
    //Long position
    indicator3 = Average[100](close)
    c3= (close > indicator3)
    IF Time <= LastEntryTime AND c3 THEN
    BUY PositionSize CONTRACTS AT BuyPrice STOP
     
    ENDIF
     
    // Conditions to enter short positions
    indicator4 = Average[100](close)
    c4 = (close < indicator4)
    indicator7 = DClose(1)
    indicator8 = SellPrice
    c7 = (indicator7 < indicator8)
    indicator6 = (high-low)
    c6 = (indicator6 < 42)
    IF Time <= LastEntryTime AND c6 AND c4 AND C7  THEN
    SELLSHORT PositionSize CONTRACTS AT SellPrice STOP
    ENDIF
     
    //trailing stop
    trailingstop = 45
    //case SHORT order
    trailshort = 40
     
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,Low) //saving the MFE of the current trade
    if tradeprice(1)-MINPRICE> 0 then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailshort*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    if tradeprice(1)-MINPRICE<= 0 then
    priceexit = tradeprice(1)+trailshort*pointsize
    endif
    endif
     
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,High) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>= 0 then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    if MAXPRICE-tradeprice(1)<= 0 then
    priceexit = tradeprice-trailingstop*pointsize// ensures trailing stop is in place mJAP improvement
    endif
    endif
     
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
     
    SELL AT priceexit STOP
    endif

     

    Best regards
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Break of Opening 5 min bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Dymjohn @dymjohn Participant
Summary

This topic contains 1 voice and has 0 replies.

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