Development questions: discussing helper.lua

Moderator: admin

Re: Recommended reading

Postby sergesp » Thu May 03, 2012 4:38 pm

.......
ExtSubscribe(1,nil,instance.period.parameters,instance.parameters.type...),
.......
Please read these sections:
Applying the strategy on candle data using the helper
ExtSubscribe function of helper.lua
...
(a) You can just write your functions into the separate file and then reuse it in a strategy by adding the call "dofile(filename)". Note that when installing the strategy in the platform, the helper file will not be installed. You should copy it into the "\FXTS2\Strategies\Custom" folder manually or write separate installer for your strategy.
.....
(d) You can use breakpoints in Strategy Debugger and Add Watch command to see values of variables during the execution of code...
.....


Hi Sunshine,
some follow on questions ( please excuse - probably I am not understanding all the details quite quickly)
(1) about the ExtSubscribe function - I tried to include the SAR indicator in the MA cross strategy and added the ExtSubscribe function from the SAR Averages strategy and got the following message: [string "C:\Gehtsoft\IndicoreSDK\Strategies\modMA_adv..."]:145 attempt to call global 'ExtSubscribe' (a nil value)
I could not figure out the reason, I checked using the watch function to see that all arguments (parameters) in the call were defined and had expected values. Although the same call works in the SAR Averages strategy and with the same parameter values.

(2) re using the dofile - Thanks, I can use that. What I did not understand is that in the example strategies the dofile call is once at the end of the file. When does this call get actually made and how does it get remade ie when data is to be updated?
I found also there is a loadfile call which is supposed to be more efficient - can you please explain if this is true and if so to verify that the returned value is used as a function call to execute the code section loaded by the load file?

(3) thanks about the breakpoint and watch functions in the debugger while I have figured out how to watch some variables - have not figured out how to look for example at what happend in a SetTag or a SetFlag call and also how the scope of the watch is defined - eg when I was watching a variable for a part of the code execution the data shown was as expected and while other functions were being executed the values were not defined.. Again if there is a manual on the debugger please point me to it .

Thanks very much for your help :)
sergesp
 
Posts: 18
Joined: Thu Mar 01, 2012 6:28 pm

Re: Recommended reading

Postby sunshine » Wed May 16, 2012 6:53 am

Hi,
sergesp wrote:and got the following message: [string "C:\Gehtsoft\IndicoreSDK\Strategies\modMA_adv..."]:145 attempt to call global 'ExtSubscribe' (a nil value)

Could you please provide the full code of the modified strategy?

sergesp wrote:(2) re using the dofile - Thanks, I can use that. What I did not understand is that in the example strategies the dofile call is once at the end of the file. When does this call get actually made and how does it get remade ie when data is to be updated?
I found also there is a loadfile call which is supposed to be more efficient - can you please explain if this is true and if so to verify that the returned value is used as a function call to execute the code section loaded by the load file?

All Marketscope strategies and signals which use helper.lua use "dofile". I'd recommend you to use "dofile". It definitely works. I'm not sure about "loadfile". Please read http://www.lua.org/pil/8.html I hope the link will be helpful.
sunshine
 

Recommended reading

Postby sergesp » Tue May 22, 2012 12:39 pm

sunshine wrote:Hi,
sergesp wrote:and got the following message: [string "C:\Gehtsoft\IndicoreSDK\Strategies\modMA_adv..."]:145 attempt to call global 'ExtSubscribe' (a nil value)

Could you please provide the full code of the modified strategy?

..........
All Marketscope strategies and signals which use helper.lua use "dofile". I'd recommend you to use "dofile". It definitely works. I'm not sure about "loadfile". Please read http://www.lua.org/pil/8.html I hope the link will be helpful.


Hi Sunshine,

Thanks for the tips and links - working through it but it is hard going..

here is the code I am having a problem with not sure how to attach a file :oops: so puting in code: Trying to understand difference between when to use update and ExtUpdate and the differences in coding requirements for using each
Code: Select all
-- ------------------------------------------------------
-- MAcross with SAR
--
-- Sample advisor on the base of the moving average cross
--   With SAR to check if price enough on right side.
--   Enter trade only if price <=  >= SAR on correct side
--   modified from MA Advisor, Ssp Apr15 2012
---------------------------------------------------------

