ChangeParameters() not changing instance.parameters

All posts which do not fit into any other sections of the forum.

Moderator: admin

ChangeParameters() not changing instance.parameters

Postby OQTradeTech » Mon Jul 06, 2020 2:51 pm

Hello,

According to to the documentation, instance.parameters should change when ChangeParameters() is called. In my tests, I do not see this happening. In the following test code output, final line (top) should have parameters changed to m15, 10, but the values are not changed. It seems example code in documentation has the same issue.
Am I doing something wrong, or is it a bug in Trading Station?
TS version: 01.15.081619

Code: Select all
Symbol   Strategy/Indicator   Message   Time
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:31
EUR/USD   TEST m15 10   Trace: 'ExtAsyncOperationFinished called.'.   2020-07-06 12:12:31
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:26
EUR/USD   TEST m15 10   Trace: 'ExtAsyncOperationFinished called.'.   2020-07-06 12:12:26
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'ChangeParameters called.'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'New parameters: m15; 10'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'CheckParameters called.'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   TEST m1 1 is started.   2020-07-06 12:12:00
   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:00
   TEST m15 10   Trace: 'Prepare called.'.   2020-07-06 12:12:00


Test code (opening/closing trade prints current parameters):
Code: Select all
function Init()
    strategy:name("Test");
    strategy:description("");
    strategy:type(core.Strategy);
   
    strategy.parameters:addString("t", "t", "", "m1");
    strategy.parameters:setFlag("t", core.FLAG_PERIODS);
    strategy.parameters:addInteger("i", "i", "", 1);
end

function Prepare(name_only)
    instance:name(string.format("%s %s %i",profile:id(),instance.parameters.t,instance.parameters.i));
    if not name_only then
        log("Prepare called.");
        printParameters();
        core.host:execute("subscribeTradeEvents", 1000, "trades");
    end
end

function ReleaseInstance()
    log("ReleaseInstance called.");
    printParameters();
end

function CheckParameters(params)
    log("CheckParameters called.");
    printParameters();
    log("New parameters: %s; %i",params.t, params.i);
    return string.format("%s %s %i",profile:id(),params.t,params.i);
end

function ChangeParameters()
    log("ChangeParameters called.")
    printParameters();
end

function ExtUpdate(id, source, period)
    log("ExtUpdate called.");
    printParameters();
end

function ExtAsyncOperationFinished(cookie, success, message, message1, message2)
    log("ExtAsyncOperationFinished called.");
    printParameters();
end

function log(text, ...)
    core.host:trace(string.format(text, unpack(arg)));
end

function printParameters()
    log("Current parameters: %s; %i",instance.parameters.t, instance.parameters.i);
end

dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");
OQTradeTech
 
Posts: 2
Joined: Mon Jul 06, 2020 12:23 pm


Re: ChangeParameters() not changing instance.parameters

Postby OQTradeTech » Tue Jul 28, 2020 5:15 am

Thank you, but removing ChangeParameters() from the program results in data loss, and does not really solve the issue of documentation describing the function inaccurately.
Attachments
test.jpg
test.lua
(1.17 KiB) Downloaded 392 times
OQTradeTech
 
Posts: 2
Joined: Mon Jul 06, 2020 12:23 pm

Re: ChangeParameters() not changing instance.parameters

Postby Apprentice » Mon Aug 17, 2020 3:40 am

Your request is added to the development list.
Development reference 1892.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 37918
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Re: ChangeParameters() not changing instance.parameters

Postby davidmark » Fri Sep 13, 2024 2:35 am

OQTradeTech wrote:Hello,

According to to the documentation rice purity test, instance.parameters should change when ChangeParameters() is called. In my tests, I do not see this happening. In the following test code output, final line (top) should have parameters changed to m15, 10, but the values are not changed. It seems example code in documentation has the same issue.
Am I doing something wrong, or is it a bug in Trading Station?
TS version: 01.15.081619

Code: Select all
Symbol   Strategy/Indicator   Message   Time
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:31
EUR/USD   TEST m15 10   Trace: 'ExtAsyncOperationFinished called.'.   2020-07-06 12:12:31
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:26
EUR/USD   TEST m15 10   Trace: 'ExtAsyncOperationFinished called.'.   2020-07-06 12:12:26
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'ChangeParameters called.'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'New parameters: m15; 10'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'CheckParameters called.'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   TEST m1 1 is started.   2020-07-06 12:12:00
   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:00
   TEST m15 10   Trace: 'Prepare called.'.   2020-07-06 12:12:00


Test code (opening/closing trade prints current parameters):
Code: Select all
function Init()
    strategy:name("Test");
    strategy:description("");
    strategy:type(core.Strategy);
   
    strategy.parameters:addString("t", "t", "", "m1");
    strategy.parameters:setFlag("t", core.FLAG_PERIODS);
    strategy.parameters:addInteger("i", "i", "", 1);
end

function Prepare(name_only)
    instance:name(string.format("%s %s %i",profile:id(),instance.parameters.t,instance.parameters.i));
    if not name_only then
        log("Prepare called.");
        printParameters();
        core.host:execute("subscribeTradeEvents", 1000, "trades");
    end
