Cconvert script from Amibroker AFL to TOS?

heramone

New member
Here you go. could you please convert this below script to fit in TOS. This is Supply and Demand Indicator

Code:
_SECTION_BEGIN("Demand");
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",ColorRGB(85,90,60));
SetChartBkColor(bk);

amount = Param("Sensitivity", 0.5, 0.1, 2, 0.1 );

array = C ;
zz0 = Zig( array, amount );
zz1 = Ref( zz0, -1 );
zz2 = Ref( zz0, -2 );

tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1);
pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1);
PU = tr + 0.01 * abs(tr)*amount;
PD = pk - 0.01 * abs(pk)*amount;

ZZT = IIf( array >= PU AND zz0 > zz1, 1,
       IIf( array <= PD AND zz0 < zz1, -1, 0 ) );

ZZT = ValueWhen( ZZT != 0, ZZT );

Buy_Valid_=zzt>0;
Sell_Valid_=zzt<0;
Buy_Valid = ExRem(Buy_Valid_,Sell_Valid_);
Sell_Valid = ExRem(Sell_Valid_,Buy_Valid_);
Plot(Ref(Buy_valid,0),"",ColorRGB(0,0,100),styleHistogram|styleDashed|styleOwnScale|styleNoLabel,0,0,0,-1);
Plot(Ref(Sell_valid,0),"",ColorRGB(100,0,0),styleHistogram|styleDashed|styleOwnScale|styleNoLabel,0,0,0,-1);

Candlecol=IIf(BarsSince(Buy_Valid)<BarsSince(Sell_Valid) AND BarsSince(Buy_Valid)!=0,5,
          IIf(BarsSince(Buy_Valid)>BarsSince(Sell_Valid) AND BarsSince(Sell_Valid)!=0,4,1));
cc1=IIf(Buy_valid,colorYellow,IIf(Sell_valid,colorBlack,Candlecol));
SetBarFillColor(Cc1);
Plot(C,"Demand & Supply Zone AFL By NTA Blogger",Cc1,64,0,0,0,0);

pk=BarsSince(Buy_Valid)<BarsSince(Sell_Valid) ;//AND BarsSince(Buy_Valid)!=0;//Zz>Ref(zz,-1);
tr=BarsSince(Buy_Valid)>BarsSince(Sell_Valid) ;//AND BarsSince(Sell_Valid)!=0;//Zz<Ref(zz,-1);

Ll=LowestSince(sell_valid,L,1);
hH=HighestSince(Buy_Valid,H,1);
Llm=LowestSince(sell_valid,Min(O,C),1);
hHm=HighestSince(Buy_Valid,Max(O,C),1);

xx=Cum(1);
NoLines = Param("No of Lines",5,1,10,1);

Col2=ParamColor( "Res Color", colorRed );
Col1=ParamColor( "Sup Color", colorGreen );

for( i = 1; i < NoLines+1 ; i++ )
{
scol=ColorBlend(Col1,2,0.1*i);
rcol=ColorBlend(Col2,2,0.1*i);

px1 = LastValue(ValueWhen(Buy_valid,Cum(1),i)) ;
py1 = LastValue(ValueWhen(Buy_valid,Ll,i)) ;
pz1 = LineArray(px1, py1, (BarCount-1), py1);
Plot(pz1,"",scol,32);

tx1 = LastValue(ValueWhen(sell_valid,Cum(1),i)) ;
ty1 = LastValue(ValueWhen(sell_valid,Hh,i)) ;
tz1 = LineArray(tx1, ty1, (BarCount-1), ty1);
Plot(tz1,"",rcol,32);

px1m = LastValue(ValueWhen(Buy_valid,Cum(1),i)) ;
py1m = LastValue(ValueWhen(Buy_valid,Llm,i)) ;
pz1m = LineArray(px1m, py1m, (BarCount-1), py1m);
PlotOHLC(pz1,pz1,pz1m,pz1m,"",scol,styleCloud|styleNoLabel,0,0,0,-i-nolines);

tx1m = LastValue(ValueWhen(sell_valid,Cum(1),i)) ;
ty1m = LastValue(ValueWhen(sell_valid,Hhm,i)) ;
tz1m = LineArray(tx1m, ty1m, (BarCount-1), ty1m);
PlotOHLC(tz1,tz1,tz1m,tz1m,"",rcol,styleCloud|styleNoLabel,0,0,0,-i-nolines);
}

for( j = 0; j < BarCount; j++ )
{
if( Buy_valid [j])  PlotText( "Dz\n"+Ll[ j ], j, Ll[j], colorPaleGreen );
if( Sell_valid[j] ) PlotText( "Sz\n"+Hh[ j ], j, Hh[j], colorRose);
}
_SECTION_END();
 
Last edited by a moderator:

Koolkth1

New member
people like me can convert it, it just helps to know what the expected benefits are otherwise it probably won't benefit anyone that's trying to help.