-- initialize the advisor profile
--    RC file MAcrossWithSAR.lua.rc
---------------------------------------
function Init()
    strategy:name(resources:get("R_NAME"));
    strategy:description(resources:get("R_DESCRIPTION"));
    strategy:setTag("group", "Moving Averages");

    strategy.parameters:addGroup(resources:get("R_PARAMS_FMA"));
    strategy.parameters:addString("FMA_M", resources:get("R_MA_METHOD"), resources:get("R_MA_METHOD_D"), "MVA");
    strategy.parameters:addStringAlternative("FMA_M", "MVA", "", "MVA");
    strategy.parameters:addStringAlternative("FMA_M", "EMA", "", "EMA");
    strategy.parameters:addStringAlternative("FMA_M", "LWMA", "", "LWMA");
    strategy.parameters:addStringAlternative("FMA_M", "TMA", "", "TMA");
    strategy.parameters:addStringAlternative("FMA_M", "SMMA*", "", "SMMA");
    strategy.parameters:addStringAlternative("FMA_M", "Vidya (1995)*", "", "VIDYA");
    strategy.parameters:addStringAlternative("FMA_M", "Vidya (1992)*", "", "VIDYA92");
    strategy.parameters:addStringAlternative("FMA_M", "Wilders*", "", "WMA");
    strategy.parameters:addStringAlternative("FMA_M", "TEMA*", "", "TEMA1");
    strategy.parameters:addInteger("FMA_N", resources:get("R_MA_N"), "", 20, 1, 5000);
    strategy.parameters:addInteger("FMA_S", resources:get("R_MA_S"), resources:get("R_MA_S_D"), 1, 1, 5000);
    strategy.parameters:addString("FMA_P", resources:get("R_MA_P"), "", "C");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_OPEN"), "", "O");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_HIGH"), "", "H");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_LOW"), "", "L");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_CLOSE"), "", "C");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_MEDIAN"), "", "M");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_TYPICAL"), "", "T");
    strategy.parameters:addStringAlternative("FMA_P", resources:get("R_MA_P_WEIGHTED"), "", "W");

    strategy.parameters:addGroup(resources:get("R_PARAMS_SMA"));
    strategy.parameters:addString("SMA_M", resources:get("R_MA_METHOD"), resources:get("R_MA_METHOD_D"), "MVA");
    strategy.parameters:addStringAlternative("SMA_M", "MVA", "", "MVA");
    strategy.parameters:addStringAlternative("SMA_M", "EMA", "", "EMA");
    strategy.parameters:addStringAlternative("SMA_M", "LWMA", "", "LWMA");
    strategy.parameters:addStringAlternative("SMA_M", "TMA", "", "TMA");
    strategy.parameters:addStringAlternative("SMA_M", "SMMA*", "", "SMMA");
    strategy.parameters:addStringAlternative("SMA_M", "Vidya (1995)*", "", "VIDYA");
    strategy.parameters:addStringAlternative("SMA_M", "Vidya (1992)*", "", "VIDYA92");
    strategy.parameters:addStringAlternative("SMA_M", "Wilders*", "", "WMA");
    strategy.parameters:addStringAlternative("SMA_M", "TEMA*", "", "TEMA1");
    strategy.parameters:addInteger("SMA_N", resources:get("R_MA_N"), "", 30, 1, 5000);
    strategy.parameters:addInteger("SMA_S", resources:get("R_MA_S"), resources:get("R_MA_S_D"), 1, 1, 5000);
    strategy.parameters:addString("SMA_P", resources:get("R_MA_P"), "", "L");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_OPEN"), "", "O");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_HIGH"), "", "H");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_LOW"), "", "L");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_CLOSE"), "", "C");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_MEDIAN"), "", "M");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_TYPICAL"), "", "T");
    strategy.parameters:addStringAlternative("SMA_P", resources:get("R_MA_P_WEIGHTED"), "", "W");

    strategy.parameters:addGroup("SAR Parameters");   -- Add SAR parameters.
    strategy.parameters:addDouble("Step", "Step", "", 0.02, 0.01, 1);
    strategy.parameters:addDouble("Max", "Max", "", 0.2, 0.01, 10);

    strategy.parameters:addGroup(resources:get("R_PARAMS_PRICE"));
    strategy.parameters:addString("TF", resources:get("R_TF"), "", "H1");
    strategy.parameters:setFlag("TF", core.FLAG_PERIODS);

    strategy.parameters:addString("TYPE", resources:get("R_TYPE"), "", "Bid");
    strategy.parameters:addStringAlternative("TYPE", resources:get("R_BID"), "", "Bid");
    strategy.parameters:addStringAlternative("TYPE", resources:get("R_ASK"), "", "Ask");

    strategy.parameters:addGroup(resources:get("R_PARAMS_TRADING"));
    strategy.parameters:addString("CANTRADE", resources:get("R_TR_ALLOWED"), resources:get("R_TR_ALLOWED_D"), "No");
    strategy.parameters:addStringAlternative("CANTRADE", resources:get("R_YES"), "", "Yes");
    strategy.parameters:addStringAlternative("CANTRADE", resources:get("R_NO"), "", "No");
    strategy.parameters:addString("ACCOUNT", resources:get("R_ACCOUNT"), "", "");
    strategy.parameters:setFlag("ACCOUNT", core.FLAG_ACCOUNT);
    strategy.parameters:addString("ALLOWEDSIDE", resources:get("R_ALLOWEDSIDE"), resources:get("R_ALLOWEDSIDE_D"), "Both");
    strategy.parameters:addStringAlternative("ALLOWEDSIDE", resources:get("R_BOTH"), "", "Both");
    strategy.parameters:addStringAlternative("ALLOWEDSIDE", resources:get("R_BUY"), "", "Buy");
    strategy.parameters:addStringAlternative("ALLOWEDSIDE", resources:get("R_SELL"), "", "Sell");

    strategy.parameters:addInteger("AMOUNT", resources:get("R_AMOUNT"), "", 1, 1, 1000);
    strategy.parameters:addInteger("LIMIT", resources:get("R_TR_L"), resources:get("R_TR_L_D"), 0, 0, 10000);
    strategy.parameters:addInteger("STOP", resources:get("R_TR_S"), resources:get("R_TR_S_D"), 0, 0, 10000);
    strategy.parameters:addBoolean("USE_TRAILING_STOP", resources:get("R_USE_TRAILING_STOP"), "", true);
    strategy.parameters:addBoolean("PLAY", resources:get("R_SOUND"), "", false);
    strategy.parameters:addBoolean("RECURRENTSOUND", resources:get("R_RECURRENTSOUND"), "", false);
    strategy.parameters:addFile("SOUND", resources:get("R_SOUND_FILE"), "", "");
    strategy.parameters:setFlag("SOUND", core.FLAG_SOUND);
    strategy.parameters:addBoolean("SENDEMAIL", resources:get("R_SENDEMAIL"), "", false);
    strategy.parameters:addString("EMAIL", resources:get("R_EMAIL"), resources:get("R_EMAIL_D"),"");
    strategy.parameters:setFlag("EMAIL", core.FLAG_EMAIL);
