Simple Coding Help - No Promise.

its not working houmansat sir
It is working
Code:
_SECTION_BEGIN("New formula 75");
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,"Cas-S_D-Zone",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( "Tr\n"+Ll[ j ], j, Ll[j], colorPaleGreen ); 
if( Sell_valid[j] ) PlotText( "Pk\n"+Hh[ j ], j, Hh[j], colorRose); 
} 
_SECTION_END();
 
_SECTION_BEGIN("Bollinger Bands");

_SECTION_BEGIN("DispMA");
P = ParamField("Field");
Type = ParamList("Type", "Simple,Exponential,Double Exponential,Tripple Exponential,Wilders,Weighted");
Periods = Param("Periods", 8, 2, 300 );
Displacement = Param("Displacement", 3, -50, 50 );
m = 0;

if( Type == "Simple" ) m = MA( P, Periods );
if( Type == "Exponential" ) m = EMA( P, Periods );
if( Type == "Double Exponential" ) m = DEMA( P, Periods );
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods );
if( Type == "Wilders" ) m = Wilders( P, Periods );
if( Type == "Weighted" ) m = WMA( P, Periods );

Plot( m, _DEFAULT_NAME(), ParamColor("Color", ColorCycle), ParamStyle("Style"), 0, 0, Displacement );
_SECTION_END();



P=m ;
//P = ParamField("Price field",-1);
Periods = Param("Periods", 8, 2, 300, 1 );
Width = Param("Width", 1, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
_SECTION_END();

MA8 = MA(C,8);
//Plot(MA8,"MA8",colorRed,styleThick);
_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

dear all
can any one add buy signal above top bollinger band
and sell below at bottom bollinger band
with arrow pls
 
Hi Senior Mmber and Happy Sir

Can you please let me know how to plot the below trailing stop loss in Amibroker

Trailng stop : Highest low(taking highest low of every bar) - atr(20)
 
Last edited:
Hey Guys...! This is a very simple stupid AFL sintaxis-logic question, but Im a little bit rusty to digg quite inside. I would like to "ReWrite" the NVI() PVI() functions, in order to change some of the internals, in this case the "Close ROC" originally propossed by Fosback.

In my attempt, I want to use AvgPrice range, my initial formula is based on an algorithm found on TradingViews, given funcitons used as well on AFL Ami's! Here is the code that currently give errors:

Code:
_SECTION_BEGIN("Modded Negative Volume Index");
function xNVI()
{
	xROC = ROC(Avg,1);
	xNVI = IIf(V < Ref(V,-1), Nz(Ref(xNVI,-1),0) + xROC, Nz(Ref(xNVI,-1),0));
	return xNVI	;
}
Plot( xNVI(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style")  );

_SECTION_END();
Thaks in Advance! :thumb:
 

trash

Well-Known Member
Hey Guys...! This is a very simple stupid AFL sintaxis-logic question, but Im a little bit rusty to digg quite inside. I would like to "ReWrite" the NVI() PVI() functions, in order to change some of the internals, in this case the "Close ROC" originally propossed by Fosback.

In my attempt, I want to use AvgPrice range, my initial formula is based on an algorithm found on TradingViews, given funcitons used as well on AFL Ami's! Here is the code that currently give errors:

Code:
_SECTION_BEGIN("Modded Negative Volume Index");
function xNVI()
{
	xROC = ROC(Avg,1);
	xNVI = IIf(V < Ref(V,-1), Nz(Ref(xNVI,-1),0) + xROC, Nz(Ref(xNVI,-1),0));
	return xNVI	;
}
Plot( xNVI(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style")  );

_SECTION_END();
Thaks in Advance! :thumb:
Ref() is not for self referencing! It is an array function. It is applied on whole array at once.

For self referencing equations you may use loop.

Code:
_SECTION_BEGIN( "Modded Negative Volume Index" );
// fixed self referencing  by trash
function xNVI(array)
{
    xROC = ROC( array, 1 );
    Vcond = ROC( V, 1 ) < 0;

    _NVI = 0; // initialize _NVI

    for ( i = 1; i < BarCount; i++ )
    {
        prevNVI = _NVI[ i - 1 ]; // previous value of _NVI

        if ( Vcond[i] )
            _NVI[ i ] = prevNVI + xROC[ i ];
        else
            _NVI[ i ] = prevNVI;
    }

    return _NVI + 100;
}

Plot( xNVI(Avg), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle( "Style" ) );
_SECTION_END();
 
Last edited:

trash

Well-Known Member
Hey Guys...! This is a very simple stupid AFL sintaxis-logic question, but Im a little bit rusty to digg quite inside. I would like to "ReWrite" the NVI() PVI() functions, in order to change some of the internals, in this case the "Close ROC" originally propossed by Fosback.

In my attempt, I want to use AvgPrice range, my initial formula is based on an algorithm found on TradingViews, given funcitons used as well on AFL Ami's! Here is the code that currently give errors:

Code:
_SECTION_BEGIN("Modded Negative Volume Index");
function xNVI()
{
	xROC = ROC(Avg,1);
	xNVI = IIf(V < Ref(V,-1), Nz(Ref(xNVI,-1),0) + xROC, Nz(Ref(xNVI,-1),0));
	return xNVI	;
}
Plot( xNVI(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style")  );

_SECTION_END();
Thaks in Advance! :thumb:
But you could also use this approach shown by Tomasz http://www.amibroker.com/kb/2014/11/04/indicators-based-on-user-values/
to use a custom array other than Close for functions that work on Close by default.

In your case it would be

Code:
_SECTION_BEGIN( "Modded Negative Volume Index" );
//http://www.amibroker.com/kb/2014/11/04/indicators-based-on-user-values/

procedure SaveRestorePrices( DoSave )
{
  global SaveO, SaveH, SaveL, SaveC, SaveV;
  
  if( DoSave )
  {
     SaveO = Open;
     SaveH = High;
     SaveL = Low;
     SaveC = Close;
     SaveV = Volume;
  }
  else
  {
    Open = SaveO;
    High = SaveH;
    Low = SaveL;
    Close = SaveC;
    Volume = SaveV;
  }
}

// save OHLCV arrays
SaveRestorePrices( True );

// calculate our array
customArray = Avg;

// override built-in array(s)
Close = customArray;

// calculate our function, MACD and Signal in this case
Plot( NVI(), "NVI", colorRed );

// restore OHLCV arrays
SaveRestorePrices( False );
_SECTION_END();
 
Ref() is not for self referencing! It is an array function. It is applied on whole array at once.

For self referencing equations you may use loop.

Code:
_SECTION_BEGIN( "Modded Negative Volume Index" );
// fixed self referencing  by trash
function xNVI(array)
{
    xROC = ROC( array, 1 );
    Vcond = ROC( V, 1 ) < 0;

    _NVI = 0; // initialize _NVI

    for ( i = 1; i < BarCount; i++ )
    {
        prevNVI = _NVI[ i - 1 ]; // previous value of _NVI

        if ( Vcond[i] )
            _NVI[ i ] = prevNVI + xROC[ i ];
        else
            _NVI[ i ] = prevNVI;
    }

    return _NVI + 100;
}

Plot( xNVI(Avg), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle( "Style" ) );
_SECTION_END();

That's what I try to found somewhere, the "loop" method to rewrite the function itself! Just something I noted:

The algorithm itself plots "same pattern" as the built in NVI() formula at Ami, but given some time; the Ami indicator index growth much more than the one your wrote with the same array CLOSE.

Eventhough this little issue, the function plots what it supposed to plot given this mathematical criteria!

Thanks a lot Trash! :clap:
 

Similar threads