Australian (ASX) Stock Market Forum

Amibroker FAQ

Hi Guys,

Wondering if someone could add some valid buy/sell lines to this code of Ed's. I've had a shot but it's beyond my ability. Just looking for buy at 50%, sell at 38%. Thanks.


// Amibroker AFL code by Edward Pottasch, Nov 2012
// Alternative ZIG type function based on the ATR and VSTOP functions
// Added multiple timeframes. Maximum timeframe set to 1440 minutes
// Added Fib retrace levels

x=xx=BarIndex();
tc=ParamList("Display Mode","ZIG|VSTOP|ZIG&VSTOP",0);
disp0=ParamToggle("Display labels","Off|On",1);
disp1=ParamToggle("Display value labels","Off|On",1);
tf=Param("Time Frame (min)",60,1,1440,1);tfrm=in1Minute*tf;
perBull=Param("perBull",20,1,150,1);
perBear=Param("perBear",20,1,150,1);
multBull=Param("multBull",2,0.05,4,0.05);
multBear=Param("multBear",2,0.05,4,0.05);
perc=Param("Percentage Range (S/R lines)",20,0.05,100,0.01);
npiv=Param("N Pivots Used (S/R lines)",1,1,250,1);
disp2=ParamToggle("Display S/R levels","Off|On",0);
disp3=ParamToggle("Display Fibonacci levels","Off|On",0);
nlev=Param("Number of Fib Levels to display",7,0,12,1);
TimeFrameSet(tfrm);
function vstop_func(trBull,trBear)
{
trailArray[0]=C[0];
for(i=1;i<BarCount;i++)
{
prev=trailArray[i-1];

if(C>prev AND C[i-1]>prev)
{
trailArray=Max(prev,C-trBull);
}
else if(C<prev AND C[i-1]< prev)
{
trailArray=Min(prev,C+trBear);
}
else if (C>prev)
{
trailArray=C-trBull;
}
else
{
trailArray=C+trBear;
}
}
return trailArray;
}

trBull=multBull*ATR(perBull);
trBear=multBear*ATR(perBear);
trailArray = vstop_func(trBull,trBear);
ts=IIf(trailArray>C,trailArray,Null);
tl=IIf(trailArray<C,trailArray,Null);
TimeFrameRestore();

ts=TimeFrameExpand(ts,tfrm,expandLast);
tl=TimeFrameExpand(tl,tfrm,expandLast);

GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle Up Color", colorBrightGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color", ColorRGB(0,255,0)),IIf(C<=O,ParamColor("Shadow Color", ColorRGB(255,0,0)),colorLightGrey)),64,0,0,0,0,1);

lll=LLV(L,BarsSince(!IsEmpty(tl)));lll=IIf(ts,lll,Null);llls=lll;
ttt1=IIf((!IsEmpty(ts) AND IsEmpty(Ref(ts,1))) OR BarIndex()==BarCount-1,1,Null);
ttt=ValueWhen(ttt1,lll,0);ttt=IIf(ts,ttt,Null);ttt=IIf(ttt1,Ref(ttt,-1),ttt);
tr=L==ttt;lll=Sum(tr,BarsSince(!IsEmpty(tl)));
qqq=ValueWhen(ttt1,lll,0);qqq=IIf(ts,qqq,Null);qqq=IIf(ttt1,Ref(qqq,-1),qqq);tr=tr AND lll==qqq;
tr=IIf((!IsEmpty(ts) AND IsEmpty(Ref(ts,1)) AND IsEmpty(Ref(ts,-1))),1,tr);//exception
hhh=HHV(H,BarsSince(!IsEmpty(ts)));hhh=IIf(tl,hhh,Null);hhhs=hhh;
ttt1=IIf((!IsEmpty(tl) AND IsEmpty(Ref(tl,1))) OR BarIndex()==BarCount-1,1,Null);
ttt=ValueWhen(ttt1,hhh,0);ttt=IIf(tl,ttt,Null);ttt=IIf(ttt1,Ref(ttt,-1),ttt);
pk=H==ttt;hhh=Sum(pk,BarsSince(!IsEmpty(ts)));
sss=ValueWhen(ttt1,hhh,0);sss=IIf(tl,sss,Null);sss=IIf(ttt1,Ref(sss,-1),sss);pk=pk AND hhh==sss;
pk=IIf((!IsEmpty(tl) AND IsEmpty(Ref(tl,1)) AND IsEmpty(Ref(tl,-1))),1,pk);//exception