end
-- check parameters and set advisor name
local name;
local Step, Max;
local Period, Price;
local sar = nil;
local tsource = nil;
local minChange;

function Prepare(onlyName)
        Step = instance.parameters.Step;
        Max = instance.parameters.Max;
    -- set the name
    name = profile:id() .. "(" .. instance.bid:instrument() .. "." .. instance.parameters.TF .. "." .. instance.parameters.TYPE .. "," ..
                                  instance.parameters.FMA_M .. "(" .. instance.parameters.FMA_P .. "," .. instance.parameters.FMA_N .. "," .. instance.parameters.FMA_S .. ")," ..
                                  instance.parameters.SMA_M .. "(" .. instance.parameters.SMA_P .. "," .. instance.parameters.SMA_N .. "," .. instance.parameters.SMA_S .. ")," ..
                                  Step.. "," .. Max .. ")";
    instance:name(name);
    assert(core.indicators:findIndicator("AVERAGES") ~= nil, "Please, download and install AVERAGES.LUA indicator");
    if onlyName then
        return;
    end

-- Create SAR and minChange on stop
--    minChange = math.pow(10, -instance.bid:getPrecision());
    tsource = ExtSubscribe(1, nil, instance.parameters.TF, instance.parameters.TYPE == "Bid", "bar");
    sar = core.indicators:create("SAR", tsource, instance.parameters.Step, instance.parameters.Max);

    -- check time frame
    assert(instance.parameters.TF ~= "t1", resources:get("R_ERROR_TICK"));
    -- check sound alert params
    assert(not(instance.parameters.PLAY) or (instance.parameters.PLAY and instance.parameters.SOUND ~= ""), resources:get("R_ERROR_SOUND"));
    -- check trading params
    if instance.parameters.CANTRADE == "Yes" then
        assert(core.host:findTable("Accounts"):find("AccountID", instance.parameters.ACCOUNT) ~= nil, resources:get("R_ERROR_ACCOUNT"));
        assert(core.host:findTable("offers"):find("Instrument", instance.bid:instrument()) ~= nil, resources:get("R_ERROR_OFFER"));
    end

    -- check methods
    assert(core.indicators:findIndicator(instance.parameters.FMA_M) ~= nil, resources:get("R_ERROR_METHOD"));
    assert(core.indicators:findIndicator(instance.parameters.SMA_M) ~= nil, resources:get("R_ERROR_METHOD"));
