#resource not work!

Back to topics list To post a new topic, please log in or register
avatar
86
fly7680 2016.05.13 11:07
 
Hello everyone, after writing this indicator, I tried to import the ex4 file at compile time, but even if there are no errors, the final file will not work.

Where am I wrong?



#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0x0000FF
#property indicator_label1 "Sell"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x00FF66
#property indicator_label2 "Buy"


//--- indicator buffers
double Buffer1[];
double Buffer2[];

extern double HistograM = 0.00001;
extern double HistograMneg = -0.00001;
datetime time_alert; //used when sending alert
extern bool Audible_Alerts = true;
double myPoint; //initialized in OnInit

#resource "\\Indicators\\macd_2tonecolor.ex4"  //---not work?!?

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Istogrammi @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | Istogrammi @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 159);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 159);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 1, i) > HistograM + Close[4+i] //macd_2tonecolor > fixed value + Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 1, i) > HistograM + Close[3+i] //macd_2tonecolor > fixed value + Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 1, i) > HistograM + Close[2+i] //macd_2tonecolor > fixed value + Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 1, i) > HistograM + Close[1+i] //macd_2tonecolor > fixed value + Candlestick Close
      )
        {
         Buffer1[i] = Open[i] + 1 * myPoint; //Set indicator value at Candlestick Open + fixed value
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 2, i) < HistograMneg + Close[4+i] //macd_2tonecolor < fixed value + Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 2, i) < HistograMneg + Close[3+i] //macd_2tonecolor < fixed value + Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 2, i) < HistograMneg + Close[2+i] //macd_2tonecolor < fixed value + Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor", 2, 4, 2, 2, i) < HistograMneg + Close[1+i] //macd_2tonecolor < fixed value + Candlestick Close
      )
        {
         Buffer2[i] = Open[i] - 1 * myPoint; //Set indicator value at Candlestick Open - fixed value
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer2[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+


avatar
1109
Ovo 2016.05.13 13:44 #
 
I never tried the indicator as a resource, but I would expect the resource reference starting with :: , like bitmaps and sounds.
avatar
86
fly7680 2016.05.13 14:02 #
 

Thanks Ovo for the answer, in addition to what you said you, I also changed this line of code:


iCustom(NULL, PERIOD_CURRENT, "macd_2tonecolor" //---<not work

iCustom(Symbol(), PERIOD_CURRENT, "::Indicators\\macd_2tonecolor.ex4" //---<it work!
avatar
119
Doerk 2016.05.13 16:15 #
 
Portable mode?
Back to topics list  

To add comments, please log in or register