px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);

minipk=H>=Ref(HHV(H,1),-1) AND Ref(HHV(H,1),1)<H;
minitr=L<=Ref(LLV(L,1),-1) AND Ref(LLV(L,1),1)>L;

switch(tc)
{
case("ZIG"):
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);aa1=IIf(pk,Ref(aa1,-1),aa1);ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND px1<tx1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorBlue,styleLine,0,0,0,2,3);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);aa1=IIf(tr,Ref(aa1,-1),aa1);ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND tx1<px1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorOrange,styleLine,0,0,0,2,3);
break;
case("VSTOP"):
Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
break;
case("ZIG&VSTOP"):
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);aa1=IIf(pk,Ref(aa1,-1),aa1);ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND px1<tx1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorBlue,styleLine,0,0,0,2,3);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);aa1=IIf(tr,Ref(aa1,-1),aa1);ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND tx1<px1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorOrange,styleLine,0,0,0,2,3);
Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
break;
}

PlotShapes(shapeSmallCircle*tr,colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*pk,colorRed,0,H,10);

qq=Interval()/60;
if(qq < 60){tf=" min";tt=qq;}
else if(qq >= 60 AND qq < 1440){tf=" hrs";tt=qq/60;}
else if(qq >= 1440){tf=" days";tt=(qq/60)/24;}
qq=Max(tfrm/60,Interval()/60);
if(qq < 60){tfa=" min";tta=qq;}
else if(qq >= 60 AND qq < 1440){tfa=" hrs";tta=qq/60;}
else if(qq >= 1440){tfa=" days";tta=(qq/60)/24;}

Title = Name() +
"\nChart TF: " + tt + tf +
"\nZig TF: " + tta + tfa;

dxhm=14;dxlm=10;dxh=0;dxl=0;dyhm=5;dylm=3;dyh=18;dyl=29;hm=30;lm=30;
dyl2=42;dylm2=16;dyhm2=18;dyh2=31;
function GetVisibleBarCount()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelsToBarX(Pixels)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
fac=pxchartwidth/Pixels;
bar=(lvb-fvb)/fac;
return bar;
}
function GfxConvertPixelToValueY(Pixels)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
fac=pxchartheight/Pixels;
Value=(Maxy-Miny)/fac;
return Value;
}

ll=tr AND tl1<tl2;
hl=tr AND tl1>tl2;
hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2;
dt=pk AND ph1==ph2;
db=tr AND tl1==tl2;

miny=Status("axisminy");
maxy=Status("axismaxy");
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
LowMargin=Miny+GfxConvertPixelToValueY(lm);
HighMargin=Maxy-GfxConvertPixelToValueY(hm);
dyllm=GfxConvertPixelToValueY(dylm);
dyhhm=GfxConvertPixelToValueY(dyhm);
dyll=GfxConvertPixelToValueY(dyl);
dyhh=GfxConvertPixelToValueY(dyh);
dxllm=GfxConvertPixelsToBarX(dxlm);
dxhhm=GfxConvertPixelsToBarX(dxhm);
dxll=GfxConvertPixelsToBarX(dxl);
dxhh=GfxConvertPixelsToBarX(dxh);

dyllm2=GfxConvertPixelToValueY(dylm2);
dyll2=GfxConvertPixelToValueY(dyl2);
dyhhm2=GfxConvertPixelToValueY(dyhm2);
dyhh2=GfxConvertPixelToValueY(dyh2);