end

function ReleaseInstance()
    log("ReleaseInstance called.");
    printParameters();
end

function CheckParameters(params)
    log("CheckParameters called.");
    printParameters();
    log("New parameters: %s; %i",params.t, params.i);
    return string.format("%s %s %i",profile:id(),params.t,params.i);
end

function ChangeParameters()
    log("ChangeParameters called.")
    printParameters();
end

function ExtUpdate(id, source, period)
    log("ExtUpdate called.");
    printParameters();
end

function ExtAsyncOperationFinished(cookie, success, message, message1, message2)
    log("ExtAsyncOperationFinished called.");
    printParameters();
end

function log(text, ...)
    core.host:trace(string.format(text, unpack(arg)));
end

function printParameters()
    log("Current parameters: %s; %i",instance.parameters.t, instance.parameters.i);
end

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

It looks like you're experiencing an issue with the ChangeParameters() function not updating the parameters as expected. Based on your output, even after calling ChangeParameters(), the parameters remain unchanged. This could either be a bug in Trading Station or an issue with how the parameters are being set. I recommend checking the documentation for any additional requirements or constraints related to parameter changes. If everything seems correct, consider reporting it to the Trading Station support team for further assistance.
davidmark
 
Posts: 1
Joined: Fri Sep 13, 2024 2:31 am

Re: ChangeParameters() not changing instance.parameters

Postby Apprentice » Sat Sep 14, 2024 3:36 am

We have added your request to the development list.
Development reference 708
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 37918
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: ChangeParameters() not changing instance.parameters

Postby Victor.Tereschenko » Fri Oct 11, 2024 1:32 am

davidmark wrote:
OQTradeTech wrote:Hello,

According to to the documentation rice purity test, instance.parameters should change when ChangeParameters() is called. In my tests, I do not see this happening. In the following test code output, final line (top) should have parameters changed to m15, 10, but the values are not changed. It seems example code in documentation has the same issue.
Am I doing something wrong, or is it a bug in Trading Station?
TS version: 01.15.081619

Code: Select all
Symbol   Strategy/Indicator   Message   Time
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:31
EUR/USD   TEST m15 10   Trace: 'ExtAsyncOperationFinished called.'.   2020-07-06 12:12:31
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:26
EUR/USD   TEST m15 10   Trace: 'ExtAsyncOperationFinished called.'.   2020-07-06 12:12:26
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'ChangeParameters called.'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'New parameters: m15; 10'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   Trace: 'CheckParameters called.'.   2020-07-06 12:12:12
EUR/USD   TEST m15 10   TEST m1 1 is started.   2020-07-06 12:12:00
   TEST m15 10   Trace: 'Current parameters: m1; 1'.   2020-07-06 12:12:00
   TEST m15 10   Trace: 'Prepare called.'.   2020-07-06 12:12:00


Test code (opening/closing trade prints current parameters):
Code: Select all
function Init()
    strategy:name("Test");
    strategy:description("");
    strategy:type(core.Strategy);
   
    strategy.parameters:addString("t", "t", "", "m1");
    strategy.parameters:setFlag("t", core.FLAG_PERIODS);
    strategy.parameters:addInteger("i", "i", "", 1);
end

function Prepare(name_only)
    instance:name(string.format("%s %s %i",profile:id(),instance.parameters.t,instance.parameters.i));
    if not name_only then
        log("Prepare called.");
        printParameters();
        core.host:execute("subscribeTradeEvents", 1000, "trades");
    end
end

function ReleaseInstance()
    log("ReleaseInstance called.");
    printParameters();
end

function CheckParameters(params)
    log("CheckParameters called.");
    printParameters();
    log("New parameters: %s; %i",params.t, params.i);
    return string.format("%s %s %i",profile:id(),params.t,params.i);
end

function ChangeParameters()
    log("ChangeParameters called.")
    printParameters();
end

function ExtUpdate(id, source, period)
    log("ExtUpdate called.");
    printParameters();
end

function ExtAsyncOperationFinished(cookie, success, message, message1, message2)
    log("ExtAsyncOperationFinished called.");
    printParameters();
end

function log(text, ...)
    core.host:trace(string.format(text, unpack(arg)));
end

function printParameters()
    log("Current parameters: %s; %i",instance.parameters.t, instance.parameters.i);
end

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

It looks like you're experiencing an issue with the ChangeParameters() function not updating the parameters as expected. Based on your output, even after calling ChangeParameters(), the parameters remain unchanged. This could either be a bug in Trading Station or an issue with how the parameters are being set. I recommend checking the documentation for any additional requirements or constraints related to parameter changes. If everything seems correct, consider reporting it to the Trading Station support team for further assistance.


Take a look at the viewtopic.php?f=17&t=68571 (Double Rectangle). There is a workaround in that code

Code: Select all
local temp_params;
function CheckParameters(params)
    temp_params = params;
    return profile:name();
end

function ChangeParameters()
    -- copy all the params because of FXTS2 bug
    instance.parameters.start_rate = temp_params.start_rate;
...
    Prepare(false);
end

“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 151
Joined: Fri Nov 19, 2010 8:55 am


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 1 guest