Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Kase Dev Stops V1 – Amibroker AFL Code

1 min read

What is a Kase Dev Stops?

Kase Dev Stops is a volatility based stop and Dev Stops refers to the Standard Deviation based Stops and uses ATR based volatility. Kase DevStops provide a statistically sound basis upon which to place stop-loss and stop and-reverse orders.

“A STOP THAT IS GOING TO PERFORM OPTIMALLY MUST CONSIDER THE VARIABILITY OF RANGE.”

CYNTHIA KASE
//Kase Dev Stop V1 - translated from Tradingview Pinescript
//Credits : https://www.tradingview.com/script/wF0Cm55t-Kase-Dev-Stops/
//Coder : Rajandran R
//Website : www.algomojo.com / www.marketcalls.in
//Date : 5th Mar 2022

_SECTION_BEGIN("Kase Dev Stop v1");

Length = param("Length",30,5,100,5);
Length1 = param("Length1",20,5,100,5);

inpStdDev1    = 0.0;         // Deviation 1
inpStdDev2    = 1.0;         // Deviation 2
inpStdDev3    = 2.0;         // Deviation 3
inpStdDev4    = 3.0;         // Deviation 4

RWH = (high - Ref(Low,-Length)) / (atr(Length) * sqrt(Length));
RWL = (Ref(high,-Length) - low) / (atr(Length) * sqrt(Length));

Pk = wma((RWH-RWL),3);

trendcolor = IIf(pk>0,colorGreen,colorRed);

AVTR = ma(hhv(high,2) - llv(low,2), Length1);
SD = stdev(hhv(high,2) - llv(low,2),Length1);

val0 = IIf(pk>0, hhv(high-AVTR-inpStdDev1*SD,Length1), llv(low+AVTR+inpStdDev1*SD,Length1));
val1 = IIf(pk>0, hhv(high-AVTR-inpStdDev2*SD,Length1), llv(low+AVTR+inpStdDev2*SD,Length1));
val2 = IIf(pk>0, hhv(high-AVTR-inpStdDev3*SD,Length1), llv(low+AVTR+inpStdDev3*SD,Length1));
val3 = IIf(pk>0, hhv(high-AVTR-inpStdDev4*SD,Length1), llv(low+AVTR+inpStdDev4*SD,Length1));




Plot(val0,"Val0",trendcolor,styleDots);
Plot(val1,"Val1",trendcolor,styleDots);
Plot(val2,"Val2",trendcolor,styleDots);
Plot(val3,"Val3",trendcolor,styleLine);

SetChartOptions(0, chartShowArrows | chartShowDates); //x-Axis will be plottted
//plot the candles
Plot(Close,"Close",colorDefault,styleCandle | styleNoTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));


Buy = pk>0 AND Close>val0;
Sell = (pk<0 AND Close<val0) OR (pk>0 AND Close<val3);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Short = (pk<0 AND Close<val0);
Cover = (pk>0 AND Close>val0) OR (pk<0 AND Close>val3);

Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

//Non Repainting  - Signals happens only after the close of the current
Buy = Ref(Buy,-1);
Sell = Ref(Sell,-1);
Short = Ref(Short,-1);
Cover = Ref(Cover,-1);

BuyPrice = ValueWhen(Buy,Open);
SellPrice = ValueWhen(Sell,Open);
ShortPrice = ValueWhen(Short,Open);
CoverPrice = ValueWhen(Cover,Open);

SetPositionSize(1*RoundLotSize,spsShares);
//SetPositionSize(200000,spsValue);

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(Sell * shapestar, colorBrightGreen, 0, High, 12);
PlotShapes(Cover * shapestar, colorRed, 0, Low, -12);




_SECTION_END();

Nifty Futures Hourly Long Only Trading System – Equity Curve

Nifty Futures Hourly Long Only Trading System – Drawdown

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Stoploss, Multi Target, and Trailing Stoploss Module – Amibroker…

After Intraday V2.0 Amibroker Module - a readymade drag and drop module to convert any trading strategy into the intraday trading system with alerts,...
Rajandran R
6 min read

Line Trading – Algomojo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
58 sec read

Plotting Day Wise Equity Curve using Amibroker

We know that Amibroker provides an equity curve for the whole strategy. Is there a way where we can build a simple Day Wise...
Rajandran R
1 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More