Trade FOREX with FXCM

  • Award-Winning Platform
  • 24/7 Customer Support
  • Trade Directly on Charts
  • Free $50K Practice Account
Register


Results 1 to 5 of 5

Thread: Early bird Breakout System

  1. #1
    MFX630 is offline Member
    Join Date
    Dec 2006
    Posts
    10

    Cool Early bird Breakout System

    i came across this and was wondering if anyone can code this for the marketscope and allow real trades
    Trading setup:

    Time frame: 1 hour.
    Currency pair: preferred but not limited to EUR/USD and GBP/USD.
    This Forex breakout system uses no indicators.
    Trading rules:
    The system is called "early bird" because it requires a trader being ready to trade Forex as early as 5:00 am EST.Find the Highest High and the Lowest Low for the candles from 00:00 EST to 4:59 am EST. (We should have 5 candles for each hour: 0, 1, 2, 3 and 4).
    At 5:00 am EST set 2 entry orders: buy order - above the highest high +5 pips, sell order - below the lowest low and -5 pips.Set initial profit target to +90 pips for EUR/USD and +140 pips for GBP/USD - both targets are way too high if to consider that daily range average for EUR/USD is only 110-120 pips and daily range average for GBP/USD is 180-200 pips.
    If those targets get hit - very good!However, our profits will be determined mainly by the time factor instead of a fixed amount of pips.So, we close all open positions at 12:59 EST (1:00 pm EST) and cancel all remaining orders. The next trading opportunity - only next day at 5:00 am EST.

  2. #2
    Nikolay.Gekht is offline Moderator
    Join Date
    Oct 2008
    Posts
    1,023
    The interesting system. I'll implement it and try to run it on new beta backtester. I'll be back with the results soon.

  3. #3
    Nikolay.Gekht is offline Moderator
    Join Date
    Oct 2008
    Posts
    1,023
    I wrote the first version for further testing. The limitation:
    1) the system works on non-FIFO accounts only
    2) the system does not care about restart/relogins and so on.

    The lua file is attached and the code of the strategy is below:
    Code:
    function Init()
        strategy:name("Early Bird Breakout System");
        strategy:description("");
    
        strategy.parameters:addInteger("MM", "Number of hours to find HH and LL", "", 5, 1, 24);
        strategy.parameters:addInteger("EntryHour", "Hour of entry (EST 24-hour)", "", 5, 0, 23);
        strategy.parameters:addInteger("ExitHour", "Hour of exit (EST, 24-hour)", "", 13, 0, 23);
        strategy.parameters:addInteger("ProfitTarget", "Profit Target (in pips)", "", 90, 0, 10000);
    
        strategy.parameters:addString("AccountID", "AccountID to trade on", "", "");
        strategy.parameters:setFlag("AccountID", core.FLAG_ACCOUNT);
        strategy.parameters:addInteger("Amount", "Trade Amount in Lots", "", 1, 1, 1000);
    end
    
    local MM, EntryHour, ExitHour;
    local BidH1, AskH1;
    local ProfitTarget;
    local AccountID;
    local Amount;
    local OfferID;
    local LotSize;
    local CustomID;
    local bidLoaded, askLoaded;
    local S;
    
    function Prepare(onlyName)
    
        instance:name(profile:id() .. "(" .. instance.bid:instrument() .. ")");
        if onlyName then
            return ;
        end
    
        CustomID = "EBBS_" .. instance.bid:instrument();
    
        MM = instance.parameters.MM;
        EntryHour = instance.parameters.EntryHour;
        ExitHour = instance.parameters.ExitHour;
        ProfitTarget = instance.parameters.ProfitTarget;
    
        AccountID = instance.parameters.AccountID;
        Amount = instance.parameters.Amount;
        LotSize = core.host:execute("getTradingProperty", "baseUnitSize", instance.bid:instrument(), AccountID);
        OfferID = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;
    
        bidLoaded = false;
        askLoaded = false;
    
        BidH1 = core.host:execute("getHistory", 1, instance.bid:instrument(), "H1", 0, 0, true);
        AskH1 = core.host:execute("getHistory", 2, instance.bid:instrument(), "H1", 0, 0, false);
        S = CheckTime();
    end
    
    function Update()
        local S1;
        S1 = CheckTime();
        if bidLoaded and askLoaded then
            if not S and S1 then
                -- entry time
                Entry();
            end
            if S and not S1 then
                -- exit time
                Exit();
            end
        end
        S = S1;
    end
    
    function AsyncOperationFinished(cookie, success, message)
        if cookie == 1 then
            bidLoaded = true;
            return ;
        end
    
        if cookie == 2 then
            askLoaded = true;
            return ;
        end
    
        if cookie == 100 and not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Creating entry order failed:" .. message, instance.bid:date(instance.bid:size() - 1));
        end
    
        if cookie == 101 and not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Closing trade failed:" .. message, instance.bid:date(instance.bid:size() - 1));
        end
    
        if cookie == 102 and not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Cancelling order failed:" .. message, instance.bid:date(instance.bid:size() - 1));
        end
    end
    
    function Entry()
        terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Entry", instance.bid:date(instance.bid:size() - 1));
    
        local maxAsk, minBid;
    
        maxAsk = mathex.max(AskH1.high, AskH1:size() - MM + 1, AskH1:size() - 1);
        minBid = mathex.min(BidH1.low, BidH1:size() - MM + 1, BidH1:size() - 1);
    
        CreateEntry(maxAsk + AskH1:pipSize() * 5, "B");
        CreateEntry(minBid - BidH1:pipSize() * 5, "S");
    end
    
    function CreateEntry(rate, side)
        local valuemap = core.valuemap();
    
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "SE";
        valuemap.OfferID = OfferID;
        valuemap.AcctID = AccountID;
        valuemap.Quantity = Amount * LotSize;
        valuemap.Rate = rate;
        valuemap.BuySell = side;
        valuemap.CustomID = CustomID;
        if side == "B" then
            valuemap.PegPriceOffsetPipsLimit = ProfitTarget;
        else
            valuemap.PegPriceOffsetPipsLimit = -ProfitTarget;
        end
        valuemap.PegTypeLimit = "M";
    
        success, message = terminal:execute(100, valuemap);
        if not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Creating entry order failed:" .. message, instance.bid:date(instance.bid:size() - 1));
        end
    end
    
    function Exit()
        terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Exit", instance.bid:date(instance.bid:size() - 1));
        -- close all positions
        local arr1 = {};
        local arr2 = {};
        local arr3 = {};
        local cnt = 0;
    
        local enum, row;
        local found = false;
        enum = core.host:findTable("trades"):enumerator();
        row = enum:next();
        while row ~= nil do
            if row.AccountID == AccountID and
               row.OfferID == OfferID and
               row.QTXT == CustomID then
               cnt = cnt + 1;
               arr1[cnt] = row.TradeID;
               arr2[cnt] = row.Lot;
               arr3[cnt] = row.BS;
            end
            row = enum:next();
        end
    
        if cnt > 0 then
            for i = 1, cnt, 1 do
                CloseTrade(arr1[i], arr2[i], arr3[i]);
            end
        end
    
        cnt = 0;
        enum = core.host:findTable("orders"):enumerator();
        row = enum:next();
        while row ~= nil do
            if row.AccountID == AccountID and
               row.Type == "SE" and
               row.OfferID == OfferID and
               row.QTXT == CustomID then
               cnt = cnt + 1;
               arr1[cnt] = row.OrderID;
            end
            row = enum:next();
        end
    
        if cnt > 0 then
            for i = 1, cnt, 1 do
                CancelOrder(arr1[i]);
            end
        end
    end
    
    function CloseTrade(TradeID, Amount, Side)
        local valuemap = core.valuemap();
    
        if Side == "B" then
            Side = "S";
        else
            Side = "B";
        end
    
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "CM";
        valuemap.OfferID = OfferID;
        valuemap.AcctID = AccountID;
        valuemap.Quantity = Amount
        valuemap.BuySell = Side;
        valuemap.TradeID = TradeID;
    
        success, message = terminal:execute(101, valuemap);
        if not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Closing trade failed:" .. message, instance.bid:date(instance.bid:size() - 1));
        end
    end
    
    function CancelOrder(OrderID)
        local valuemap = core.valuemap();
        valuemap.Command = "DeleteOrder";
        valuemap.OfferID = OfferID;
        valuemap.AcctID = AccountID;
        valuemap.OrderID = OrderID;
    
        success, message = terminal:execute(102, valuemap);
        if not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Cancelling order failed:" .. message, instance.bid:date(instance.bid:size() - 1));
        end
    
    end
    
    function CheckTime()
        local st = core.host:execute("getServerTime");
        local h = math.floor((st - math.floor(st)) * 24);
        if h < EntryHour then
            return false;
        elseif h < ExitHour then
            return true;
        else
            return false;
        end
    end
    Attached Files Attached Files

  4. #4
    Nikolay.Gekht is offline Moderator
    Join Date
    Oct 2008
    Posts
    1,023
    I run this version over the whole 2010 EUR/USD history (~3M ticks simulated, 1-minute source history data), mini non-FIFO account w/o hedging, in beta of the next TS release. The strategy looks promising, at least it does not loss a lot:

    Please see equity curve and statistics attached:
    Attached Thumbnails Attached Thumbnails Early bird Breakout System-backtest.jpg  

    Early bird Breakout System-stat.jpg  

    Last edited by Nikolay.Gekht; 08-24-2011 at 02:51 PM.

  5. #5
    Nikolay.Gekht is offline Moderator
    Join Date
    Oct 2008
    Posts
    1,023
    I also run the strategy trough optimizer, it looks like 13:00 EST is too early to forced exit. Please see the optimization result graph per entry/exit hour and the result of the testing of the most successful result:
    Attached Thumbnails Attached Thumbnails Early bird Breakout System-opt.jpg  

    Early bird Breakout System-backtest1.jpg  


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.