Modified Ichimoku With Buy Sell Signals

Modified Ichimoku With Buy Sell Signals
Modified Ichimoku With Buy Sell Signals

//www.aflcode.com

//////////////////////////////
// 1) Tenkan-Sen = Conversion Line = (Highest High + Lowest Low) / 2, for the past 9 periods
// 2) Kijun-Sen = Base Line = (Highest High + Lowest Low) / 2, for the past 26 periods
// 3) Chikou Span = Lagging Span = Today's closing price plotted 26 periods behind
// 4) Senkou Span A = Leading Span A = (Tenkan-Sen + Kijun-Sen) / 2, plotted 26 periods ahead
// 5) Senkou Span B = Leading Span B = (Highest High + Lowest Low) / 2, for the past 52 periods, plotted 26 periods ahead
// Kumo = Cloud = Area between Senkou Span A AND B
//////////////////////////////


_SECTION_BEGIN("Price");
HAswitch = ParamToggle("Heikin Ashi","Off,On");
PriceUpCol = ParamColor("Price UP Color",colorGreen);
PriceDnCol = ParamColor("Price DN Color",colorRed);
PriceSty = ParamStyle("Price Style",styleCandle,maskDefault | styleCandle | styleBar);

HaClose = ( O+H+L+C ) / 4;
HaOpen = AMA( Ref(HaClose, -1), 0.5);
HaHigh = Max(H, Max(HaClose, HaOpen));
HaLow = Min(L, Min(HaClose, HaOpen));

if(HAswitch)
PlotOHLC(HaOpen,HaHigh,HaLow,HaClose,"Heikin Ashi",IIf(HaClose > HaOpen,PriceUpCol,PriceDnCol),PriceSty);
else
Plot(C,"Price",IIf(C > Ref(C,-1), PriceUpCol, PriceDnCol), PriceSty);
_SECTION_END();

_SECTION_BEGIN("Tenkan-Sen");
TenkanPer = Param("Tenkan-Sen Period",9,1,100,1);
TenkanCol = ParamColor("Tenkan-Sen Color",colorRed);
TenkanSty = ParamStyle("Tenkan-Sen Style",styleLine | styleThick);
Tenkan = ( HHV(H,TenkanPer) + LLV(L,TenkanPer) ) / 2;
Plot(Tenkan,"Tenkan",TenkanCol,TenkanSty);
_SECTION_END();

_SECTION_BEGIN("Kijun-Sen");
KijunPer = Param("Kijun-Sen Period",26,1,100,1);
KijunCol = ParamColor("Kijun-Sen Color",colorBlue);
KijunSty = ParamStyle("Kijun-Sen Style",styleLine | styleThick);
Kijun = ( HHV(H,KijunPer) + LLV(L,KijunPer) ) / 2;
Plot(Kijun,"Kijun",KijunCol,KijunSty);
_SECTION_END();

_SECTION_BEGIN("Chikou Span");
ChikouShft = Param("Chikou Span Shift",26,1,100,1);
ChikouCol = ParamColor("Chikou Span Color",colorViolet);
ChikouSty = ParamStyle("Chikou Span Style",styleLine | styleNoLabel);
Chikou = C;
Plot(Chikou,"",ChikouCol,ChikouSty,Null,Null,-ChikouShft);
_SECTION_END();

_SECTION_BEGIN("Senkou-Kumo");
SenkouKumoShft = Param("Senkou-Kumo Shift",26,0,100,1);
_SECTION_END();

_SECTION_BEGIN("Senkou Span A");
SenkouACol = ParamColor("Senkou Span A Color",colorSeaGreen);
SenkouASty = ParamStyle("Senkou Span A Style",styleLine);
SenkouA = ( Tenkan + Kijun ) / 2;
Plot(SenkouA,"Senkou A",SenkouACol,SenkouASty,Null,Null,SenkouKumoShft);
_SECTION_END();

_SECTION_BEGIN("Senkou Span B");
SenkouBPer = Param("Senkou Span B Period",52,1,200,1);
SenkouBCol = ParamColor("Senkou Span B Color",colorPink);
SenkouBSty = ParamStyle("Senkou Span B Style",styleLine);
SenkouB = ( HHV(H,SenkouBPer) + LLV(L,SenkouBPer) ) / 2;
Plot(SenkouB,"Senkou B",SenkouBCol,SenkouBSty,Null,Null,SenkouKumoShft);
_SECTION_END();

_SECTION_BEGIN("Kumo");
KumoUpCol = ParamColor("Kumo UP Color",colorSeaGreen);
KumoDnCol = ParamColor("Kumo DN Color",colorPink);
PlotOHLC(SenkouA,SenkouA,SenkouB,SenkouB,"",IIf(SenkouA>SenkouB,KumoUpCol,KumoDnCol),styleCloud | styleNoLabel,Null,Null,SenkouKumoShft);
_SECTION_END();

_SECTION_BEGIN("BK");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor( ParamColor("Color Axes", colorBlack) ); 
SetChartBkGradientFill( ParamColor("BgTop", colorWhite),ParamColor("BgBottom", colorDarkGrey));
_SECTION_END();

