Fractal-based Support/Resistance RSI Strategy

Strategies are published here.

Moderator: admin

Fractal-based Support/Resistance RSI Strategy

Postby Apprentice » Thu Nov 04, 2010 1:01 pm

FBSR_STRATEGY.png


1: If Candle closes above FB resistance, open long postition.
2: If Candle closes below FB support, open short position.

I RSI filter is On.

Central line Filter
1: Only enter buy/long if RSI(8) > 50
2: Only enter sell/short if RSI(8) < 50
Overbought/Oversold Filter
1: Only enter buy/long if RSI(8) > 60
2: Only enter sell/short if RSI(8) < 40

FBSR_STRATEGY.lua
(11.87 KiB) Downloaded 2167 times



Fractal-based Support/Resistance Lines Indicator can be found here http://fxcodebase.com/code/viewtopic.php?f=17&t=367&p=606&hilit=FBSR#p606
You must have it installed, strategy to work properly.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Fractal-based Support/Resistance RSI Strategy

Postby baumann » Thu Nov 04, 2010 1:53 pm

Thank you very much for the very quick response. I will test and give feedback.

So far I see a lot of false signals. Close of candle not past R or S yet.

I will make a list and give example of what I find as soon as I can.

Still thank you very much!!!
baumann
 
Posts: 17
Joined: Thu Nov 04, 2010 4:38 am

Re: Fractal-based Support/Resistance RSI Strategy

Postby Apprentice » Thu Nov 04, 2010 3:22 pm

Use Close option, under the Price simulation, this should filter out all false signals.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Fractal-based Support/Resistance RSI Strategy

Postby baumann » Thu Nov 04, 2010 4:04 pm

I will test it on live market and give feedback. Thank you.
baumann
 
Posts: 17
Joined: Thu Nov 04, 2010 4:38 am

Re: Fractal-based Support/Resistance RSI Strategy

Postby baumann » Fri Nov 05, 2010 9:00 am

The startegy behaves just as I wanted.

RSI does not seem to be a good filter when the market is ranging small.

I will Experiment with other indicators (Maybe ATR and/or CCI)

I will post my findings later next week.

Thanks to Apprentice for a job well done!
baumann
 
Posts: 17
Joined: Thu Nov 04, 2010 4:38 am

Re: Fractal-based Support/Resistance RSI Strategy

Postby baumann » Sun Nov 07, 2010 12:52 pm

OK, Ive been doing some backtesting.

I added oversold and overbought settings and it performs much better now.

Here is the code:
Code: Select all
-- Version Oct 14, 2010

