Experiments in Technical Analysis

asnavale

Well-Known Member
Dear Murthy garu,

Thanks for your observations and suggestions. Let me attempt to put in my reactions.

i fully agree with what you said that 'The delay can be upto half the period of Moving Average'. actually about a year back, i have read a very novel method to remove the delay. this is by adding (or is it by substracting?) the HALF period EMA from the normal period EMA. after reading your post, i tried to locate the reference by googling, but couldn't find. i will continue my search and post the link if i could find. by your scientific approach, this could be easily rebuilt.

the crossover method has another limitation that sometimes stocks crossover 'too often', as, inspite of the cross over, enough strength may not be there in the move and they reverse crossover in a very short period.

another way of putting the crossovers is:

buy= EMASHORT/EMALONG>1
sell= EMASHORT/EMALONG<1

if this is modified to:

buy= EMASHORT/EMALONG>1.02
sell= EMASHORT/EMALONG<0.98

this 2% (or another such small value) 'dead--band' could possibly exclude such weak crossovers. this dead-band can be optimised.

here again, sometimes, we may come across 'weak reversals'. to exclude such weak signals, we may go for the 3day EMA of that difference than the difference itself.

i am aware that my comments 2 & 3 will incorporate delays and possibly may reduce the RETURNS. but they may reduce the RISK too. these may eat away part of the benefits of the removed delay by the method hinted in my first comment.

these comments of mine are more hypothetical in nature and request your comments on these. if your time permits, you may substanciate / negate by back testing.
I would be glad to go through the article about removing lag from moving averages. We can indeed rebuild it, may be with improvements. Post the link as soon as you locate it.

There will be many cross overs especially in range bound region which are not of much use. We must try to find out ways to eliminate them. Your suggestion of using a 3-period EMA can definitely be tested and compare the returns. I would try that after I complete the present work. Meanwhile some other members also can give it a try.

It may not be out of place to refer to my answers to Sanjay, wherein I have explained the danger of eliminating small cross-overs. We have to keep this also in mind before eliminating them. Because, when a cross-over occurs we do not know whether it is a beginning of a really big move. And surely we don't want to miss it.
not a big issue, but, if you add a column to show the date of crossover in the exploration window, it may help to know from the window itself how old is the cross-over and the most recent cross-overs.

murthymsr
The Date column in the Exploration results gives the date on which the trade is being executed. The cross-over date is the previous trading day. I think I had explained this in my earlier post under the heading 'When to Trade'.

Please keep on giving your comments and suggestions. I need them very much.

Thank you once again for your keen interest and encouragement.

Regards

-Anant
 
Dear friends,

Thanks for your views, comments and suggestions. I am sure some more will come after you run the AFLs on different stocks and under different conditions. I am waiting for your valuable inputs.

I will try to explain some of the points already posted by different members.

First of all let me thank you, Karthik, for taking such keen interest inspite of your heavy schedule. From your post I could see that you have put your test results within an hour or two after I posted the codes. Really dedicated work by you. You appear to have run the codes very late in the night or may be early hours foregoing sleep and rest. Please take care of your health.



Hi Sanjay, The Histogram does give lot of signals even inbetween actual crossover points. For example in Long Term_I, there are nearly 70-90 signals over a period of 440 trading days, several signals coming on consecutive days. Some of these may be even loss making. We must find a solution to eliminate them. But that can be done later after enough discussion in this forum, combining various ideas put forward by different members.

I have tried few methods to eliminate the small signals. But what happened was in many cases, an insignificant Buy signal just before a large upward movement got eliminated and there was no way of entering into the up trend. This is important especially at the end of a range bound movement. Therefore I just kept on trading with all the signals, however minute they were. This is also in line with my conditions posted earlier that all signals will be traded.



Yes we can consider this later. But I will carry out the intial portfolio test with the same stocks, but eliminate those which have insufficient data.



Thanks for the code. It appears from the code you posted that the values of p1 and p2 were changed to 13 and 9. I had posted p1=15 and p2=15. The values 15 for p1 and p2 gave slightly better results. You may try to use these values and and find out.

I had removed the histogram plotting code in order to highlight the exploration part alone. (I have a combined code which can plot and explore so that the same AFL can be used to either plot or to explore.)

Hello thetraderman, I am sorry. I have never used MS. So I cannot help you. But the members here would do that for you.

Regards and Happy trading.

-Anant
Thank You Anant, but I think I figured it out. Here it is. If anyone can take a look that would be great. Also I did see amny ripshaws with this indicator especially wilh laterally moving markets. That needs to be improved before it can be used effectively.

p1:=13; {13}
p2:=9; {9}
X := Mov(C,p1,E);
Y := Mov(X,p2,E); {Signal}
D := X-Y;

