Multiple strategy at the same time: doesnt'works?

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Multiple strategy at the same time: doesnt'works?

Postby pinimo » Tue Oct 07, 2014 12:32 pm

Hi to all, Currently I have several strategies running at the same time on differnt pairs.
For example RLW strategy on EUR/USD + FIBO CANDLES Strategy on USD-JPY.
I noticed that the signals on euro dollar are successful and open positions, but the other strategy does not trigger any signal ever.

I did a backtest and signals must be generated...why the second strategy does not generate signals?

What can I do to solve this problem?


Any suggestion will be appreciated ;)
pinimo
 
Posts: 17
Joined: Mon Jul 21, 2014 2:41 am
Location: http://www.marketmovers.it/

Re: Multiple strategy at the same time: doesnt'works?

Postby Apprentice » Thu Oct 09, 2014 2:25 am

I have test both of them, they work as expected in Backtesting at least.
Have you set "Allow strategy to trade" parameter to Yes?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Multiple strategy at the same time: doesnt'works?

Postby pinimo » Thu Oct 09, 2014 6:55 am

Yes, all strategies are set to trade.
Now I have these active strategies:
RLW Eur/USD
BREAKEVENALL EUR/USD
RLW usd/chf
BREAKEVENALL usd/chf
RLW Eur/jpy
BREAKEVENALL EUR/jpy
FIBO USD/JPY
FIBO EUR/AUD

all strategies work , unless of fibo.
could be due to some conflict with other strategies ?
pinimo
 
Posts: 17
Joined: Mon Jul 21, 2014 2:41 am
Location: http://www.marketmovers.it/

Re: Multiple strategy at the same time: doesnt'works?

Postby Apprentice » Fri Oct 10, 2014 1:50 am

Untitled.png

Hmm strange, in Backtester everything works as expected.
(With Default Fib Level Parameters)

You are using the default Fib Level parameter?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Multiple strategy at the same time: doesnt'works?

Postby pinimo » Fri Oct 10, 2014 8:01 am

Apprentice thank you for reply ;)
yes, I have set 0.382 level in 1HR timeframe. If I do a backtest the strategy works, but leaving turn strategy into real does not generate signals. For example, last week it did not open any position . If I do a backtest I discover that should have been open.
pinimo
 
Posts: 17
Joined: Mon Jul 21, 2014 2:41 am
Location: http://www.marketmovers.it/

Re: Multiple strategy at the same time: doesnt'works?

Postby p_maltsev » Thu Oct 16, 2014 6:13 am

Hi pinimo,

Unfortunately, Fibo candles strategy is not supposed to work with other strategies. The strategy checks whether there are open positions or not. But it does not check how the position was opened (manually or by a strategy, and by which strategy).
p_maltsev
 

Re: Multiple strategy at the same time: doesnt'works?

Postby pinimo » Fri Oct 17, 2014 9:10 am

oh thank you very much, You gave me a big indication ;) . Do you know how it is possible to modify the code so that does not behave in this way? :?:
pinimo
 
Posts: 17
Joined: Mon Jul 21, 2014 2:41 am
Location: http://www.marketmovers.it/

Re: Multiple strategy at the same time: doesnt'works?

Postby pinimo » Fri Oct 17, 2014 1:47 pm

This is the fibo candles code.

