I've spent an hour searching for something pretty simple, but haven't figured it out. How would you code if a MA is sloping up or down?
If the MA slopes up, buy -- if down, sell.
If the MA slopes up, buy -- if down, sell.
lets develop a system which is very very simple but effective. 7 replies
Very Simple MT4 Question 6 replies
mt4 coder needed for a very very simple system 2 replies
Very simple question 0 replies
After this, the problem becomes, what is the threshold which defines a slope?
Once you have this down, you need to consider:
Some food for thought.
[Edit]
The mql4 codebase has several linear regression indis to play around with.
#property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red #property indicator_level1 0.0 extern int maPeriod =25, //a D1 month distanceX =1; double slope[], Y0, Y1, distanceY; int init() { SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,slope); return(0); } int start() { int counted_bars=IndicatorCounted(); int limit = Bars-counted_bars-1; for(int i=limit;i>=0;i--) { Y0 = iMA(NULL,0,maPeriod,0,MODE_SMA,PRICE_OPEN, i ); Y1 = iMA(NULL,0,maPeriod,0,MODE_SMA,PRICE_OPEN, i + distanceX ); distanceY = Y0 - Y1; slope[i] = ( distanceY )/( distanceX ); } return(0); }