Buy := Ref(D,-2)>Ref(D,-1) AND D>Ref(D,-1);
Sell:= Ref(D,-2)<Ref(D,-1) AND D<Ref(D,-1);
Bprice := If(Buy,Ref(O,1),0); {Buying Price}
Sprice := If(Sell,-Ref(O,1),0); {Selling Price}

Bprice;
Sprice;

Thanks,
TheTraderMan
 

SGM

Active Member
Dear Anant

I will use the value 15 for P1 and P2 and try to chk out the diff. There is lots to assimilate and respond about your work, will take quite a bit of time. :)

From my limited investigations so far I am of the opinion that the original system proposed by Karthik suits me better (buying above the previous peak reduces most of the wipsaws).

But as the seniors say the most important aspect about suitability of a system has to be the temperament of the trader/investor.


Another way of putting the crossovers is:

buy= EMASHORT/EMALONG>1
sell= EMASHORT/EMALONG<1

if this is modified to:

buy= EMASHORT/EMALONG>1.02
sell= EMASHORT/EMALONG<0.98

this 2% (or another such small value) 'dead--band' could possibly exclude such weak crossovers. this dead-band can be optimised.

here again, sometimes, we may come across 'weak reversals'. to exclude such weak signals, we may go for the 3day EMA of that difference than the difference itself.

i am aware that my comments 2 & 3 will incorporate delays and possibly may reduce the RETURNS. but they may reduce the RISK too. these may eat away part of the benefits of the removed delay by the method hinted in my first comment.
Hello Murthygaru

I have tried to incorporate the above inputs from you in an Indicator. After introducing the dead band the system gives more whipsaws, and averaging the difference (EMA of D) just delays the signal further adding to the risk rather than reducing it.

I am uploading the Indicator, plz insert it below the price chart. Just play around with the various parameter values to see the different effects.

I have also plotted the ATR value on the indicator which will be useful to try to judge the outside limits of deviations of the signal line(EMA) from the averages(EMA of EMA). This could be used as an anti-trend signal, perhaps to book partial profits :)

Warm Regards
Sanjay

PS: Rename the file extention from txt to afl
 

murthymsr

Well-Known Member
dear sgm,

thanks for the indicator.
i will 'play' with it and post by observations; but it needs good lot of time.

murthymsr
 

SGM

Active Member
Dear Anant

As suggested by you, I tried out the combination of 15 & 15 as values for p1 and p2 . It definately improves the performance.
It appears from the code you posted that the values of p1 and p2 were changed to 13 and 9. I had posted p1=15 and p2=15. The values 15 for p1 and p2 gave slightly better results. You may try to use these values and and find out.
I tried to use the optimize feature in AB to find the performance of various pairs for P1 & P2. For every data set AB tested for about 324 combinations of P1 & P2. The following pairs gave the best performance with diff data sets.

12,20 ; 13,19 ; 14,16 ; 15,17 ; 16,16 & yes also 15,15.

It would be amazing if you have arrived at the 15,15 pair just by intuition.

There was another interesting aspect that i noticed. The values of P1, P2 can be interchanged without having much difference in the performance. For e.g. Instead of P1 = 12 and P2 = 20, we can also use P1=20 and P2 = 12.

Personally, I have chosen the values of 13, 19 for use with the Mabitus system.

Finally, I would like to thank Karthik, Murthy and Anant, for all the help I have got from your posts in this thread. It enabled me to get some insight into back testing for a trading system.

Thanks and Regards
Sanjay
 
Last edited:
hai Mr. Kumar ,
You all seem to speak Latin & Greek , for me , as I am very new to this world of trading. Please let me know what are these. Please mail me
[email protected].

Pl. give feedback , so that I can try to understand what are these points. Thanks in advance.:) :confused: :)
 
Re: Modified Mabitus

I think its ok if it gives whipsaws in sideways. You cann't have a single system for every mode. This indicator works well in trending mkt and you may be well off, with osc in sideways.
Anjan
 

asnavale

Well-Known Member
Hi,

MABIUTS-H is a very innovative and novel approach. Very scientific explanation too. Please explain the proof of Moving average delay.

***Uma***
Dear Uma,

Thank you for your appreciative words and I am glad to see your interest in learning.

I am giving the proof of moving average delay below:

For the sake of easy explanation I am oversimplifying the example. However, the steps explained here are equally applicable to real situation also.

Let us assume a share being traded at Rs. 100 and the price goes on increasing by Re. 1 every day (You can take any value you like, eg price = 300 and increase = 1.7 etc. But the values I have taken make the calculation easy). Also assume that the price increases from 100 to 110 and then starts falling by Re. 1 each day till it reaches Rs 95. Thereafter it again increases Re. 1 everyday to again reach Rs 110. This up and down continues. Let us take the first 50 days' data for our example. Let us say we want to calculate 5-day and 15-day simple moving averages and their cross over. The price data, the moving averages and their difference along with the chart are attached as a PDF file with this post. You can download the file, take a print out and follow along with the explanation here.