Code: Select all
function Init() --The strategy profile initialization
    strategy:name("Fibo Candles strategy");
    strategy:description("Fibo Candles strategy");

    strategy.parameters:addGroup("Parameters");
    strategy.parameters:addInteger("Period", "Period", "", 10);
    strategy.parameters:addString("FiboLevel", "Fibo level", "Fibo level", "0.236");
    strategy.parameters:addStringAlternative("FiboLevel", "0.236", "", "0.236");
    strategy.parameters:addStringAlternative("FiboLevel", "0.382", "", "0.382");
    strategy.parameters:addStringAlternative("FiboLevel", "0.500", "", "0.500");
    strategy.parameters:addStringAlternative("FiboLevel", "0.618", "", "0.618");
    strategy.parameters:addStringAlternative("FiboLevel", "0.762", "", "0.762");

    strategy.parameters:addGroup("Strategy Parameters");
    strategy.parameters:addString("TypeSignal", "Type of signal", "", "direct");
    strategy.parameters:addStringAlternative("TypeSignal", "direct", "", "direct");
    strategy.parameters:addStringAlternative("TypeSignal", "reverse", "", "reverse");

    strategy.parameters:addGroup("Price Parameters");
    strategy.parameters:addString("TF", "Time Frame", "", "m15");
    strategy.parameters:setFlag("TF", core.FLAG_PERIODS);

    strategy.parameters:addGroup("Trading Parameters");
    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:addString("AllowDirection", "Allow direction for positions", "", "Both");
    strategy.parameters:addStringAlternative("AllowDirection", "Both", "", "Both");
    strategy.parameters:addStringAlternative("AllowDirection", "Long", "", "Long");
    strategy.parameters:addStringAlternative("AllowDirection", "Short", "", "Short");

    strategy.parameters:addGroup("Signal 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("Recurrent", "RecurrentSound", "", 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

-- Signal Parameters
local ShowAlert;
local SoundFile;
local RecurrentSound;
local SendEmail, Email;

-- Internal indicators
local FT = nil;

-- Strategy parameters
local openLevel = 0
local closeLevel = 0
local confirmTrend;

-- Trading parameters
local AllowTrade = nil;
local Account = nil;
local Amount = nil;
local BaseSize = nil;
local PipSize;
local SetLimit = nil;
local Limit = nil;
local SetStop = nil;
local Stop = nil;
local TrailingStop = nil;
local CanClose = nil;
local AllowDirection;

--
--
--
function Prepare()
    ShowAlert = instance.parameters.ShowAlert;
    AllowDirection = instance.parameters.AllowDirection;
    local PlaySound = instance.parameters.PlaySound
    if  PlaySound then
        SoundFile = instance.parameters.SoundFile;
    else
        SoundFile = nil;
    end
    assert(not(PlaySound) or SoundFile ~= "", "Sound file must be chosen");
    RecurrentSound = instance.parameters.Recurrent;

    local SendEmail = instance.parameters.SendEmail;
    if SendEmail then
        Email = instance.parameters.Email;
    else
        Email = nil;
    end
    assert(not(SendEmail) or Email ~= "", "Email address must be specified");
    assert(instance.parameters.TF ~= "t1", "The time frame must not be tick");

    local name;
    name = profile:id() .. "(" .. instance.bid:name() .. "." .. instance.parameters.TF .. "," .. ")";
    instance:name(name);

    AllowTrade = instance.parameters.AllowTrade;
    if AllowTrade then
        Account = instance.parameters.Account;
        Amount = instance.parameters.Amount;
        BaseSize = 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);
        PipSize = instance.bid:pipSize();
        SetLimit = instance.parameters.SetLimit;
        Limit = instance.parameters.Limit;
        SetStop = instance.parameters.SetStop;
        Stop = instance.parameters.Stop;
        TrailingStop = instance.parameters.TrailingStop;
    end

    Source = ExtSubscribe(2, nil, instance.parameters.TF, true, "bar");
    FT = core.indicators:create("FIBO_TRIGGER", Source, instance.parameters.Period, instance.parameters.FiboLevel);

    ExtSetupSignal(profile:id() .. ":", ShowAlert);
    ExtSetupSignalMail(name);
end

