//+------------------------------------------------------------------+ //| Simply MA wrong.mq4 | //| MetaQuotes | //| http://forum.alpari-idc.ru/viewtopic.php?t=48186 | //+------------------------------------------------------------------+ #property copyright "MetaQuotes" #property link "http://forum.alpari-idc.ru/viewtopic.php?t=48186" //---- #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //---- input parameters extern int PeriodMA=21; extern int ShiftMA=0; //---- buffers double ExtMapBuffer1[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); int limit; // îãðàíè÷èòåëü ðàñ÷åòîâ double val; // âðåìåííàÿ ïåðåìåííàÿ, äëÿ âû÷èñëåíèÿ çíà÷åíèé èíäèêàòîðà //---- if (counted_bars==0) limit=Bars-PeriodMA; // ïîñ÷èòàííûõ áàðîâ åùå íåò, áóäåò ñ÷èòàòü ñ áàðà, // ïåðåä êîòîðûì åñòü õîòÿ áû PeriodMA-1 áàðîâ. if (counted_bars>0) limit=Bars-counted_bars-PeriodMA; // âû÷òåì èç ÷èñëà äîñòóïíûõ áàðîâ êîëè÷åñòâî //ïîñ÷èòàííûõ áàðîâ Print("Bars=",Bars," limit=",limit," counted_bars=",counted_bars); //---- int i=limit; while(i>=0) { /* Íåîáõîäèìûå âû÷èñëåíèÿ val */ val=0; // íå çàáóäåì êàæäûé ðàç îáíóëÿòü ñëóæåáíóþ // ïåðåìåííóþ ïåðåä ïðîõîäîì â öèêëå for(int k=0;k<PeriodMA;k++) { val=val+Close[i+k]; } val=val/PeriodMA; // ñóììà ïîñëå öèêëà åñòü, óñðåäíÿåì åå ExtMapBuffer1[i]=val; // óñòàíîâèì ýíà÷åíèå //ñðåäíåé íà áàðå ñ èíäåêñîì i i--; } //---- return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features: