Detailed explanation of iCustom - page 4

 
honest_knave: I never knew it was called camel case. Thanks!
Looks like the Moderator deleted my previous Post because it had a WikiPedia link, so just do a search on WikiPedia (or Google) for some history and details about "Camel Case".
 
Fernando Carreiro:
Looks like the Moderator deleted my previous Post because it had a WikiPedia link, so just do a search on WikiPedia (or Google) for some history and details about "Camel Case".
Your post was removed as it was a double. The same link is already posted.
 
Continuing from #23 and encapsulating in a function #26, I now show a struct that works on both MT4 and MT5. (For post-build 600, I've changed the invalid dots (#29) in variable names, and approprate ints to standard enumerations.)
Not compiled, not tested.
struct SFX{                            // SFX indicator at #1
   #define SFX_NAME_PATH   "SFX"       // Indicator filename without extension,
                                       // including blanks if any.
   enum SFXbuffer{SFX_STD, SFX_STDMA};
   string                  PairName;
   ENUM_TIMEFRAMES         tf;
   int                     StdDev_MA_Period;
   int                     StdDev_MA_Shift;
   ENUM_MA_METHOD          StdDev_MA_Method;
   ENUM_APPLIED_PRICE      StdDev_MA_Price;
   int                     MA_Fast_Period;
   ENUM_MA_METHOD          MA_Fast_Method;
   int                     MA_Fast_Shift;
   #define CheckOncePerBar true;
   void SFX()      : PairName(_Symbol),            tf(PERIOD_CURRENT),
                     StdDev_MA_Period(12),         StdDev_MA_Shift(0),
                     StdDev_MA_Method(MODE_SMA),   StdDev_MA_Price(PRICE_CLOSE),
                     MA_Fast_Period(3),            MA_Fast_Method(MODE_SMMA),
#ifndef __MQL5__
                     MA_Fast_Shift(0){}
   double get(SFXbuffer buf, int iBar = 0){
      return iCustom(PairName, tf, SFX_NAME_PATH,
                     StdDev_MA_Period,             StdDev_MA_Shift,
                     StdDev_MA_Method,             StdDev_MA_Price,
                     MA_Fast_Period,               MA_Fast_Method,
                     MA_Fast_Shift,                CheckOncePerBar,
                     buf, iBar);
   }  // get
#else // MQL5
                     MA_Fast_Shift(0),             Handle(INVALID_HANDLE){}
   void ~SFX(){   if(Handle != INVALID_HANDLE) IndicatorRelease(Handle);   }
   double get(SFXbuffer buf, int iBar = 0){
      if(Handle == INVALID_HANDLE){
         Handle = iCustom(PairName, tf, SFX_NAME_PATH,
                     StdDev_MA_Period,             StdDev_MA_Shift,
                     StdDev_MA_Method,             StdDev_MA_Price,
                     MA_Fast_Period,               MA_Fast_Method,
                     MA_Fast_Shift,                CheckOncePerBar);
         if(Handle == INVALID_HANDLE){
            PrintFormat("%s: iCustom(%s) Failed: %i",
                        __FUNCTION__, SFX_NAME_PATH, _LastError);
            return 0;
         }
      }
      double  value[1]; CopyBuffer(Handle, buf, iBar, 1, value);
      return  value[0];
   }  // get
 Private:
   int                  Handle;     // MT5 only
#endif   // __MQL5__
}; // SFX
///////////////////////////////////////////////////////////////////////////////
SFX   SFXindicator;
// SFXindicator.StdDev_MA_Period = ...;   // modification of default parameters.
:
double     STDBuffer = SFXindicator.get(SFX_STD,   0);   // example calls
double     stddevma  = SFXindicator.get(SFX_STDMA, 0);
Not compiled, not tested.
 

Hello, i have a quick (and painless, i hope) question about iCustom: let's say that i have 3 indicators called Ind_A, Ind_B and Ind_C, and i have an Expert Advisor called EA.

the EA calls all the 3 indicators using icustom, passing their arguments and getting the results by indexing their respctive buffers.

i attach my 3 indicator on the EURUSD chart and i run my EA; let's focus on the indicator Ind_A, he is running as indicator but at the same time is executed by the EA: the instance is the same or we have two instances of ind_A running? (i mean, one instance runs on his own and the other instance lives inside the EA).

in suche case, each instance has his own buffer? or is the buffer shared between all the instances of the indicator?

Many thanks!

 

Sorry to wake up this thread again. But I thought my question belongs to this topic. 

I try to access 2 buffers from a custom indicator trend-target, the indicator has one input = 60, and two buffers Band UP and Band LO

using

double Value1 = iCustom(Symbol(),0,"TrendTarget.ex4",60,0,1,0);



double Value2 = iCustom(Symbol(),0,"TrendTarget.ex4",60,0,0,1);double Value1 = iCustom(Symbol(),0,"TrendTarget.ex4",60,0,1,0);



Comment("iCustom returned v1= "+Value1+ " and value2= ",Value2);

  is the way I set parameters for this iCustom correct? because I seem not to get the Band Up and Band LO values not exact to the buffers in data watch panel pls check the attached picture. Only the 2 or 3 first decimal digits or 3e right but for a FX quote all 4 digits must be correct is it right?

I hope the coder and experienced users on MQL5 can help me quickly correct this issue? Thanks in advance