function ExtUpdate(id, source, period)  -- The method called every time when a new bid or ask price appears.
    FT:update(core.UpdateLast);

    -- Check that we have enough data
    if (FT.DATA:first() > (period - 1)) then
        return
    end

    local pipSize = instance.bid:pipSize()

    local trades = core.host:findTable("trades");
    local haveTrades = (trades:find('AccountID', Account) ~= nil)
   
    local MustOpenB=false;
    local MustOpenS=false;
   
    if FT.DATA[period]==source.low[period] then
     if instance.parameters.TypeSignal=="direct" then
      MustOpenB=true;
     else
      MustOpenS=true;
     end
    end
   
    if FT.DATA[period]==source.high[period] then
     if instance.parameters.TypeSignal=="direct" then
      MustOpenS=true;
     else
      MustOpenB=true;
     end
    end
   
    if (haveTrades) then
        local enum = trades:enumerator();
        while true do
            local row = enum:next();
            if row == nil then break end

            if row.AccountID == Account and row.OfferID == Offer then
                    -- Close position if we have corresponding closing conditions.
                if row.BS == 'B' then
                  if MustOpenS then
              if ShowAlert then
               if instance.parameters.AllowDirection=="Long" then
                            ExtSignal(source, period, "Close BUY", SoundFile, Email, RecurrentSound);
                         else
             ExtSignal(source, period, "Close BUY and SELL", SoundFile, Email, RecurrentSound);
          end   
             end

              if AllowTrade then
                            Close(row);
                            if instance.parameters.AllowDirection~="Long" then
                             Open("S")
                            end
             end
                  end
                elseif row.BS == 'S' then
                  if MustOpenB then
              if ShowAlert then
               if instance.parameters.AllowDirection=="Short" then
                            ExtSignal(source, period, "Close SELL", SoundFile, Email, RecurrentSound);
                         else
             ExtSignal(source, period, "Close SELL and BUY", SoundFile, Email, RecurrentSound);
          end   
             end

              if AllowTrade then
                            Close(row);
                            if instance.parameters.AllowDirection~="Short" then
                             Open("B")
                            end
             end
                  end
                end

            end
        end
  else
        if MustOpenB==true and instance.parameters.AllowDirection~="Short" then

            if ShowAlert then
                ExtSignal(source, period, "BUY", SoundFile, Email, RecurrentSound)
            end

            if AllowTrade then
                Open("B")
            end
        end

        if MustOpenS==true and instance.parameters.AllowDirection~="Long" then
            if ShowAlert then
               ExtSignal(source, period, "SELL", SoundFile, Email, RecurrentSound)
       end

            if AllowTrade then
                Open("S")
       end
        end
    end
end

-- The strategy instance finalization.
function ReleaseInstance()
end

-- The method enters to the market
function Open(side)
    local valuemap;

    valuemap = core.valuemap();
    valuemap.OrderType = "OM";
    valuemap.OfferID = Offer;
    valuemap.AcctID = Account;
    valuemap.Quantity = Amount * BaseSize;
    valuemap.CustomID = CID;
    valuemap.BuySell = side;
    valuemap.QTXT="1";
    if SetStop and CanClose then
        valuemap.PegTypeStop = "O";
        if side == "B" then
            valuemap.PegPriceOffsetPipsStop = -Stop;
        else
            valuemap.PegPriceOffsetPipsStop = Stop;
        end
        if TrailingStop then
            valuemap.TrailStepStop = 1;
        end;
    end
    if SetLimit and CanClose then
        valuemap.PegTypeLimit = "O";
        if side == "B" then
            valuemap.PegPriceOffsetPipsLimit = Limit;
        else
            valuemap.PegPriceOffsetPipsLimit = -Limit;
        end
    end
    success, msg = terminal:execute(200, valuemap);
    assert(success, msg);

    -- FIFO Account, in that case we have to open Net Limit and Stop Orders
    if not(CanClose) then
        if SetStop then
            valuemap = core.valuemap();
            valuemap.OrderType = "SE"
            valuemap.OfferID = Offer;
            valuemap.AcctID = Account;
            valuemap.NetQtyFlag = 'y';
            if side == "B" then
                valuemap.BuySell = "S";
                rate = instance.ask[NOW] - Stop * PipSize;
                valuemap.Rate = rate;
            elseif side == "S" then
                valuemap.BuySell = "B";
                rate = instance.bid[NOW] + Stop * PipSize;
                valuemap.Rate = rate;
            end
            if TrailingStop then
                valuemap.TrailUpdatePips = 1
            end
            success, msg = terminal:execute(200, valuemap);
            --core.host:trace('Set stop @ ' .. rate);
            assert(success, msg);
        end
        if SetLimit then
            valuemap = core.valuemap();
            valuemap.OrderType = "LE"
            valuemap.OfferID = Offer;
            valuemap.AcctID = Account;
            valuemap.NetQtyFlag = 'y';
            if side == "B" then
                valuemap.BuySell = "S";
                rate = instance.ask[NOW] + Limit * PipSize;
                valuemap.Rate = rate;
            elseif side == "S" then
                valuemap.BuySell = "B";
                rate = instance.bid[NOW] - Limit * PipSize;
                valuemap.Rate = rate;
            end
            success, msg = terminal:execute(200, valuemap);
            --core.host:trace('Set limit @ ' .. rate);
            assert(success, msg);
        end
    end
end