_SECTION_BEGIN("AuthorName");
k = (GetPerformanceCounter()/100)%100; 
printf("GetPerformance Counter %g",k);
GfxSelectFont("comics", 14,800); 
GfxSetBkMode(1); 
GfxSetTextColor(colorWhite); 
GfxTextOut("ABDEL01S",-10+k,20); 
RequestTimedRefresh(10); 
_SECTION_END();

//------------------------------------------------------
//
//  Formula Name:    Volume Breakout Trading System
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

SetBarsRequired(200, 0);
_SECTION_BEGIN("TA signal ");

GraphXSpace = 5;
SetChartOptions(0, chartShowArrows|chartShowDates);
k = Optimize("K", Param("A (Change To Optimise)", 1.75, 0.25, 5, 0.25), 0.25, 5, 0.25);
Per= Optimize("ATR", Param("B (Change To Optimise)", 10, 3, 20, 1), 3, 20, 1);
CloseAtEnd = ParamToggle("Close Positions EOD", "No|Yes");
ShowBands = ParamToggle("Show Trending Bands", "No|Yes");
ShowPivots = ParamToggle("Show Pivot High/Low", "No|Yes");
SetChartBkGradientFill( ParamColor("BgTop", colorDarkOliveGreen), ParamColor("BgBottom", colorRose), ParamColor("titleblock", colorRose ));
//Param_Margin = Param("Margin required (used for backtesting only)", 15, 0.001, 100, 0.001);
//Param_LotSize = Param("Lot Size (used for backtesting only)", 50, 5, 5000, 5);
//Param_NoOfLots = Param("No of lots normally traded (used for backtesting only)", 2, 1, 10000, 1);

R=(H-L);//RANGE;

FR=(H-L)/3;//THIRD OF RANGE;

S1=H-FR;//SEGMENT ONE;

S2=H-2*FR;//SEGMENT TWO;

S3=L;//SEGMENT THREE;

/*POSITION OF OPEN AND CLOSE RELATIVE TO BAR*/

P=IIf(O>S1, 1, IIf(S1>O<S2, 2, IIf(S2>O<L, 3, 0)));// POSITION OF OPENING PRICE ;

CL=IIf(C>S1, 1, IIf(S1>C<S2, 2, IIf(S2>C<L, 3, 0)));// POSITION OF CLOSING PRICE;

/*CONDITIONAL STATEMENTS */


COND_C=((P==2 OR P==3) AND CL==1) OR (P==3 AND (CL==1 OR CL==2)); //CLIMBERS(eq. 1)

COND_C=(P==2 /*OR P==3)*/ AND CL==1) OR (P==3 AND (CL==1 OR CL==2));//CLIMBERS (eq. 1a)


COND_D=(P==1 AND (CL==2 OR CL==3)) OR (P==2 AND (CL==2 OR CL==3));//DRIFTERS

COND_N=((P==CL) AND ( P==1 OR P==2 OR P==3)); //NEUTRAL BARS

DYNAMIC_COLOR=IIf(COND_C, colorDarkGreen, IIf(COND_D, colorRed, IIf(COND_N, colorBlue, colorTeal)));

PlotOHLC( Open, High, Low, Close, "Price chart ", DYNAMIC_COLOR, styleCandle, styleThick);

HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
j=Haclose;

//================================================== ================================================== ===================
//=========================Indicator================ ================================================== ============================
f=ATR(14);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;