end

-- global data block start
local init = false;
local loaded = false;
local priorbar = nil;

-- price and MVA data (indicator, data and shift)
local TICKSRC;
local SRC;
local SMA, SMADATA, SMASHIFT;
local FMA, FMADATA, FMASHIFT;

-- trade data
local OFFER;
local CANTRADE;
local ACCOUNT;
local AMOUNT;
local PLAY;
local RECURRENTSOUND;
local SOUND;
local LIMIT;
local STOP;
local SELL;
local BUY;
local CANCLOSE;
local SENDEMAIL;
local EMAIL;
local ALLOWEDSIDE;
local CID = "MACROSS";
local USE_TRAILING_STOP;
local sar_period = 0.0;
local LONG_TRADE = false;
local SHORT_TRADE = false;

-- global data block end
function Update()
    if not(init) then
        TICKSRC = instance.bid;
        -- collect the trading parameters
        CANTRADE = (instance.parameters.CANTRADE == "Yes");
        if CANTRADE then
            ACCOUNT = instance.parameters.ACCOUNT;
            USE_TRAILING_STOP = instance.parameters.USE_TRAILING_STOP;
            AMOUNT = instance.parameters.AMOUNT * core.host:execute("getTradingProperty", "baseUnitSize", TICKSRC:instrument(), ACCOUNT);
            LIMIT = math.floor(instance.parameters.LIMIT + 0.5);
            STOP = math.floor(instance.parameters.STOP + 0.5);
            OFFER = core.host:findTable("offers"):find("Instrument", TICKSRC:instrument()).OfferID;
            CANCLOSE = core.host:execute("getTradingProperty", "canCreateMarketClose", TICKSRC:instrument(), ACCOUNT);
        end
        ALLOWEDSIDE = instance.parameters.ALLOWEDSIDE;
        SELL = resources:get("R_SELL");
        BUY = resources:get("R_BUY");
        PLAY = instance.parameters.PLAY;
        SOUND = instance.parameters.SOUND;
        RECURRENTSOUND = instance.parameters.RECURRENTSOUND;

        SENDEMAIL = instance.parameters.SENDEMAIL
        EMAIL = instance.parameters.EMAIL

        -- load the price data
        SRC = core.host:execute("getHistory", 1, TICKSRC:instrument(), instance.parameters.TF, 0, 0, instance.parameters.TYPE == "Bid");
        FMA, FMADATA = CreateMA(instance.parameters.FMA_M, instance.parameters.FMA_N, instance.parameters.FMA_P, SRC);
        SMA, SMADATA = CreateMA(instance.parameters.SMA_M, instance.parameters.SMA_N, instance.parameters.SMA_P, SRC);
        FMASHIFT = instance.parameters.FMA_S;
        SMASHIFT = instance.parameters.SMA_S;

        init = true;
        return ;
    end

    -- return if the data is not loaded yet
    if not(loaded) or SRC:size() < 2 then
        return ;
    end

    -- the index of the bar to be processed
    local p = SRC:size() - 2;

    -- check if the same bar is still updating
    if priorbar ~= nil and SRC:serial(p) == priorbar then
        return ;
    end

    -- remember the last processed bar
    priorbar = SRC:serial(p);

    -- update moving average
    FMA:update(core.UpdateLast);
    SMA:update(core.UpdateLast);
    sar:update(core.UpdateLast);
    sar_period = sar.DATA:size() - 1;

    -- check whether here is enough data to check the
    -- signal conditions
    if p <= FMADATA:first() + FMASHIFT or p <= SMADATA:first() + SMASHIFT then
        return ;
    elseif sar_period < sar.DATA:first() then
        return ;
    end

