// Downloaded From https://www.WiseStockTrader.com //------------------------------------------------------ // // Formula Name: Mean Reversion Trading System // Author/Uploader: Trading Tuitions // E-mail: support@tradingtuitions.com // Website: www.tradingtuitions.com //------------------------------------------------------ _SECTION_BEGIN("Mean Reversion 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, SelectedValue( ROC( C, 1 ) ) )); 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(150,spsShares); SetOption( "AllowPositionShrinking", True ); BuyPrice=Open; SellPrice=Open; ShortPrice=Open; CoverPrice=Open; Periods =optimize("Periods",110,10,200,20); Width =optimize("width",2,1,10,1); MAPeriods = 200; BBColor = colorOrange; Style = 0; bTop=BBandTop( Close, Periods, Width ); bBottom=BBandBot( Close, Periods, Width ); ADXPeriods=optimize("ADXPeriods",10,2,20,1); BuyCondition=IIf(Ref(C,-1)bBottom AND ADX(ADXPeriods)<35,1,0); ShortCondition=IIf(Ref(C,-1)>bTop AND closebBottom AND ADX(ADXPeriods)<35,1,0); Short = IIf(Ref(C,-1)>bTop AND close=LastShortPrice+LastBuyPrice*(Stoploss/100); BuyTarget=BarsSinceBuy=LastBuyPrice+LastBuyPrice*(Target/100); ShortSL=BarsSinceShortbTop OR ShortSL OR BuyTarget; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); Short=ExRem(Short,Cover); Cover=ExRem(Cover,Short); ApplyStop(Type=0,Mode=1,Amount=StopLoss); ApplyStop(Type=1,Mode=1,Amount=Target); printf("\nBuy : " + Buy ); printf("\nShort : " + Short ); printf("\nCover : " + Cover ); printf("\nSell : " + Sell ); printf("\nBuyPrice : " + BuyPrice ); printf("\nShortPrice : " + ShortPrice ); printf("\nLastBuyPrice : "+ LastBuyPrice); printf("\nLastShortPrice : "+ LastShortPrice); printf("\nBuyCondition : "+ BuyCondition); printf("\nShortCondition : "+ ShortCondition); printf("\nBuySL : "+BuySL); printf("\nShortSL : "+ShortSL); Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); Plot( bTop, "BBTop" + _PARAM_VALUES(), BBColor , Style ); Plot( bBottom, "BBBot" + _PARAM_VALUES(), BBColor , Style ); /* 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();