function Init()
    strategy:name("FBSR Strategy");
    strategy:description("FBSR Strategy");
 
   strategy.parameters:addGroup("RSI Parameters");
   strategy.parameters:addInteger("Frame", "RSI Period", "", 8, 2, 1000);
   strategy.parameters:addInteger("OVRB", "Overbought level", "", 60, 2, 100);
   strategy.parameters:addInteger("OVRS", "Oversold level", "", 40, 2, 100);
 
   
    strategy.parameters:addInteger("PIN" , "RSI Price Type", "", 4);
    strategy.parameters:addIntegerAlternative("PIN" , "Open", "", 1);
    strategy.parameters:addIntegerAlternative("PIN", "High", "", 2);
    strategy.parameters:addIntegerAlternative("PIN" , "Low", "", 3);
   strategy.parameters:addIntegerAlternative("PIN" , "Close", "", 4);
   strategy.parameters:addIntegerAlternative("PIN", "Median", "", 5);
    strategy.parameters:addIntegerAlternative("PIN" , "Typical", "", 6);
   strategy.parameters:addIntegerAlternative("PIN" , "Weighted ", "", 7);      
 
   strategy.parameters:addGroup("Strategy Time Frame");
   strategy.parameters:addString("TF", "Time Frame", "", "m15");
    strategy.parameters:setFlag("TF", core.FLAG_PERIODS);

    strategy.parameters:addGroup("Trading Parameters");
   strategy.parameters:addBoolean("Test", "Use RSI Confirmation", "", true);   
    strategy.parameters:addBoolean("AllowTrade", "Allow strategy to trade", "", false);
    strategy.parameters:addString("Account", "Account to trade on", "", "");
    strategy.parameters:setFlag("Account", core.FLAG_ACCOUNT);
    strategy.parameters:addInteger("Amount", "Trade Amount in Lots", "", 1, 1, 100);
    strategy.parameters:addBoolean("SetLimit", "Set Limit Orders", "", false);
    strategy.parameters:addInteger("Limit", "Limit Order in pips", "", 30, 1, 10000);
    strategy.parameters:addBoolean("SetStop", "Set Stop Orders", "", false);
    strategy.parameters:addInteger("Stop", "Stop Order in pips", "", 30, 1, 10000);
    strategy.parameters:addBoolean("TrailingStop", "Trailing stop order", "", false);

    strategy.parameters:addGroup("Alert Parameters");
    strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", true);
    strategy.parameters:addBoolean("PlaySound", "Play Sound", "", false);
    strategy.parameters:addFile("SoundFile", "Sound File", "", "");
    strategy.parameters:setFlag("SoundFile", core.FLAG_SOUND);
    strategy.parameters:addBoolean("RecurrentSound", "Recurrent Sound", "", false);

    strategy.parameters:addGroup("Email Parameters");
    strategy.parameters:addBoolean("SendEmail", "Send email", "", false);
    strategy.parameters:addString("Email", "Email address", "", "");
    strategy.parameters:setFlag("Email", core.FLAG_EMAIL);
end

local Email;

local ShowAlert;
local SoundFile;
local RecurrentSound;

local AllowTrade;
local Offer;
local CanClose;
local Account;
local Amount;
local SetLimit;
local Limit;
local SetStop;
local Stop;

local barsource = nil;
local name;
local  Allow;
local PRICE;
local PIN;
local Frame;
local RSI;
local OVRB;
local OVRS;
local FBSR;
--local EXIT;
local Test;

function Prepare(onlyName)

    assert(core.indicators:findIndicator("FBSR") ~= nil, "Please download and install  FBSR Indicator!");
   Test = instance.parameters.Test;
    OVRB = instance.parameters.OVRB;
    OVRS = instance.parameters.OVRS;
    Frame = instance.parameters.Frame;
    PIN = instance.parameters.PIN;
    Allow = instance.parameters.Allow;

    --EXIT = instance.parameters.EXIT;   
     
    local SendEmail = instance.parameters.SendEmail;
    if SendEmail then
        Email = instance.parameters.Email;
    else
        Email = nil;
    end
    assert(not(SendEmail) or (SendEmail and Email ~= ""), "Email address must be specified");

    assert(instance.parameters.TF ~= "t1", "The time frame must not be tick");
    assert(not(instance.parameters.PlaySound) or (instance.parameters.PlaySound and instance.parameters.SoundFile ~= ""), "Sound file must be chosen");
       
    name = profile:id() .. "(" .. "FBSR(" .. instance.bid:name() .. "." .. instance.parameters.TF .. ", "..instance.parameters.Frame .. ")";
      
    ShowAlert = instance.parameters.ShowAlert;
    if instance.parameters.PlaySound then
        SoundFile = instance.parameters.SoundFile;
        RecurrentSound = instance.parameters.RecurrentSound;
    else
        SoundFile = nil;
        RecurrentSound = false;
    end

    AllowTrade = instance.parameters.AllowTrade;

    if AllowTrade then
        Account = instance.parameters.Account;
        Amount = instance.parameters.Amount * core.host:execute("getTradingProperty", "baseUnitSize", instance.bid:instrument(), Account);
        Offer = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;
        CanClose = core.host:execute("getTradingProperty", "canCreateMarketClose", instance.bid:instrument(), Account);
        SetLimit = instance.parameters.SetLimit;
        Limit = instance.parameters.Limit * instance.bid:pipSize();
        SetStop = instance.parameters.SetStop;
        Stop = instance.parameters.Stop * instance.bid:pipSize();
        TrailingStop = instance.parameters.TrailingStop;
     
        name = name .. ", trade) ";
    else
        name = name .. ", signal) ";
    end

    instance:name(name);

    if onlyName then
        return ;
    end

    barsource = ExtSubscribe(1, nil, instance.parameters.TF, true, "bar");
   
       if PIN == 1 then
      PRICE = barsource.open;      
      elseif PIN==2 then
      PRICE = barsource.high;   
      elseif PIN==3 then
      PRICE = barsource.low;   
      elseif PIN==4 then
      PRICE = barsource.close;   
      elseif PIN==5 then
      PRICE = barsource.median;   
      elseif PIN==6 then
      PRICE = barsource.typical;   
      elseif PIN==7 then
      PRICE = barsource.weighted;   
      end
      
       RSI=core.indicators:create("RSI", PRICE, Frame);   
        FBSR=core.indicators:create("FBSR", barsource);