if(disp0)
{
for(i=0;i<AllVisibleBars;i++)
{
// HH,HL etc. labels
if(ll[i+fvb] AND L[i+fvb]>LowMargin) PlotText("LL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorDefault);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("LL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText("HL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("HL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText("DB",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("DB",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("HH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("HH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("LH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("LH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText("DT",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("DT",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorDefault);
}
}
if(disp1)
{
for(i=0;i<AllVisibleBars;i++)
{
// value labels at HH,HL etc.
if(ll[i+fvb] AND L[i+fvb]>LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll,L[i+fvb]-dyll2,colorWhite,colorDefault);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll+dxllm,L[i+fvb]-dyllm2,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll,L[i+fvb]-dyll2,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll+dxllm,L[i+fvb]-dyllm2,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll,L[i+fvb]-dyll2,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll+dxllm,L[i+fvb]-dyllm2,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh,H[i+fvb]+dyhh2,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm2,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh,H[i+fvb]+dyhh2,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm2,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh,H[i+fvb]+dyhh2,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm2,colorWhite,colorDefault);
}
}
if(disp2)
{
miny=LastVisibleValue(C)-LastVisibleValue(C)/100*perc;
maxy=LastVisibleValue(C)+LastVisibleValue(C)/100*perc;
for (i=1;i<=npiv;i++)
{
rr=ValueWhen(pk,H,i);
rr=IIf(rr>maxy OR rr<miny,Null,rr);
ss=ValueWhen(tr,L,i);
ss=IIf(ss>maxy OR ss<miny,Null,ss);
Plot(rr,"",colorBlue,styleNoLine|styleDots,0,0,0,-1);
Plot(ss,"",colorRed,styleNoLine|styleDots,0,0,0,-1);
}
}
if(disp3)
{
fiblevel[0]=0;fiblevel[1]=0.23;fiblevel[2]=0.38;fiblevel[3]=0.5;fiblevel[4]=0.62;
fiblevel[5]=0.78;fiblevel[6]=1;fiblevel[7]=1.27;fiblevel[8]=1.62;fiblevel[9]=2;
fiblevel[10]=2.62;fiblevel[11]=4.24;
rr=ValueWhen(pk,H,1);
ss=ValueWhen(tr,L,1);
delta=rr-ss;
fvb=Status("firstvisiblebar");
for(i=0;i<nlev;i++)
{
l1=IIf(Flip(tr,pk),ValueWhen(tr,ss+delta*fiblevel),Null);
Plot(l1,"",ColorRGB(255-15*i,0,0),1);
l2=IIf(Flip(pk,tr),ValueWhen(pk,rr-delta*fiblevel),Null);
Plot(l2,"",ColorRGB(0,255-15*i,0),1);
for(j=0;j<AllVisibleBars;j++)
{
if(tr[j+fvb]) PlotText(""+NumToStr(fiblevel),fvb+j,l1[fvb+j],colorWhite);
if(pk[j+fvb]) PlotText(""+NumToStr(fiblevel),fvb+j,l2[fvb+j],colorWhite);
}
}
}
 
I presume you also wish to do this WITHOUT using a formula that references zig zag
 
And for the 6 TH time .

Once you start referencing point 50%/38% etc from a high or low you'll be using a derivative of zig zag.
Defining a point of x % above or below an entry point won't help the look back scew.

But hey dream on.
 
Re: Amibroker FAQ (instead of creating a new thread I am asking here! :) )

Hi,
I am fairly new to Amibroker, just learning how to code AFL, backtesting etc etc. I want to use IB as my broker. I know Amibroker provides a "IB-Interface". However, can I perform order-management, risk-management, position-sizing in Amibroker (not for backtesting or optimisation). Or is there another piece of software that I will need in my workflow?
I.e. Amibroker (perform tech-analysis and send/export signals) --> Another software (read/import signals from amibroker, perform position sizing, order-management, talk to IB-TWS/Gateway etc etc) <<<--->>> Interactive-Broker

Advice and suggestions will be most appreciated.

Note: I have tried asking this question on Amibroker yahoogroup, its been two days since I asked the question and my question still does not appear on that yahoo group!
 
Re: Amibroker FAQ (instead of creating a new thread I am asking here! :) )

Hi,
I am fairly new to Amibroker, just learning how to code AFL, backtesting etc etc. I want to use IB as my broker. I know Amibroker provides a "IB-Interface". However, can I perform order-management, risk-management, position-sizing in Amibroker (not for backtesting or optimisation). Or is there another piece of software that I will need in my workflow?
I.e. Amibroker (perform tech-analysis and send/export signals) --> Another software (read/import signals from amibroker, perform position sizing, order-management, talk to IB-TWS/Gateway etc etc) <<<--->>> Interactive-Broker

Advice and suggestions will be most appreciated.

Note: I have tried asking this question on Amibroker yahoogroup, its been two days since I asked the question and my question still does not appear on that yahoo group!

The yahoo group is not a support channel, mail amibroker support directly, they are very quick to respond are very helpful.

That said, it should work.

Fwiw, be careful, if your asking questions like this then remember the devil is going to be in the detail.

I think you will find that IB is just a broker engine that supplies data and manages orders, all logic should remain in AB.
 
Hi all,

I have a back test question I'm sure has been answered or answered many times before. The answer will help find a solution to my own discretionary testing that I am trying to set up.

If you guys are backtesting on daily bars, how do your results determine if an entry was hit prior to the intraday low, which wouldve stopped you out, or after the low, in which case your still in the trade?

Do you have intraday data which the back test scans through removing this possible error?

If so, I am trying to find a complete intraday data supplier for Amibroker myself. Ideally with level 2 market depth. Can anyone please point to the right place?

Esignal don't supply level 2,
IB limits the no. of securities and historical data,

Is there a complete ASX data vendor out there for this purpose?

Thanks in advance.
 
Hi Youngeagle,

While i can't answer for Amibroker specifically, when i was using Multicharts for testing ideas i had to use intra-day data for entries and exits, while using the EOD data for my setups. The only way to 'look inside' a daily bar is to use Intra-day data. Otherwise you're just using the closing prices and assuming an exit on the close etc...

As far as your data goes, thats a tough ask of ASX data. I don't know of any data vendor that supplies what your are looking for, the kicker is the level II for ASX equities.

Good luck with that one!
 
Hi,
However, can I perform order-management, risk-management, position-sizing in Amibroker (not for backtesting or optimisation).

Sure.

You can also use IQFeed/esignal/.. as data feed and send orders to IB. You just configure the database to download data from IQFeed and run the auto-trading formula (it will only use IB for trading) - data interface and trading controller are totally separate.

You may however need to use e.g. Amibroker's ALIAS field for ticker names for IB-wise symbology in case of futures, options etc. as symbol names will be different in this case (so you can't refer to NAME() when placing orders).
 
Hi all,

I have a back test question I'm sure has been answered or answered many times before. The answer will help find a solution to my own discretionary testing that I am trying to set up.

If you guys are backtesting on daily bars, how do your results determine if an entry was hit prior to the intraday low, which wouldve stopped you out, or after the low, in which case your still in the trade?

Do you have intraday data which the back test scans through removing this possible error?

If so, I am trying to find a complete intraday data supplier for Amibroker myself. Ideally with level 2 market depth. Can anyone please point to the right place?

Esignal don't supply level 2,
IB limits the no. of securities and historical data,

Is there a complete ASX data vendor out there for this purpose?

Thanks in advance.

If you don't enter/exit on Open/Close but on stops then best way is to use intra-day data. You can't look from pure EOD bars to inside of a bar. No magician on Earth or from any other universal place will be able to get that info out of EOD bars. As for ASX data you could try asking the guys of PremiumData whether they know more about where to get it from.
 
Re: Amibroker FAQ (instead of creating a new thread I am asking here! :) )

Hi,
I am fairly new to Amibroker, just learning how to code AFL, backtesting etc etc. I want to use IB as my broker. I know Amibroker provides a "IB-Interface". However, can I perform order-management, risk-management, position-sizing in Amibroker (not for backtesting or optimisation). Or is there another piece of software that I will need in my workflow?
I.e. Amibroker (perform tech-analysis and send/export signals) --> Another software (read/import signals from amibroker, perform position sizing, order-management, talk to IB-TWS/Gateway etc etc) <<<--->>> Interactive-Broker

Advice and suggestions will be most appreciated.

Note: I have tried asking this question on Amibroker yahoogroup, its been two days since I asked the question and my question still does not appear on that yahoo group!
This dude has created an AFL to send orders to Interactive Broker using IB data feed to Amibroker.

http://blog.tipster.ca/p/tipster-trendlines-3.html

This is not a recommendation as I have never tried it and one thing that I was unsure of is how an AFL buy and sell works with the IB data stream. If I tried it I would need to test it first to ensure trades execute correctly.

* I think intraday stock trading is a tough act. EOD analysis with a medium to longer term perspective is a smarter way to go.
 
Hi

StaticVarSet() / StaticVarGet() seems not work for Buy/sell signal
How to do let it to work for Buy/sell signal ?
use StrFormat() ?

ex:

if()
{

buy=a and b;

StaticVarSet(buy);
}

buy999= StaticVarGet(buy);

it is not work
 
Hi

StaticVarSet() / StaticVarGet() seems not work for Buy/sell signal
How to do let it to work for Buy/sell signal ?
use StrFormat() ?

ex:

if()
{

buy=a and b;

StaticVarSet(buy);
}

buy999= StaticVarGet(buy);

it is not work

Sure it won't work

Your staticvarset and staticvarget are wrong

This is more correct

StaticVarSet("My long entry", Buy);

buy999 = StaticVarGet("My long entry");
 
Sure it won't work

Your staticvarset and staticvarget are wrong

This is more correct

StaticVarSet("My long entry", Buy);

buy999 = StaticVarGet("My long entry");


I had modify it but it still not work.

buy999 shows " {EMPTY} "

maybe StaticVarSet only for volume .

I try VarSet/VarGet too , it shows " {EMPTY} " too

ex:

if()
{
a=.......;
b=.........;
c=a + b;

StaticVarSet("c", c);


}

c = StaticVarGet("c"); <--------- it is ok , but c=( a and b) ; c= (a or b); both will shows {EMPTY}
 
Post the whole code not just parts of it. We don't know what you do so we can not reproduce.
And no, StaticVarSet is not for volume only.
 
Post the whole code not just parts of it. We don't know what you do so we can not reproduce.
And no, StaticVarSet is not for volume only.

Thank you very much, I had check it and it is whole issue not StaticVarSet,

The StaticVarSet will consume 8 * (number_of_bars) bytes of memory.
the code is ok for using StaticVarRemove() ?

a=1+1;
StaticVarSet("a", a );
a=StaticVarGet("a");
StaticVarRemove( "a" );
c=a+b; <------------------------------ a still there ?
 
Thank you very much, I had check it and it is whole issue not StaticVarSet,

The StaticVarSet will consume 8 * (number_of_bars) bytes of memory.
the code is ok for using StaticVarRemove() ?

a=1+1;
StaticVarSet("a", a );
a=StaticVarGet("a");
StaticVarRemove( "a" );
c=a+b; <------------------------------ a still there ?
a in your example will keep value

You could do this

Code:
b = 1;
a = 1 + 1;

d = Nz( StaticVarGet( "a" ) );

if ( Condition )
    StaticVarSet( "a", a  );
else
    StaticVarRemove( "a" );

c = d + b;

printf( "%g", c);
 
a in your example will keep value

You could do this

Code:
b = 1;
a = 1 + 1;

d = Nz( StaticVarGet( "a" ) );

if ( Condition )
    StaticVarSet( "a", a  );
else
    StaticVarRemove( "a" );

c = d + b;

printf( "%g", c);


Thank you very much.
The "if ( Condition )" I want to do like as follows:
It is ok ?

-----begin---------------

lasttimenum = StaticVarGet("lasttimenum");
Condition = ( Now( 4 ) - lasttimenum ) > 100 ;

d = Nz( StaticVarGet( "a" ) );

if ( Condition )
{
b = 1;
a = 1 + 1;
StaticVarSet( "a", a );
}
else
{
StaticVarRemove( "a" );
}
c = d + b;
-----end---------------


>>> On May 11, 2007, at 1:26 PM, Tomasz Janeczko wrote:
>>>
>>>> Hello,
>>>>
>>>> Then my advice is to use AddToComposite for computing intensive
>>>> task.
>>>>
>>>> lasttimenum = StaticVarGet("lasttimenum"); // if you want it chart-
>>>> specific you may add GetChartID() prefix/suffix
>>>>
>>>> if( ( Now( 4 ) - lasttimenum ) > 100 )
>>>> {
>>>> // one minute passed sincce last recalc
>>>>
>>>> .... // do computing intesive stuff here
>>>> result = .. .put your result array here
>>>>
>>>> AddToComposite( result, "~myresult", "x",
>>>> atcFlagEnableInIndicator | atcDefaults );
>>>> }
>>>>
>>>> // regular part that is executed all the time
>>>> result = Foreign("~myresult", "c" ); // this will retrieve values
>>>> of computing-intensive part calculated last time
>>>>
>>>>
>>>> Best regards,
>>>> Tomasz Janeczko
>>>> amibroker.com
 
Top