Correct syntax for use of Indicators as Resources

 

Hi All,

I'm not a great programmer so was looking for advice. I am using the Resource function to include my indicators in my Expert Advisor but I cannot get it working correct.. can someone help?

In my code I am using this:

#resource "\\indicators\\heikenashi.ex4"


After the OnTick section I use

void OnTick() {

   double heikenashi=iCustom(_Symbol,_Period,"::heikenashi.ex4",0,0);


And there is further code:

double heikenashi(string symbol, int timeframe, string mode, int shift) {

   if(symbol == "NULL" || symbol == "Current") {

      if(mode == "Open") {

         return(NormalizeDouble(iCustom(NULL, timeframe, "::heikenashi.ex4", 0,0,0,0, 2, shift), 6));

      }

      if(mode == "Close") {

         return(NormalizeDouble(iCustom(NULL, timeframe, "::heikenashi.ex4", 0,0,0,0, 3, shift), 6));

      }

      if(mode == "High") {

         return(NormalizeDouble(MathMax(iCustom( NULL, timeframe, "::heikenashi.ex4", 0,0,0,0, 0, shift), iCustom( NULL, timeframe, "::heikenashi.ex4", 0,0,0,0, 1, shift)), 6));

      }

      if(mode == "Low") {

         return(NormalizeDouble(MathMin(iCustom( NULL, timeframe, "::heikenashi.ex4", 0,0,0,0, 0, shift), iCustom( NULL, timeframe, "::heikenashi.ex4", 0,0,0,0, 1, shift)), 6));

      }


Can someone help me with the correct syntax in all the sections please?


Thanks

 
Alan Lee:

Hi All,

I'm not a great programmer so was looking for advice. I am using the Resource function to include my indicators in my Expert Advisor but I cannot get it working correct.. can someone help?

In my code I am using this:

Can someone help me with the correct syntax in all the sections please?

Thanks

I would code it like this

#resource "\\indicators\\heikenashi.ex4"

string HeikenAshi="::Indicators\\heikenashi.ex4"


After the OnTick section I use

void OnTick() {

   double heikenashi=iCustom(_Symbol,_Period, HeikenAshi ,0,0);


And there is further code:

double heikenashi(string symbol, int timeframe, string mode, int shift) {

   if(symbol == "NULL" || symbol == "Current") {

      if(mode == "Open") {

         return(NormalizeDouble(iCustom(NULL, timeframe, HeikenAshi , 0,0,0,0, 2, shift), 6));

      }

      if(mode == "Close") {

         return(NormalizeDouble(iCustom(NULL, timeframe, HeikenAshi , 0,0,0,0, 3, shift), 6));

      }

      if(mode == "High") {

         return(NormalizeDouble(MathMax(iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 0, shift), iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 1, shift)), 6));

      }

      if(mode == "Low") {

         return(NormalizeDouble(MathMin(iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 0, shift), iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 1, shift)), 6));

      }

 
Daniel Stein:

I would code it like this

#resource "\\indicators\\heikenashi.ex4"

string HeikenAshi="::Indicators\\heikenashi.ex4"


After the OnTick section I use

void OnTick() {

   double heikenashi=iCustom(_Symbol,_Period, HeikenAshi ,0,0);


And there is further code:

double heikenashi(string symbol, int timeframe, string mode, int shift) {

   if(symbol == "NULL" || symbol == "Current") {

      if(mode == "Open") {

         return(NormalizeDouble(iCustom(NULL, timeframe, HeikenAshi , 0,0,0,0, 2, shift), 6));

      }

      if(mode == "Close") {

         return(NormalizeDouble(iCustom(NULL, timeframe, HeikenAshi , 0,0,0,0, 3, shift), 6));

      }

      if(mode == "High") {

         return(NormalizeDouble(MathMax(iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 0, shift), iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 1, shift)), 6));

      }

      if(mode == "Low") {

         return(NormalizeDouble(MathMin(iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 0, shift), iCustom( NULL, timeframe, HeikenAshi , 0,0,0,0, 1, shift)), 6));

      }

Thank you .. i will try.. will  string HeikenAshi  get confused with  double heikenashi ? Just want to ask before i edit my code

 
  1. Please edit your posts and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. Just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
              Use the publicly released code - MQL5 programming forum 2017.02.20
              Resources - MQL4 Reference

    Be aware that using resources is 40x times slower than using CIs directly.
              A custom indicator as a resource - MQL4 programming forum 2019.11.26

    Also make use there are no spaces in the path.
              Getting error 4802 when loading custom indicator that loads another custom indicator with iCustom - Technical Indicators - MQL5 programming forum. 2020.07.21