Attachments forums

List of attachments posted on this forum.


All files on forums: 161054

Little changes in TMA+CG.mq4 cause freezing mt4

Jagg, Tue Sep 19, 2017 7:07 pm

Hi,

I only have added these lines to the TMA+CG mladen.mq4 indicator from @mladen. But when I add this new version to a chart mt4 freezes completely :(
What is wrong with it?

Code: Select all

--- C:\Users\Hermann\AppData\Roaming\MetaQuotes\Terminal\6757291BBE1793F2A78EDD4695819C20\MQL4\Indicators\TMA+CG mladen.mq4	2017-09-15 13:54:38.381000000 +0200
+++ C:\Users\Hermann\AppData\Roaming\MetaQuotes\Terminal\6757291BBE1793F2A78EDD4695819C20\MQL4\Indicators\TMA+CG mladen v1.01j.mq4	2017-09-19 11:02:01.189000000 +0200
@@ -22,6 +22,7 @@
 //
 //
 
+extern string Part_1          = "*** TMA settings ***";
 extern string TimeFrame       = "current time frame";
 extern int    HalfLength      = 56;
 //extern int    Price           = PRICE_WEIGHTED; //=0-6 PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED
@@ -35,6 +36,11 @@
 extern bool   alertsSound     = false;
 extern bool   alertsEmail     = false;
 extern bool   Chart_to_front  = false;
+extern string Part_2          = "*** Arrows only when above/below MA ***";
+extern bool   Arrows_based_on_MA_Filter  = true;
+extern int    MA_Filter_Period= 120;
+extern ENUM_APPLIED_PRICE MA_Filter_Price = PRICE_CLOSE;
+extern ENUM_MA_METHOD MA_Filter_Method = MODE_SMMA;
 
 //
 //
@@ -60,7 +66,7 @@
 bool   calculatingTma = false;
 bool   returningBars  = false;
 int    timeFrame;
-
+double Smoothed_MA_value;
 //+------------------------------------------------------------------+
 //|                                                                  |
 //+------------------------------------------------------------------+
@@ -147,11 +153,27 @@
          upBuffer[i] = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations,1,shift1);
          dnBuffer[i] = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations,2,shift1);
 
-         upArrow[i] = EMPTY_VALUE;
-         dnArrow[i] = EMPTY_VALUE;            
-            if (High[i+1]>upBuffer[i+1] && Close[i+1]>Open[i+1] && Close[i]<Open[i]) upArrow[i] = High[i]+iATR(NULL,0,20,i);
-            if ( Low[i+1]<dnBuffer[i+1] && Close[i+1]<Open[i+1] && Close[i]>Open[i]) dnArrow[i] = High[i]-iATR(NULL,0,20,i)*2;
-
+         upArrow[i] = EMPTY_VALUE; //short arrow
+         dnArrow[i] = EMPTY_VALUE; //long arrow  
+         
+         Smoothed_MA_value = iMA(NULL,0,MA_Filter_Period,0,MA_Filter_Method,MA_Filter_Price,i+1);
+
+         if (!Arrows_based_on_MA_Filter) {
+            if (High[i+1]>upBuffer[i+1] && Close[i+1]>Open[i+1] && Close[i]<Open[i]) 
+               upArrow[i] = High[i]+iATR(NULL,0,20,i);
+            if (Low[i+1]<dnBuffer[i+1] && Close[i+1]<Open[i+1] && Close[i]>Open[i]) 
+               dnArrow[i] = High[i]-iATR(NULL,0,20,i)*2;
+         } else {
+            if ((High[i+1]>upBuffer[i+1] && Close[i+1]>Open[i+1] && Close[i]<Open[i]) 
+                  && (Close[i+1]<Smoothed_MA_value)) {
+                     upArrow[i] = High[i]+iATR(NULL,0,20,i);
+            }
+            if ((Low[i+1]<dnBuffer[i+1] && Close[i+1]<Open[i+1] && Close[i]>Open[i]) 
+                  && (Close[i+1]>Smoothed_MA_value)) {
+                     dnArrow[i] = High[i]-iATR(NULL,0,20,i)*2;
+            }
+         }
+            
          if (timeFrame <= Period() || shift1==iBarShift(NULL,timeFrame,Time[i-1])) continue;
          if (!Interpolate) continue;
 
What I try to do is only show the buy arrows (at bottom tma) when the price is above 120 MA value and vice versa.

Attached is my modified mt4 version.

Thanks!
All files in topic