Simple Coding Help - No Promise.

Only small help and modifications,as specified by the thread owner

Similar Stochastic code,courtesy wisestocktrader site......................

http://www.wisest ocktra der.com/indicators/1149-stochastic
Code:
_SECTION_BEGIN("Stochastic");
 
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
myStochD=StochD( periods , Ksmooth, DSmooth );
myStochK=StochK( periods , Ksmooth);
Overbought=80;
Oversold=20;
 
Buy = Cross(myStochK, myStochD );
Sell = Cross( myStochD, myStochK );
 
Plot( myStochD, "Stochastic %D"+_PARAM_VALUES(), ParamColor( "ColorD", colorRed ), ParamStyle("StyleD") );
Plot( myStochK, "Stochastic %K", ParamColor( "ColorK", colorGreen ), ParamStyle("StyleK") );
 
PlotShapes(IIf(Sell, shapeHollowDownArrow , shapeNone), colorRed);
PlotShapes(IIf(Buy, shapeHollowUpArrow , shapeNone), colorBlue);
 
Plot(Overbought,"Overbought Level",colorRed);
Plot(Oversold,"Oversold Level",colorGreen); 
 
 
PlotOHLC( myStochK,myStochK,50,myStochK, "", colorRed, styleCloud | styleClipMinMax, 20, 80 );
PlotOHLC( myStochD,myStochD,50,myStochD, "", colorYellow, styleCloud | styleClipMinMax, 20, 80 );
 
PlotOHLC( Null,myStochD,myStochK,Null, "", colorBlue, styleCloud); 
 
 
_SECTION_END();
thanks for your help , but this is only plot stochastic !! ,i need translate this loop to amibroker .for floating level . please

MySto = oSlowK;
min = 100;
max = 0;
for value1=0 to MinMaxPeriod-1 begin
if min>MySto[value1] then min=MySto[value1];
if max<MySto[value1] then max=MySto[value1];
end;

range = max-min;
 
Hey,

I have a question .
Is it possible to make backtesting afl or settings.
There your condition is :
target should be reached in next 5 candlestick .. and give results according to that .. .

Target = next 5 bars i.e. Nifty 5 point ..

How to do it?

regards
mtftrader
 
Amibrokers Default Zigzag tool and the tool from your 2nd link is not like in my image.
It doesnt draw a line on candles.
Code:
pr=Param("ZigZag change amount", 5, 0.1,100,0.1);
pk=PeakBars(H,pr)==0;
tr=TroughBars(L,pr)==0;
zzHi=Zig(H,pr);
zzLo=Zig(L,pr);
Avg=(zzHi+zzLo)/2;
x=IIf(pk,zzHi,IIf(tr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
zzHiLo=Zig(x,pr);
Plot( zzHiLo, "", ParamColor("Color",colorRed), ParamStyle("Style"));
Not perfect but almost, will plot Zig-Zag on High/Low.

But as Amit has said above not really useful for trading as it looks into future


Happy :)
 
Hey,

I have a question .
Is it possible to make backtesting afl or settings.
There your condition is :
target should be reached in next 5 candlestick .. and give results according to that .. .

Target = next 5 bars i.e. Nifty 5 point ..

How to do it?

regards
mtftrader
Anyone?
lot of people do backtesting,i'm sure you come up with this case already.
Mbacktesting Target: next 5 point of nifty in next 5 bar.

regards
mtftrader
 
Anyone?
lot of people do backtesting,i'm sure you come up with this case already.
Mbacktesting Target: next 5 point of nifty in next 5 bar.

regards
mtftrader
You can use ApplyStop function as follows

ApplyStop( stopTypeNBar, stopModeBars, 5 );

OR


Buy = xxxxx ..... Whatever your entry condition may be ....
Sell = BarsSince(Buy) == 5;
 

trash

Well-Known Member
You can use ApplyStop function as follows

ApplyStop( stopTypeNBar, stopModeBars, 5 );

OR


Buy = xxxxx ..... Whatever your entry condition may be ....
Sell = BarsSince(Buy) == 5;
I hope you understand that those two examples are not the same and behave differently. The 2nd one may lead to undesired results (and users not understanding it). If you don't know what I mean then I will explain.

Long story short, the only proper way of coding stops is using ApplyStop() or loop (custom stops not being implemented in Applystop).
 
I hope you understand that those two examples are not the same and behave differently. The 2nd one may lead to undesired results (and users not understanding it). If you don't know what I mean then I will explain.

Long story short, the only proper way of coding stops is using ApplyStop() or loop (custom stops not being implemented in Applystop).
Please go ahead and share what you think is a problem.
 

trash

Well-Known Member
I'm quite surprised you don't know that there is a difference between both versions since it is rather a mistake beginners do thinking that both versions were the same ones. No,they are not.

OK. Well, the problem is that in your second example if a new buy arrives (without a preceding sell) then it is resetting barssince to zero!

What does that mean in practice?

Suppose you have a simple buy signal as follows

Code:
period = 20; // number of averaging periods 
m = MA( Close, period ); // simple moving average
Buy = C > m; // buy when close is ABOVE of moving average
So if price is above of ma you will receive buy signal on every new bar being above of MA.

Now if using ApplyStop it takes care of that to get desired classic n-bar exit after 5 bars.

Code:
Sell = 0;

ApplyStop( stopTypeNBar, stopModeBars, 5, True );

If( Status( "action" ) == actionIndicator ) {
	Equity(1); // evaluates stops for Applystop

	Plot( C, "Price", colorDefault, styleCandle );
	Plot( m, "MA", colorRed, styleLine );

	NBarStop = Sell == 5;

	PlotShapes( Buy * shapeUpArrow + NBarStop * shapeDownArrow,
				IIf( Buy, colorGreen, colorRed ), layer = 0,
				y = IIf( Buy, L, H ), dist = -12 );
}

Example picture


Now what happens if instead we use barssince with such extending buy signal? So we comment ApplyStop and use standard sell rule.

Code:
Sell = BarsSince( Buy ) == 5;

//ApplyStop( stopTypeNBar, stopModeBars, 5, True );

If( Status( "action" ) == actionIndicator ) {
	Equity(1);  // evaluates stops for Applystop

	Plot( C, "Price", colorDefault, styleCandle );
	Plot( m, "MA", colorRed, styleLine );

	BarStop = Sell == 1;

	PlotShapes( Buy * shapeUpArrow + BarStop * shapeDownArrow,
				IIf( Buy, colorGreen, colorRed ), layer = 0,
				y = IIf( Buy, L, H ), dist = -12 ); 

}
We get a rather undesired result.



Now you might think it is a bug. No, it isn't.

If commenting Equity(1); line (which removed excessive signals) then we get visually shown to us the reason as explained above -> new buy signals (appearing before 5 bars are reached) reset barssince to zero.



So if you want classic n-bar stop then never ever use BarsSince as n-bar stop.
 

Similar threads