-- Check buy Entry
    if core.crossesOver(FMADATA, SMADATA, p - FMASHIFT, p - SMASHIFT) and

 -- #######     PRICE >=  SAR + 50 pip   and #######  --  ADD Condition of Price >= SAR + 50 PIP

                                      (ALLOWEDSIDE == "Both" or ALLOWEDSIDE == "Buy") then

        -- buy condition met (fast crosses over slow and Price is greater than SAR dot + 50 pip and trade allowed)

        if CANTRADE and LONG_TRADE ~= true then
            close("S");     -- closes all existing shorts on the account
            enter("B");     -- and the enter long
            LONG_TRADE = true;  -- set long trade flag
        end
        terminal:alertMessage(TICKSRC:instrument(), TICKSRC[NOW], name .. ":" .. BUY, TICKSRC:date(NOW));
        if PLAY then
            terminal:alertSound(SOUND, RECURRENTSOUND);
        end

        if SENDEMAIL then
            terminal:alertEmail(EMAIL, name .. ":" .. BUY, FormatEmail(TICKSRC, NOW, BUY));
        end   

-- Check sell Entry
    elseif core.crossesUnder(FMADATA, SMADATA, p - FMASHIFT, p - SMASHIFT) and

-- ######     Price <= SAR - 50 PIP      and  #######  --  ADD condition PRICE <= SAR - 50 PIP

                                     (ALLOWEDSIDE == "Both" or ALLOWEDSIDE == "Sell") then

        -- sell condition met (Fast crosses under slow and Price is greater than SAR dot + 50 pip and trade allowed)

        if CANTRADE and SHORT_TRADE ~= true then
            close("B");     -- closes all existing longs on the account
            enter("S");     -- and the enter short
            SHORT_TRADE = true; -- set short trade flag
        end
        terminal:alertMessage(TICKSRC:instrument(), TICKSRC[NOW], name .. ":" .. SELL, TICKSRC:date(NOW));
        if PLAY then
            terminal:alertSound(SOUND, RECURRENTSOUND);
        end

        if SENDEMAIL then
            terminal:alertEmail(EMAIL, name .. ":" .. SELL, FormatEmail(TICKSRC, NOW, SELL));
        end
    end
end
-- creates moving average with the specified parameters for the specified price
function CreateMA(method, n, price, src)
    local p;
    if price == "O" then
        p = src.open;
    elseif price == "H" then
        p = src.high;
    elseif price == "L" then
        p = src.low;
    elseif price == "M" then
        p = src.median;
    elseif price == "T" then
        p = src.typical;
    elseif price == "W" then
        p = src.weighted;
    else
        p = src.close;
    end

    local indicator = core.indicators:create(method, p, n);
    return indicator, indicator.DATA;
end

-- closes all positions of the specified direction (B for buy, S for sell)
function close(side)
    local enum, row, valuemap;

    enum = core.host:findTable("trades"):enumerator();
    while true do
        row = enum:next();
        if row == nil then
            break;
        end
        if row.AccountID == ACCOUNT and
           row.OfferID == OFFER and
           row.BS == side and
           row.QTXT == CID then
            -- if trade has to be closed

            if CANCLOSE then
                -- non-FIFO account, create a close market order
                valuemap = core.valuemap();
                valuemap.OrderType = "CM";
                valuemap.OfferID = OFFER;
                valuemap.AcctID = ACCOUNT;
                valuemap.Quantity = row.Lot;
                valuemap.TradeID = row.TradeID;
                valuemap.CustomID = CID;
                if row.BS == "B" then
                    valuemap.BuySell = "S";
                else
                    valuemap.BuySell = "B";
                end
                success, msg = terminal:execute(200, valuemap);
                assert(success, msg);
            else
                -- FIFO account, create an opposite market order
                valuemap = core.valuemap();
                valuemap.OrderType = "OM";
                valuemap.OfferID = OFFER;
                valuemap.AcctID = ACCOUNT;
                valuemap.Quantity = AMOUNT;
                valuemap.CustomID = CID;
                if row.BS == "B" then
                    valuemap.BuySell = "S";
                else
                    valuemap.BuySell = "B";
                end
                success, msg = terminal:execute(200, valuemap);
                assert(success, msg);
            end
        end
    end