-----------------------------------------------------------------------------------------------------
Apropos what is your indicator has 5 inputs and 4 buffers,

double Value1 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,1,0,0,0);

double Value2 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,2,0,0);

double Value3 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,0,3,0);

double Value4 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,0,0,4);


Like this above?

 
ntk2017: Sorry to wake up this thread again. But

Please edit your (original) post 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
          Messages Editor

 
ntk2017: Apropos what is your indicator has 5 inputs and 4 buffers,
double Value1 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,1,0,0,0);
double Value2 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,2,0,0);
double Value3 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,0,3,0);
double Value4 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,0,0,4);

Like this above?

Absolutely not.

iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,BufferIndex,BarIndex);
 
William Roeder:

Absolutely not.

I should use like this
double value1 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,1,0,0,0,0); //with BarIndex=0, when only check on close or 1= when check on every tick;
double value2 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,1,0,0,0);
double value3 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,0,1,0,0);
double value4 = iCustom(Symbol(),0,"indicator",a1,a2,a3,a4,a5,0,0,0,1,0);

thank you for your correction I just found an example " Combined Use of Programs" (https://book.mql4.com/samples/shared) in mql5 I think that example in codig is what I need. I will study that part, if have question in my programing I hope you would help me to get it run getting more stable and more profit 

Combined Use of Programs - Simple Programs in MQL4 - MQL4 Tutorial
Combined Use of Programs - Simple Programs in MQL4 - MQL4 Tutorial
  • book.mql4.com
It was said earlier that according to MQL4 rules trade functions cannot be used in custom indicators, that is why for automated trading Expert Advisors or scripts should be used. However, the resource-saving technology used for calculations in indicators (see Creation of Custom Indicators) is widely used when creating trading programs. In most...
 
William Roeder:

Absolutely not.

I have the code this way now I cn see the buffers 1, 2 of the TrendTarget (But still not all 4 digits correct!!!), I set the BarsIndex value on every stick to  1 because I like to recheck the TrendTarget 

   double shortSma, longSma, ShortSL, ShortTP, LongSL, LongTP,Band_UP,Band_LO;

   double Value1,Value2 ;





   Value1 = iCustom(Symbol(),0,"TrendTarget.ex4",60,1,1);

   Value2 = iCustom(Symbol(),0,"TrendTarget.ex4",60,2,1);

   Band_UP = Value1;

   Band_LO = Value2;

   Comment(" !!!!!!! ICUSTOM returned Value1= "+Value1+ " and value2= ",Value2+"\n");

But I still have problem. I use TrendTarget like a filter
if(tik <= 5 && Ask>Band_UP) ///////////////ONLY can open SELL////////////////
        {
         ////////////////////// TP1 SL1 ///////////////////////////////////
         openOrder(Symbol(), OP_SELLSTOP,LotSize,sellPrice,sellPrice+SL1*point(), sellPrice-TP1*point(),"_Sell_1",MagicNumber,exp,Crimson);
        }

      if(tik <= 5 && Bid<Band_LO)   ///////////////ONLY can open BUY////////////////

        {
         ////////////////////// TP1 SL1 ///////////////////////////////
         openOrder(Symbol(), OP_BUYSTOP,LotSize,buyPrice,buyPrice-SL1*point(), buyPrice+TP1*point(),"_Buy_1",MagicNumber,exp,Navy);
        }
but after its run, I attach the TrendTarget indicator and I see the EA still opened many trades in between the channel!!!!!

In the picture I add the TrendTarget after it starts. When I create a tester template with include TrendTarget (parameter TF=60) the channel only show for the first X bars, then I can only see the price curve, why is it?
How can I simple add the Trend Target  indicator for visual checking where orders are opened? 

I like to use in the code the value_UP in the past, similare the use of close: before yesterday Close[2], yesterday Close[1], curren close Close[0]? Is it possible?  
Files:
 
Problem I still have with the scap test EA are following:

1rst problem:
I can see the buffers 1, 2 of the TrendTarget (But still not all 4 digits correct!!!), is it important? for EURUSD quote 1.0907 I thought when the price value should be compared with TrendTarget upper channel or lower channel, those values of TrendTarget should be exact correct at least 4 decimal digits.
I set the BarsIndex value on every stick to 1 because I like to recheck the TrendTarget

2nd problem:
But I still have problem. I use TrendTarget like a filter.

but after its run, I attach the TrendTarget indicator and then I see the EA still opened many trades in between the channel!!!!!

3rd problem:
In the attached picture I have to add the TrendTarget after it starts. When I create a tester template with include TrendTarget (parameter TF=60) the TrendTarget channel is only shown for the first X bars, maybe 100, then I can only see the price curve, why is it?

4rth problem:
How can I simple add the Trend Target indicator for run-time visual checking where orders are opened?

5th problem:
I like to use in the code the value_UP in the past, similar to the use of close: before yesterday Close[2], yesterday Close[1], current close Close[0]? Is it possible? Because there could be a longer than few bars break-out, in that case I like to change the strategy to breakout trading, instead, only an theory i still can not know how to do it in coding

6th problem:
When condition is touched, for example I like to open only 1 order, here because price remains many bar above upper channel so condition is right always, it open until my account runs out! How to do sending only one order , then wait for condition to change.?

7th problem:
Does any one know what the trendtarget is it seems to me a trrend line or MA(x) of price with +/- 1xATR(14) added to each side is that correct. Has someone the code for it?
Reason: