BangaloreBangaloreHyderabadRest of India Mon - Sun 09:00-18:00 +91-636-192-2946, +91-814-708-4334 Mon - Sun 09:00-18:00 +91-9963640037 +91-636-192-2946 Mon - sun 10:00-18:00 +34-354-5468-8

Supertrend with Martingale

PurpleTrades - stock market courses > AFL Codes > Supertrend with Martingale

Supertrend with Martingale AFL


Supertrend with Martingale system AFL as the name suggests is just the mixture of Supertrend and martingale system.

So when Supertrend generates BUY/SELL Signal, it would take a trade and continue until the next trade comes and at next trade, it will exit the previous position and reverse the trade (Exit and reverse).

However, since the Martingale system is also involved, now AFL will keep monitoring P/L.

In case, the trade gives loss, we double our quantity in the next trade and keep doing this until we make profits.

Once the trade turns positive, the next trade would again be having the initial quantity to start the entire process all over again.


This AFL Has 2 types of martingale :

  1. Arithmetic: In this system, Instead of doubling every time we lose, we simply add quantity as per arithmetic progression.

Ex :

We Buy 10 shares of X Stock and it goes against us, we exit and reverse 20 shares, and say it goes against us, then we exit and reverse 30 shares(not 40 shares)

So arithmetic series would be : 10,20,30,40,50……….


  1. Geometric: As the name suggests, we have geometric progression or basically doubling shares every time we lose.

Ex :

We Buy 10 shares of X Stock and it goes against us, we exit and reverse 20 shares, and say it goes against us, then we exit and reverse 40  shares

So Geometric series would be : 10,20,40,80,160……….


A user can choose between these two types of martingale system.


The AFL looks like this on Amibroker


Let’s explore the features/ parameters of this AFL :


It has supertrend ATR to adjust as per your preferred requirements


If you use Supertrend (10,3) you have to fill 

ATR Multiple: 3

ATR Period: 10


AFL has options to customize trade time :


Activate Intraday: To choose if you want to trade Intraday/delivery based trading.

Trade entry from : If day starts, from what time should AFL start accepting signals. In case you give this as 9:45 am, so any trade between 9:15 to 9:45 am will be discarded, as you wanted to take trade only post 9:45 am.


Trade entry upto: Till what time fresh entry should be accepted.If you fill this as 2:30 pm, any fresh trade after 2:30 pm will be ignored however the open positions initiated before 2:30 pm will be still valid and running.


Trade exit: This will generate exit on all open positions, say you fill this as 3:10pm, so all open positions will be squared of at 3:10 pm sharp.


AFL has Risk management tools :


Stoploss: In case you want to keep SL in the system, you can customize SL in percentage here.

If Buy entry was at 100rs and you keep SL as 1%, SL would be set at 99rs, irrespective of supertrend give sell signal or not.


Target: In case you want to keep Target in the system, you can customize Target in percentage here. If Buy was at 100rs and you keep the target as 1%, Target would be set for 101rs, irrespective of supertrend gives sell signal or not.


Trailing SL: You can also keep trailing SL in percentage.


To choose the number of shares per trade we have 3 options :


Trade quantity: You can choose the number of shares you wish to start trading with.

If you fill this as 30, per script that you run this AFL on, 30 shares will be bought/sold, and as per martingale system the quantity will double to 60, in case you lose the first trade and so on



Quantity using Exposure: Incase you dynamically wnt to allocate the number of shares, you can do so by filling in this exposure tab. 

If you fill 10000, then it would buy/sell shares worth 10000rs.

If X share is of 500, 20 shares will be bought/sold

If Y share is of 1000, 10 shares will be bought/sold.

And as per martingale rule, if we lose 1st trade, the exposure in 2nd trade will be 20,000 and so on.


Quantity using SL: This feature will dynamically adjust your position size as per SL defined.

Say you define SL as 1000rs and in SL tab above as 1% for the stock of 100rs, it means SL of 1rs.

Thus 1000 shares will be bought/sold as per this SL based system.


(Note : You cannot choose all the three together, you have to choose your quantity only as per one of the above-mentioned method and rest you have to set to 0, in case you fill 2 or3 of the quantity method it would give you an error)


Day profit limit: You can set a limit on profit per script per day. If you fill this as 1000, then after all the trades in a script in a day, if the net gain is 1000, it would stop trading in that script.


Day loss limit: you can set a limit on loss per day. If you fill this as 1000, then after all the trades in a script in a day, if net loss is 1000, it would stop trading in that script.


Misc :

message board: This will show you what’s happening with your position, your current MTM per script, how much profit is booked for the day, when did the last signal come and other details.


Button trading: we have also added four buttons LE, LX, SE, SX corresponding to Lon entry, long exit, short entry, and short exit respectively

In case you manually want to place a trade at any given time, you on click on any of the button and corresponding trade would be triggered.


Trade Intrabar: If its Yes, it would take a trade on the same candle on which entry had come, if its 

Candle completion, it would wait for the candle to complete and then take a trade on opening of nxt candle


Strategy Tag: you can give a tag to your strategy.

Once all of these settings are done, your AFL is ready for trading.


Get this AFL at INR 2999 only 



## AFL will be delivered in 1 working day to your registered email address (Monday- Friday)


(Warning: Martingale based systems can be profitable if used with proper risk-management tools, else this system can give huge losses.

It is always advised to place Limit order and not market orders to avoid the losses due to spread in ask-bid. 

Purpletrades will not be responsible for any loss that you face using this system, consult your financial advisor before using this setup)


Find it difficult to understand?

Watch a full explanatory video here :


Similar links :




Call Now Button
Scroll Up