-- Closes specific position
function Close(trade)
    local valuemap;
    valuemap = core.valuemap();

    if CanClose then
        -- non-FIFO account, create a close market order
        valuemap.OrderType = "CM";
        valuemap.TradeID = trade.TradeID;
    else
        -- FIFO account, create an opposite market order
        valuemap.OrderType = "OM";
    end

    valuemap.OfferID = trade.OfferID;
    valuemap.AcctID = trade.AccountID;
    valuemap.Quantity = trade.Lot;
    valuemap.CustomID = trade.QTXT;
    if trade.BS == "B" then valuemap.BuySell = "S"; else valuemap.BuySell = "B"; end
    success, msg = terminal:execute(200, valuemap);
    assert(success, msg);
end

function AsyncOperationFinished(cookie, successful, message)
  if not successful then
    core.host:trace('Error: ' .. message)
  end
end

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



I think I should modify this part of code, but I don't Know what and how exactly:

Code: Select all
   if (haveTrades) then
        local enum = trades:enumerator();
        while true do
            local row = enum:next();
            if row == nil then break end

            if row.AccountID == Account and row.OfferID == Offer then
                    -- Close position if we have corresponding closing conditions.
                if row.BS == 'B' then
                  if MustOpenS then
              if ShowAlert then
               if instance.parameters.AllowDirection=="Long" then
                            ExtSignal(source, period, "Close BUY", SoundFile, Email, RecurrentSound);
                         else
             ExtSignal(source, period, "Close BUY and SELL", SoundFile, Email, RecurrentSound);
          end   
             end

              if AllowTrade then
                            Close(row);
                            if instance.parameters.AllowDirection~="Long" then
                             Open("S")
                            end
             end
                  end
                elseif row.BS == 'S' then
                  if MustOpenB then
              if ShowAlert then
               if instance.parameters.AllowDirection=="Short" then
                            ExtSignal(source, period, "Close SELL", SoundFile, Email, RecurrentSound);
                         else
             ExtSignal(source, period, "Close SELL and BUY", SoundFile, Email, RecurrentSound);
          end   
             end

              if AllowTrade then
                            Close(row);
                            if instance.parameters.AllowDirection~="Short" then
                             Open("B")
                            end
             end
                  end
                end

            end
        end
  else
        if MustOpenB==true and instance.parameters.AllowDirection~="Short" then

            if ShowAlert then
                ExtSignal(source, period, "BUY", SoundFile, Email, RecurrentSound)
            end

            if AllowTrade then
                Open("B")
            end
        end

        if MustOpenS==true and instance.parameters.AllowDirection~="Long" then
            if ShowAlert then
               ExtSignal(source, period, "SELL", SoundFile, Email, RecurrentSound)
       end

            if AllowTrade then
                Open("S")
       end
        end
    end
end
pinimo
 
Posts: 17
Joined: Mon Jul 21, 2014 2:41 am
Location: http://www.marketmovers.it/

Re: Multiple strategy at the same time: doesnt'works?

Postby Apprentice » Mon Oct 20, 2014 4:08 am

Sure strategy can manipulate other strategy positions.
Check if the position is opened by another strategy.

U have to check the position QTXT, the comment text added to the order the position was opened by.
But only if this information is provided by strategy in question.
Unfortunately this information is not there to manually open positions.

From all the above and still do not know what your final goal.
Can you describe in detail.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Multiple strategy at the same time: doesnt'works?

Postby pinimo » Mon Oct 20, 2014 2:54 pm

I thought the problem was clear...
I activated different strategies on a real account, RLW and FIBO CANDLES.
These strategies work on different exchange rates for example RLW eur/usd and FIBO CANDLES USD/JPY.

I do not know why but the fibo candles doesn't generates signal and doesn't open positions.

Strategies are working in a real account from one month to this part.
RLW opened and closed a lot of position, FIBO CANDLEs did nothing.
if I run a backtest on FIBO CANDLES with the same parameters as real there are several positions to open and close, but for some reason, the strategy does not work.
So I then thought that there is some conflict with other operations opened by other strategies (but cross are different) or something else that I do not know.

In conclusion, if the strategy FIBO CANDLES runs alone work properly, if there are other active strategies does nothing.
pinimo
 
Posts: 17
Joined: Mon Jul 21, 2014 2:41 am
Location: http://www.marketmovers.it/

Next

Return to Discussions

Who is online

Users browsing this forum: No registered users and 6 guests