for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j[i] < NW[i-1])
{
Trend[i] = -1;
NW[i] = j[i] + Revers[i];
}
else
{
Trend[i] = 1;
if((j[i] - Revers[i]) > NW[i-1])
{
NW[i] = j[i] - Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j[i] > NW[i-1])
{
Trend[i] = 1;
NW[i] = j[i] - Revers[i];
}
else
{
Trend[i] = -1;
if((j[i] + Revers[i]) < NW[i-1])
{
NW[i] = j[i] + Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
}

activezone=ADX(14) >20 AND V> MA(V, 60);
calmzone=ADX(14) < 20 AND V < MA(V, 60);


Plot( 2, /* defines the height of the ribbon in percent of pane width
*/"ribbon",
IIf( activezone, colorBlue, IIf( calmzone, colorYellow, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

//===============system================

ForceCloseTradesAfter = 153000;

NextBarOutsideRTH = (Ref(TimeNum(), 1) > ForceCloseTradesAfter);
NextBarNotToday = (Ref(DateNum(), 1) > DateNum());
Buy=Cross(j, nw);
Short=Cross(nw, j);
Sell=IIf(CloseAtEnd==False, Short, Short OR NextBarOutsideRTH OR NextBarNotToday);
Cover=IIf(CloseAtEnd==False, Buy, Buy OR NextBarOutsideRTH OR NextBarNotToday);

SellPrice=ValueWhen(Short, C, 1);
BuyPrice=ValueWhen(Buy, C, 1);
Long=Flip(Buy, Sell);
Shrt=Flip(Short, Cover);

OBSetting=Param("Setting", 45, 1, 500, 1);
Bline = StochD(OBSetting);
Oversold=Bline<=5;
Overbought=Bline>=95;


PlotShapes (IIf(Oversold, shapeSmallCircle, shapeNone), colorBrightGreen, layer = 0, yposition = HaLow, offset = -8 );
PlotShapes (IIf(Overbought, shapeSmallCircle, shapeNone), colorOrange, layer = 0, yposition = HaHigh, offset = 7 );

//=================TITLE============================ ================================================== ==================

if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlue)+ "StockManiacs Intraday Trading System V2.0 - www.stockmaniacs.net" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) +
" - " + Date() +" - "+"n" +EncodeColor(colorLightBlue) +"Open-"+O+" "+"High-"+H+" "+"Low-"+L+" "+
"Close-"+C+" "+ "Volume= "+ WriteVal(V)+"n"+
EncodeColor(colorBlue)+
WriteIf (Buy, " GO LONG ABOVE "+H+" AND IF TRIGGERS ADD MORE LONG NEAR "+C+" - KEEP SL BELOW"+NW+" ", "")+
WriteIf (Short, " GO SHORT BELOW "+L+" AND IF TRIGGERS ADD MORE SHORT NEAR "+C+" - KEEP SL ABOVE"+NW+" ", "")+"n"+EncodeColor(colorDarkGreen)+
WriteIf(Short AND CloseAtEnd==False, "Total Profit/Loss For The Last Trade: Points - "+(C-BuyPrice)+"", "")+
WriteIf(Buy AND CloseAtEnd==False, "Total Profit/Loss For The Last Trade: Points - "+(SellPrice-C)+"", "")+
WriteIf(Long AND NOT Buy, "Current Trade : Long - Entry Price Near "+(BuyPrice), "")+
WriteIf(shrt AND NOT Sell, "Current Trade : Short - Entry Price Near "+(SellPrice), "")+"n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss "+(C-BuyPrice)+" Points - Current Trailing Stop Loss @ " + NW + "", "")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss "+(SellPrice-C)+" Points - Current Trailing Stop Loss @ " + NW + "", ""))+
WriteIf(NOT Long AND NOT Buy AND NOT shrt AND NOT Sell, "Currently Not In A Trade ", "");
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, Low, -15);
PlotShapes(IIf(Short, shapeHollowDownArrow, shapeNone), colorPink, 0, High, -15);
PlotShapes(IIf(Buy, shapeHollowUpArrow, shapeNone), colorLime, 0, Low, -25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone), colorDarkRed, 0, High, -25);
PlotShapes(IIf(CloseAtEnd==True AND (NextBarOutsideRTH OR NextBarNotToday), shapeStar, shapeNone), colorGold, 0, L, Offset=-10);

//Settings for Backtester
SetOption("AllowSameBarExit", False);
SetOption("AllowPositionShrinking", False);
SetOption("FuturesMode", True);
SetOption("InterestRate", 0);
SetOption("MaxOpenPositions", 1);
//RoundLotSize = Param_LotSize;
SetOption("MinShares", RoundLotSize);
SetOption("PriceBoundChecking", False);
//SetOption("CommissionMode", 3);
//SetOption("CommissionAmount", 12.5/RoundLotSize);
//SetOption("AccountMargin", Param_Margin);
SetOption("ReverseSignalForcesExit", True);
SetOption("UsePrevBarEquityForPosSizing", True);
SetOption("GenerateReport", 1);
SetOption("MaxOpenLong", 1);
SetOption("MaxOpenShort", 1);
SetOption("RefreshWhenCompleted", True);

//PositionSize = C*RoundLotSize*Param_NoOfLots;
SetTradeDelays(0, 0, 0, 0);
BuyPrice = Close;
SellPrice = Close;
ShortPrice = Close;
CoverPrice = Close;
//End of Settings for Backtester

//------------------------------------------------------
//
//  Formula Name:    Volume Breakout Trading System
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

//------------------------------------------------------
//
//  Formula Name:    Volume Breakout Trading System
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

//------------------------------------------------------
//
//  Formula Name:    Volume Breakout Trading System
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("Volume Breakout Trading System");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));

//Initial Parameters

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(120,spsShares);
SetOption( "AllowPositionShrinking", False );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

//Buy-Sell Logic

range=High-Low;

VolLookback=Param("VolLookback",50,10,100,10);
MALookback=Param("MALookback",20,10,100,10);

Buy = Volume>=Ref(Volume,-1)*1.5 AND Close>MA(Close,MALookback) AND Volume>MA(Volume,VolLookback) ;
Short =Volume>=Ref(Volume,-1)*1.5 AND Close<MA(Close,MALookback) AND Volume>MA(Volume,VolLookback);
Cover = Buy; 
Sell=Short;

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

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  
printf("\nVolume : " + Volume );   

StopLoss=Param("SL",3,1,10,1);
Target=Param("Target",30,5,40,5);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);
ApplyStop(Type=1,Mode=1,Amount=Target);


Plot( Close, "Price", colorWhite, styleCandle );
Plot(MA(Close,MALookback),"",colorYellow, styleNoLine);


/* 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(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, 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);


_SECTION_END();
Previous
Next Post »