end

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

    valuemap = core.valuemap();
    valuemap.OrderType = "OM";
    valuemap.OfferID = OFFER;
    valuemap.AcctID = ACCOUNT;
    valuemap.Quantity = AMOUNT;
    valuemap.CustomID = CID;
    valuemap.BuySell = side;
    if STOP >= 1 then
        valuemap.PegTypeStop = "O";
        if side == "B" then
            valuemap.PegPriceOffsetPipsStop = -STOP;
        else
            valuemap.PegPriceOffsetPipsStop = STOP;
        end
        if USE_TRAILING_STOP then
            valuemap.TrailStepStop = 1;
        end
    end
    if LIMIT >= 1 then
        valuemap.PegTypeLimit = "O";
        if side == "B" then
            valuemap.PegPriceOffsetPipsLimit = LIMIT;
        else
            valuemap.PegPriceOffsetPipsLimit = -LIMIT;
        end
    end

    if (not CANCLOSE) and (STOP >= 1 or LIMIT >= 1) then
        valuemap.EntryLimitStop = 'Y'
    end

    success, msg = terminal:execute(200, valuemap);
    assert(success, msg);
end

function AsyncOperationFinished(cookie, success, message)
    if cookie == 1 then
        loaded = true;
    elseif cookie == 200 then
        assert(success, message);
    end
end

local emailInit = false;
local delim;
local signalDescr;
local symbolDescr;
local messageDescr;
local dateDescr
local priceDescr;
local introDescr;
local priceFormat;
-- ---------------------------------------------------------
-- Formats the email subject and text
-- @param source   The signal source
-- @param period    The number of the period
-- @param message   The rest of the message to be added to the signal
-- ---------------------------------------------------------
function FormatEmail(source, period, message)
    --format email text
    if not(emailInit) then
        emailInit = true;
        delim = "\013\010";
        signalDescr = resources:get("R_MAIL_SIGNAL_DESCR");
        symbolDescr = resources:get("R_MAIL_SYMBOL_HEADER");
        messageDescr = resources:get("R_MAIL_MESSAGE_DESCR");
        dateDescr = resources:get("R_MAIL_TIME_HEADER");
        priceDescr = resources:get("R_MAIL_PRICE_HEADER");
        introDescr = resources:get("R_MAIL_INTRODUCTION");
        priceFormat = "%." .. instance.bid:getPrecision() .. "f";
    end
    local ttime = core.dateToTable(core.host:execute("convertTime", 1, 4, math.max(instance.bid:date(NOW), instance.ask:date(NOW))));

    local r = delim .. introDescr .. delim ..
              signalDescr .. name .. delim ..
              symbolDescr .. instance.bid:instrument() .. delim ..
              messageDescr .. message .. delim ..
              dateDescr .. string.format("%02i/%02i %02i:%02i", ttime.month, ttime.day, ttime.hour, ttime.min) .. delim ..
              priceDescr .. string.format(priceFormat, source[period]) .. delim;
    return r;
end




