Multiple updates running in strategies

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

Moderator: admin

Re: Multiple updates running in strategies

Postby Apprentice » Fri Feb 01, 2013 6:25 am

In Strategy Template u can find my Tick Based Strategy if non trading time frame is Tick.
viewtopic.php?f=28&t=2712#p6290

I Use a complex algorithm,
Not perfect, but good enough for me.
For trading time frame strategy not to do anything.
Will Execute trading algorithm only for first tick within trading time frame.

For multiple time frames, if non trading is not Tick, better solutions will be MTF Strategy Template.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Multiple updates running in strategies

Postby boss_hogg » Mon Feb 04, 2013 11:15 am

I think I got it for bar source, here is the code. The major caveat I can tell so far, is that it has to wait for a major time frame bar to execute in order to calculate the nextMBarEnd . It still needs some testing but it looks ok.

Code: Select all
local tfSync, tfSyncCounter , nextMBarEnd = false, 0, 0;

function ExtUpdate(id, source, period)
if instance.parameters.AllowTrade and (not(checkReady("Trades")) or not(checkReady("Orders"))) then
    return ;
end

if math.abs(nextMBarEnd - ( source:date(period)+(source:date(period)-source:date(period-1)) ))<0.00000001 then      -- A simple == here did not work, probably due to infinite digits and precision issues
    tfSync=true;  -- concurrent close of trading and major time frame bars
end

if id==tID then  -- trading time frame

       if tfSync then
            tfSyncCounter=tfSyncCounter+1;
        end

...check indicator results here...

end

if id==mID then   -- major time frame
-- get end of next major time frame bar:
        nextMBarEnd=source:date(period) + 2*(source:date(period)-source:date(period-1));

       if tfSync then
            tfSyncCounter=tfSyncCounter+1;
        end

...check indicator results here...

end

if tfSync and tfSyncCounter==2 then
        proceedToStrategyLogic();
        tfSync=false;
        tfSyncCounter=0;
elseif not(tfSync) then     
        proceedToStrategyLogic();
end                  -- is tfSyncCounter is still 1 , nothing happens

end
boss_hogg
FXCodeBase: Confirmed User
 
Posts: 48
Joined: Fri Oct 26, 2012 3:03 am

Previous

Return to Discussions

Who is online

Users browsing this forum: No registered users and 6 guests