end

function ExtUpdate(id, source, period)
   
   if id == 1 and period > 1 then
   
       RSI:update(core.UpdateLast);
      if  not RSI.DATA:hasData(period) or not RSI.DATA:hasData(period-1) then
        return;
        end    
         
      FBSR:update(core.UpdateLast);
      if  not FBSR.R:hasData(period) and  not FBSR.S:hasData(period) then
        return;
        end
      if  not FBSR.R:hasData(period-1) and  not FBSR.S:hasData(period-1) then
        return;
        end       
      
      if   FBSR.R[period] ~= FBSR.R[period-1] then
        return;
        end
      if  FBSR.S[period] ~= FBSR.S[period-1] then
        return;
        end
      
      if Test then
              if  core.crossesOver(barsource.close, FBSR.R,   period) and RSI.DATA[period] > OVRB then
            TRADE ("Long");
            elseif  core.crossesUnder(barsource.close, FBSR.S,   period) and RSI.DATA[period] < OVRS then
            TRADE ("Short");          
            end
            
            if EXIT then
            end
      else
            if  core.crossesOver(barsource.close, FBSR.R,   period) then
            TRADE ("Long");
            elseif  core.crossesUnder(barsource.close, FBSR.S,   period) then
            TRADE ("Short");
            end
      end
          
   end       
end

local NOTE;

function TRADE (SIDE)

            if SIDE == "Long" then
         NOTE ="Enter " ..  SIDE .. " Position";
         elseif SIDE == "Short" then
         NOTE ="Enter " ..  SIDE .. " Position";
         elseif SIDE == "Close" then
         NOTE ="Close All Position";
         end
         
            if ShowAlert then
                terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], NOTE, instance.bid:date(NOW));
            end

            if SoundFile ~= nil then
                terminal:alertSound(SoundFile, RecurrentSound);
            end

            if Email ~= nil then
                terminal:alertEmail(Email, NOTE , name .." " .. NOTE)
            end
         
            if SIDE == "Long" then
            exit("S");
            enter("B") ;
         elseif   SIDE == "Short" then
         exit("B");
            enter("S");
         elseif SIDE == "Close" and EXIT then         
         exit("B");
         exit("S");
         end
   
end