and the RC file (from MA_Advisor
Code: Select all
default=enu
[enu]
codepage=1252
R_NAME=MAcrossWithSAR
R_DESCRIPTION=MAcrossFMAxSMA+p<>SAR+50
R_PARAMS_FMA=Fast Moving Average Parameters
R_PARAMS_SMA=Slow Moving Average Parameters
R_MA_METHOD=Moving Average method
R_MA_METHOD_D=The methods marked by asterisk(*) must be downloaded and installed from the fxcodebase.com site.
R_MA_N=Number of periods
R_MA_S=Shift
R_MA_S_D=Shift of the moving average value into the future expressed in periods.
R_MA_P=Price
R_MA_P_OPEN=Open
R_MA_P_HIGH=High
R_MA_P_LOW=Low
R_MA_P_CLOSE=Close
R_MA_P_MEDIAN=Median
R_MA_P_TYPICAL=Typical
R_MA_P_WEIGHTED=Weighted
R_PARAMS_PRICE=Price
R_TF=Timeframe
R_TYPE=Price type
R_BID=Bid
R_ASK=Ask
R_PARAMS_TRADING=Trading Parameters
R_TR_ALLOWED=Allow trading
R_TR_ALLOWED_D=In case the trading is not allowed, alerts will be shown instead of actual trading.
R_YES=Yes
R_NO=No
R_AMOUNT=Amount
R_TR_L=Set Limit
R_TR_L_D=Leave 0 to not set a limit order on the trades or enter a limit distance in pips.
R_TR_S=Set Stop
R_TR_S_D=Leave 0 to not set a stop order on the trades or enter an initial stop distance in pips.
R_ACCOUNT=Account
R_LOT=The amount to trade.
R_SOUND=Play sound
R_RECURRENTSOUND=Recurrent
R_SOUND_FILE=Sound file
R_ERROR_TICK=The strategy cannot be applied on ticks.
R_ERROR_SOUND=The sound file must be chosen.
R_ERROR_ACCOUNT=The account to trade must be chosen.
R_ERROR_OFFER=The chosen symbol is not found.
R_ERROR_METHOD=The chosen moving average method is not installed. Please use fxcodebase.com site to download the approriate moving average method.
R_SELL=Sell
R_BUY=Buy
R_SENDEMAIL=Send e-mail
R_EMAIL=E-mail address
R_EMAIL_D=Note that to recieve e-mails, SMTP settings must be defined (see Signals Options).
R_MAIL_INTRODUCTION=You have received this message because the following signal alert was received:
R_MAIL_SIGNAL_DESCR=Signal:
R_MAIL_SYMBOL_HEADER=Symbol:
R_MAIL_MESSAGE_DESCR=Message:
R_MAIL_TIME_HEADER=Time:
R_MAIL_PRICE_HEADER=Price:
R_ALLOWEDSIDE=Allowed side
R_ALLOWEDSIDE_D=Allowed side for trading or signaling, can be Sell, Buy or Both
R_BOTH=Both
R_USE_TRAILING_STOP=Use trailing stop


Thanks :)
sergesp
 
Posts: 18
Joined: Thu Mar 01, 2012 6:28 pm

Re: Recommended reading

Postby sergesp » Wed May 23, 2012 5:17 am

PS: I forgot to note that I had 2 main questions:
(1) what is the difference between the use of the update and the Ext update function (the MA advisor uses one the SAR Averages strategy uses the other) and I tried to combine them - so what was I missing which led to the problem.
(2) I also had a question as to how to code the conditions for the BUY and SELL logic in the strategy (I am trying to implement) the part the which compares PRICE with the SAR (dot) Value to check that there is enough movement in the required direction.

Thanks :)
sergesp
 
Posts: 18
Joined: Thu Mar 01, 2012 6:28 pm

Re: Development questions: discussing helper.lua

Postby sunshine » Wed May 23, 2012 6:15 am

[moderated: moved discussion from "Recommended reading" in the separate topic]
sunshine
 

Re: Development questions: discussing helper.lua

Postby sunshine » Wed May 23, 2012 7:04 am

here is the code I am having a problem with

The error occurs because the helper.lua file is not included in the file. If you use ExtSubscribe function, you should include the helper.lua file by adding the line:
Code: Select all
dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");


(1) what is the difference between the use of the update and the Ext update function (the MA advisor uses one the SAR Averages strategy uses the other) and I tried to combine them - so what was I missing which led to the problem.

The strategy can use either the Update or ExtUpdate function. Unlike the Update function which is called for each tick, ExtUpdate is called once for a period, when the bar is closed. So using ExtUpdate function (and helper.lua) simplifies development of strategies since you don't need to check if the bar is closed.

(2) I also had a question as to how to code the conditions for the BUY and SELL logic in the strategy (I am trying to implement) the part the which compares PRICE with the SAR (dot) Value to check that there is enough movement in the required direction.

These conditions must be implemented in the Update (or ExtUpdate) function. Could you post the formula and I'll try to code it.
sunshine
 

Previous

Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 35 guests