Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Anti-Martingale Trading system for Amibroker (AFL)
Anti-Martingale system using Dynamic Position Sizing
Martingale or Anti-Martingale systems are widely popular across casinos across the globe. In Martingale system, the gambler doubles up his bet size on every loss so that he covers up all his loss through a single win. While in Anti-Martingale system, the gambler doubles up his bet size on every profit. The same concepts can be applied in Trading systems too. In Anti Martingale trading system, the trader increases his position size gradually if the trade goes in his favour, while the position size is decreased if the trade goes against him. The basic assumption behind this strategy is that profits from your winning trades is always higher than the losses from your losing trades. This strategy is particularly very helpful in trending markets. It’s a statistically proven fact that Anti-Martingale strategy performs better that Martingale strategy over a long term.
Amibroker has dynamic position sizing capabilities which would enable us to devise and backtest Anti Martingale strategy. In Amibroker terminology, increasing your position size is termed as Scaling-In, while decreasing your position size is termed as Scaling-Out. Two special constants: sigScaleIn / sigScaleOut provide means to tell the backtester when you want to scale-in/out
In order to change the position size you have to:
- Assign sigScaleIn to BUY/SHORT variable if you want to scale-in (increase size of) LONG/SHORT position.
- Assign sigScaleOut to BUY/SHORT variable if you want to scale-out (decrease size of) LONG/SHORT position.
Read more about this system with backtest report and equity curve (here).
Screenshots
Indicator / Formula
//------------------------------------------------------ // // Formula Name: Anti-Martingale Trading system // Author/Uploader: Trading Tuitions // E-mail: support@tradingtuitions.com // Website: www.tradingtuitions.com //------------------------------------------------------ _SECTION_BEGIN("Anti Martingale Trading Syatem"); SetTradeDelays( 1, 1, 1, 1 ); SetOption( "InitialEquity", 100000); SetOption("FuturesMode" ,True); SetOption("MinShares",1); SetOption("CommissionMode",2); SetOption("CommissionAmount",50); SetOption("AccountMargin",10); SetOption("RefreshWhenCompleted",True); SetOption( "AllowPositionShrinking", True ); BuyPrice=Open; SellPrice=Open; ShortPrice=Open; CoverPrice=Open; //Specify ScaleIn and ScaleOut parameters ScaleInPoints=100; ScaleOutPoints=50; ScaleInSize=150; ScaleOutSize=75; //Buy and Sell Condition Buy = Cross( MACD(), Signal() ); Sell = Cross( Signal(), MACD() ); BuyPrice=ValueWhen(Buy,C); for( i = 1; i < BarCount; i++ ) { Profit[i]=Close[i]-BuyPrice[i]>=ScaleInPoints; Loss[i]=Close[i]-BuyPrice[i]<=-ScaleOutPoints; if(Profit[i]==1) ScaleInPoints=(Close[i]-BuyPrice[i])+100; if(Loss[i]==1) ScaleOutPoints=-(Close[i]-BuyPrice[i])+50; if(Sell[i]) { ScaleInPoints=100; ScaleOutPoints=50; } } InTrade = Flip( Buy, Sell ); DoScaleIn = InTrade AND Profit; DoScaleOut= InTrade AND Loss; Buy = Buy + sigScaleIn * DoScaleIn + sigScaleOut * DoScaleOut; PositionSize = IIf( DoScaleOut,ScaleOutSize, ScaleInSize); Plot( Close, "Price", colorWhite, styleCandle ); SetPositionSize(PositionSize,spsShares); PlotShapes(IIf(Cross( MACD(), Signal() ), shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40); PlotShapes(IIf(Cross( MACD(), Signal() ), shapeSquare, shapeNone),colorLime, 0,L, Offset=-50); PlotShapes(IIf(Cross( MACD(), Signal() ), shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); PlotShapes(IIf(Cross( Signal(), MACD() ), shapeSquare, shapeNone),colorRed, 0, H, Offset=40); PlotShapes(IIf(Cross( Signal(), MACD() ), shapeSquare, shapeNone),colorOrange, 0,H, Offset=50); PlotShapes(IIf(Cross( Signal(), MACD() ), shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45); PlotShapes(IIf(DoScaleIn, shapeSmallUpTriangle, shapeNone),colorBlue, 0, L, Offset=-45); PlotShapes(IIf(DoScaleOut, shapeSmallDownTriangle, shapeNone),colorBlue, 0, H, Offset=-45); _SECTION_END();
14 comments
Leave Comment
Please login here to leave a comment.
Back
very nice one, amazing results at the first glance
i will be watching your site for sure!. Didn’t look at your other strategies yet. I adjusted your system posted here. Instead of using fixed scaleinpoints and scaleoutpoints you could also use the ATR function to determine the points to use. This is what I did and works good even with a slippage of 2 ticks
ah, an error found.
the buyprice is redefined using BuyPrice=ValueWhen(Buy,C);
you may use: BuyPrice=ValueWhen(Buy,C);
but then later you have to use
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
so rather than setting these prices at the start of the code you need to set them after
Buy = Buy + sigScaleIn * DoScaleIn + sigScaleOut * DoScaleOut;
intuitively I already thought it makes no sense since if it would work then a simple MACD system would also work, which it does not. Now what you do is scale in at prices of your initial buy price, and that is incorrect
or part of your code needs to be corrected to:
Hello,
Thanks for reviewing this system! I will review the correction you suggested very soon. Can you also advise how did you set up Scale-In and Scale-out points using ATR? What was the logic used?
Thanks,
Snehil
hi Snehil,
my point is that you define at the start of the code:
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
which is correct.
But then later you redefine the Buyprice as:
BuyPrice=ValueWhen(Buy,C);
this array you use to determine where to scale in or out which is correct but because you redefined the buyprice it will scale in and out at the price of the initial Buy defined by the MACD cross. When you look at the detailed backtest report you will see that the scalein and scaleout prices are not correct, they use the price of the initial buy.
I will send you my adjusted code to your private address tomorrow.
Still your code is interesting and I got all excited because it looks so professional and seemed to be working great. But in my opinion, because of the fact you redefine your BuyPrice array the scalein/out prices are incorrect.
Dear Ed sir,
Please post your adjusted code here it must useful to all
Thanks
hi,
i posted code here: http://wisestocktrader.com/indicatorpasties/1652-antimarti
made few changes also that you can see in the chart what the price is you pay when scaling in/out.
Dear ed sir,
Thanks a lot for posting
Thank you. I can see your modified code and it makes complete sense. I would update the same in my website too.
hi, one thing I did incorrectly is that the slippage applied will lead to a wrong scaleout price since these prices are stored in the buyprice array. So you will need to adjust this. So when slip = 0 it is correct in my opinion but if you add slippage you will need to adjust
so:
would need to be rewritten as:
Hello Folks,
what i need to do to apply this code for short trade?
I am not getting any thing on the chart…….just getting blank chart when applied the formula……..I am using Amibroker 5.9
is wrong this code,empottasch clearify the problem; What do they want to prove? the correct code, and results as ever, is poor