I just came across this thread from searching for "Supply and Demand Zones". This indicator would greatly help since these are historic zones where institutional buyers/sellers step in. By identifying these zones one can step and buy/sell when the institutions are buying/selling and move with the higher volume.
 

chaser2009

New member
Hello,


Can some convert the following Amibroker AFL to TOS?

Thanks


tf= IIf(ST > BBandTop(C,20,0.5),1, IIf(ST<BBandTop(C,20,0.5) AND ST>BBandBot(C,20,0.5),0,-1))*10;

td=(tf+100)/2;
Colortf=IIf(td>50,colorBlue,IIf(td<50,colorRed,colorgreen));

Plot(td,"TREND",colortf ,styleDots);
 

rad14733

Well-known member
VIP
@chaser2009 What does the code do...??? Do you have an image...??? The code may already exist here in the forums... Far too many members are just asking to have code converted for them and it's getting out of control...
 

XeoNoX

Well-known member
VIP
Hello,


Can some convert the following Amibroker AFL to TOS?

Thanks


tf= IIf(ST > BBandTop(C,20,0.5),1, IIf(ST<BBandTop(C,20,0.5) AND ST>BBandBot(C,20,0.5),0,-1))*10;

td=(tf+100)/2;
Colortf=IIf(td>50,colorBlue,IIf(td<50,colorRed,colorgreen));

Plot(td,"TREND",colortf ,styleDots);
if you put the code in AFL Code wizard it will tell you what the script does and you can post back here so someone can try and convert it, it appears to be some kinda of simple bollinger band script.
 

chaser2009

New member
_SECTION_BEGIN("");
tf= IIf(C > BBandTop(C,20,0.5),1, IIf(C<BBandTop(C,20,0.5) AND C>BBandBot(C,20,0.5),0,-1))*10;

td=(tf+100)/2;
Colortf=IIf(td>50,colorBlue,IIf(td<50,colorRed,colorgreen));

Plot(td,"Trend",colortf ,styleDots);
_SECTION_END();

-----------------------------------------------------------------------------
Sorry. This is the correct code, but I don't have access to AFL Code Wizard. I posted a picture, but I'm having trouble attaching it here, so there's the link for it. The indicator is on the bottom of the picture.


Thank you very much!
 

rad14733

Well-known member
VIP
@chaser2009 I'm fairly certain that code is just a trending Bollinger Band midline... I'm not familiar with AMI Broker code so I'm not going to even entertain a conversion... But by looking at the dotted line in the image provided it just looks like a trending midline... That can be easily coded into the standard TOS Bollinger Band Study... We have plenty of code to use as an example of how to change plot color based on trend so with a little effort you can make the modifications...
 

XeoNoX

Well-known member
VIP
like rad said youre going to have to explain what it does unless you get lucky enough to find a thinkscripter and amni pro coder that knows both languages. I would assume if you use it that you should know how it works to be able to explain it
 

chaser2009

New member
like rad said youre going to have to explain what it does unless you get lucky enough to find a thinkscripter and amni pro coder that knows both languages. I would assume if you use it that you should know how it works to be able to explain it
I found out the meaning in AFL now.

1, if Close>BBandTop(C,20,0.5) then return 1,
2, if Close<BBandTop(C,20,0.5) and Close>BBandBot(C,20,0.5) then return 0, else return -1.

BBandTop is Upper Bollingerband
BBandBot is Lower Bollingerband

Sorry, I am the new to this, I am getting close to understanding.

Thank you
 

chaser2009

New member
I found out the meaning in AFL now.

1, if Close>BBandTop(C,20,0.5) then return 1,
2, if Close<BBandTop(C,20,0.5) and Close>BBandBot(C,20,0.5) then return 0, else return -1.

BBandTop is Upper Bollingerband
BBandBot is Lower Bollingerband

Sorry, I am the new to this, I am getting close to understanding.

Thank you
I think I figured it out by myself. Thank you everyone for responding and for helping me!
 

rad14733

Well-known member
VIP
I found out the meaning in AFL now.

1, if Close>BBandTop(C,20,0.5) then return 1,
2, if Close<BBandTop(C,20,0.5) and Close>BBandBot(C,20,0.5) then return 0, else return -1.

BBandTop is Upper Bollingerband
BBandBot is Lower Bollingerband

Sorry, I am the new to this, I am getting close to understanding.

Thank you

Yes, we knew that much which is why I stated that it looked like a Bollinger Band midline... As @XeoNoX mentioned, please post your working code to give back to the community...
 

chaser2009

New member
post your final code back on here, maybe you can help someone else out in the future.
declare Lower;

input averageType = AverageType.SIMPLE;

def upperBand = BollingerBands(close, 0, 20, -0.5, 0.5, averageType).UpperBand;
def lowerBand = BollingerBands(close, 0, 20, -0.5, 0.5, averageType).LowerBand;

def t=if close>upperband then 1 else 0;
def b=if close<lowerband then -1 else 0;
plot td=t+b;
plot center=0;

Sorry for the delay, hope someone will like!

Thank you!
 

Similar threads

Top