-- enter into the specified direction
function enter(BuySell)
    if not(AllowTrade) then
        return ;
    end

    local enum, row, valuemap, success, msg;

    -- check whether we have at least one trade on the specified account
    -- in the specified direction for the specified instrument
    local count = 0;
    enum = core.host:findTable("trades"):enumerator();
    row = enum:next();
    while count == 0 and row ~= nil do
        if row.AccountID == Account and
           row.OfferID == Offer and
           row.BS == BuySell then
           count = count + 1;
        end
        row = enum:next();
    end

    -- do not enter if position in the
    -- specified direction already exists
    if count > 0 then
        return ;
    end


    local valuemap, success, msg;
    valuemap = core.valuemap();

    valuemap.OrderType = "OM";
    valuemap.OfferID = Offer;
    valuemap.AcctID = Account;
    valuemap.Quantity = Amount;
    valuemap.BuySell = BuySell;
    valuemap.PegTypeStop = "M";

    if SetLimit then
        -- set limit order
        if BuySell == "B" then
            valuemap.RateLimit = instance.ask[NOW] + Limit;
        else
            valuemap.RateLimit = instance.bid[NOW] - Limit;
        end
    end

    if SetStop then
        -- set limit order
        if BuySell == "B" then
            valuemap.RateStop = instance.ask[NOW] - Stop;
        else
            valuemap.RateStop = instance.bid[NOW] + Stop;
        end
        if TrailingStop then
            valuemap.TrailStepStop = 1;
        end
    end

    success, msg = terminal:execute(100, valuemap);

    if not(success) then
        terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Open order failed" .. msg, instance.bid:date(instance.bid:size() - 1));
    end
end

-- exit from the specified direction
function exit(BuySell)
    if not(AllowTrade) then
        return ;
    end

    local enum, row, valuemap, success, msg;

    -- check whether we have at least one trade on the specified account
    -- in the specified direction for the specified instrument
    local count = 0;
    enum = core.host:findTable("trades"):enumerator();
    row = enum:next();
    while count == 0 and row ~= nil do
        if row.AccountID == Account and
           row.OfferID == Offer and
           row.BS == BuySell then
           count = count + 1;
        end
        row = enum:next();
    end

    if count > 0 then
        valuemap = core.valuemap();

        -- switch the direction since the order must be in oppsite direction
        if BuySell == "B" then
            BuySell = "S";
        else
            BuySell = "B";
        end
        valuemap.OrderType = "CM";
        valuemap.OfferID = Offer;
        valuemap.AcctID = Account;
        valuemap.NetQtyFlag = "Y";
        valuemap.BuySell = BuySell;
        success, msg = terminal:execute(101, valuemap);

        if not(success) then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Close order failed" .. msg, instance.bid:date(instance.bid:size() - 1));
        end
    end
end


dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");



Apprentice - can you look at the code and see if it's sufficient and update the uploaded file?

Thank you very much.

I will test it live this week. (Only on EURUSD)
baumann
 
Posts: 17
Joined: Thu Nov 04, 2010 4:38 am

Re: Fractal-based Support/Resistance RSI Strategy

Postby Apprentice » Sun Nov 07, 2010 3:50 pm

Looks good.
I'm lazy by nature, So I added one more option,
i can have the best of both worlds now.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Fractal-based Support/Resistance RSI Strategy

Postby automan » Thu Mar 17, 2011 9:19 am

Hi

1: If Candle closes above FB resistance, open long postition.
2: If Candle closes below FB support, open short position.

Is it possible to change the code so that it opens the trade one tick above/below instead of waiting for the close?

I have been looking at the code but i cant figure it out
automan
 
Posts: 19
Joined: Wed Mar 09, 2011 1:32 pm

Re: Fractal-based Support/Resistance RSI Strategy

Postby fabfxcm » Fri Mar 18, 2011 2:57 am

If i load FBSDR on strategy the strategy run, but when I try to back test of FBSR strategy doesn't work and appear the following message: string FBSR_strategy.lua: 121 unsupported.
What does it mean? What can I do?
fabfxcm
 
Posts: 23
Joined: Mon Jan 17, 2011 5:50 am

Re: Fractal-based Support/Resistance RSI Strategy

Postby R3boot » Fri Mar 18, 2011 12:15 pm

just GREAT


i have been testing it. i think so far it needs more dev.

and we can do that be testing it and discuses our results



so far i think we need an option to make a limit and stop for every trade that is going to open


what do u think guys ?
R3boot
 
Posts: 19
Joined: Thu Mar 17, 2011 10:36 pm

Next

Return to Custom Strategies

Who is online

Users browsing this forum: No registered users and 11 guests