{"id":21,"date":"2007-04-21T14:01:50","date_gmt":"2007-04-21T14:01:50","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2007\/04\/21\/removing-static-variables\/"},"modified":"2007-07-07T19:39:19","modified_gmt":"2007-07-07T19:39:19","slug":"removing-static-variables","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2007\/04\/21\/removing-static-variables\/","title":{"rendered":"Removing Static Variables"},"content":{"rendered":"

Trading systems may use hundreds or even thousands of Static Variables, and the associated memory usage will eventually slow down your system. To prevent this you need to clear them whenever possible. Since at this time AmiBroker doesn’t have a function to remove all Static Variables from memory, you can remove them by referencing each of them by their name, i.e. StaticVarRemove( StaticVarName ).<\/p>\n

Using an indexed name will allow you to use a loop to remove Static Variables from memory. For example, a naming convention such as BuyPrice\u009d+ NumToStr(n,1.0,false), where n could be the DateNum(), TimeNum(), DateTime(), BarIndex(), etc., would allow you to use a simple loop to generate all possible names and remove those that return non-null values.<\/p>\n

Below are two examples of how to remove StaticVariables with this technique. Be careful when using BarNum() because the bar number changes if you use SetBarsRequired(), or if you use Quick-AFL, or if your data exceed the amount set in your DataBase settings or in Preferences.<\/p>\n

procedure ClearAllTrades()
\n{
\nfor( T=0; T<=BarCount; T++)
\n{
\nTradeNumStr = NumToStr(T,1.0,False);
\nTradeName = \"Trade\"+TradeNumStr;
\nStaticVarRemove( TradeName );
\n}
\n}<\/code><\/p>\n

Here is an example of how to remove from memory Ticker-specific OrderIDs that were, for example, used in a portfolio trading system:<\/p>\n

procedure RemoveBasketIDs()
\n{
\nglobal TradingBasket;
\nfor( NT=0; ( Ticker = StrExtract( TradingBasket, NT ) ) != \"\"; NT++ )
\n{
\nStaticVarRemove(Ticker+\"-OID\");
\nStaticVarRemove(Ticker+\"-Action\");
\nStaticVarRemove(Ticker+\"-Qty\");
\n}
\n}<\/code><\/p>\n

Edited by Al Venosa<\/p>\n","protected":false},"excerpt":{"rendered":"

Trading systems may use hundreds or even thousands of Static Variables, and the associated memory usage will eventually slow down your system. To prevent this you need to clear them whenever possible. Since at this time AmiBroker doesn’t have a function to remove all Static Variables from memory, you can remove them by referencing each […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[64],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/21"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}