The 5-day moving average is simply the average of previous 5 day prices starting today. So, in our example the first four days have no moving average, 5th day onwards the values are calculated and entered against the day number. So, the first MA value is against 5th day, second value against 6th day etc. Similar is the case with 15-day moving average, the first value is against 15th day and so on. The moving average difference column starts with 15th day.

You can see from the table of values in the attached file that the price has reached the maximum value of 110 on 11th day and thereafter it is falling. But the 5-day moving average reached maximum value of 108.80 on 13th day and the 15-day MA reached its maximum value of 106.27 on 18th day. This extra time is the moving average lag. Why it happens?

When you take 5-day MA the first time you add values of day 1 to day 5. On the second occasion you add values of day 2 to day 6. In effect, you are removing the first day value and adding 6th day value. As the 6th day value is higher than 5th day value the MA increases. On 11th day you add the maximum price for the first time. On 12th day you add a value which is smaller than the maximum, but the value being removed is still smaller than this 12 th day value. So, MA continues to increase even after the Peak in price is reached. This continues till the latest value added is smaller than the value removed. This happens when the Maximum Price is in the center. As we are taking 5-days prices, the Maximum price is in the centre after half of this period i.e. 2.5 days. This makes it 11+2.5=13.5. So we see the peak in MA on 13th day. Similarly, the peak of 15-day MA appears on 11+(15/2)=11+7.5=18.5 days which is rounded to 18th day. Therefore, the MA peak lags the price peak by half of the averaging period. Similarly, the lowest value of MA lags the lowest price by the same number of days.

We have taken regularly increasing/decreasing prices in this example. In real situation this is not true. So, the actual lag will be a little different from the 'half of the averaging period'. Depending on which side of the price peak (or valley) is changing faster, the MA peak is displaced a little to the left or right. But on an average we can take this lag to be half of averaging period.

Coming to the cross-over of the two MAs we can explain it as follows. Now I have to introduce a little maths here. But it is very simple.

Let us say p1 is short term, p2 is long term. As we have seen above, the short term MA reaches peak (p1)/2 days after the price peak and the long MA reaches its peak (p2)/2 days after price peak. So the time difference between the two MA peaks is (p2)/2 - (p1)/2 which is same as (p2-p1)/2. That means Half of the difference between the two averaging periods. The cross over will occur midway between this difference. So it will be hallf of (p2-p1)/2 or equal to (p2-p1)/4. That is one-fourth of the difference between the averaging periods. In our case the MA period difference is 15-5=10 and 10/4=2.5. So the cross over is 2.5 days (or 2 to 3 days) after short MA peak. We can see from the data and graphs that this is indeed the case.

If you have understood this, then you can try to prove why the histogram peaks appear much before the cross over. I will leave it as an excercise. As the Histogram peak appears much before the cross over, I tried to use it in my MABIUTS-H strategy.

Regards

-Anant
 
Last edited:

asnavale

Well-Known Member
Dear Sanjay,

Thanks for your test results and optimisation results. Thanks also for the words of appreciation and encouragement.

I tried to use the optimize feature in AB to find the performance of various pairs for P1 & P2. For every data set AB tested for about 324 combinations of P1 & P2. The following pairs gave the best performance with diff data sets.

12,20 ; 13,19 ; 14,16 ; 15,17 ; 16,16 & yes also 15,15.

It would be amazing if you have arrived at the 15,15 pair just by intuition.
I did not try optimisation but it was only intuition to try 15,15 in the tests. Happy to see that it is one of the optimum values. It is also intersting to see that the sum of P1 and P2 is 30 or 32. Interesting to investigate it.

This is the reason why this forum is the place to learn. Sharing the test results will thus be put to test and better suggestions will come out to improve the strategies. I hope some more people will come out with their test results and we may finally get a solution to reducing the number of signals generated in MABIUTS-H without sacrificing much of the profits.

There was another interesting aspect that i noticed. The values of P1, P2 can be interchanged without having much difference in the performance. For e.g. Instead of P1 = 12 and P2 = 20, we can also use P1=20 and P2 = 12.
Yes, You are right again. Interchanging P1 and P2 makes no substantial difference. It can be proved. But I will not go into those details now. Let us concentrate on improving the strategy.

Thank you once again.

Hope to get more intersting test results from you and others too.

Regards.

-Anant
 

asnavale

Well-Known Member
Re: Modified Mabitus

Hi Anjan,

Thanks. But we are not taking any of the four strategies as the final. The aim of posting the results is to improve them and get a best possible solution. You might be impressed by the very attractive results. But remember, it is still under testing and review. So, personally I don't recommend using it for real trading. You can do paper trading to get confidence in the system. However, the decision is a personal matter.

-Anant
 

Similar threads