• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 1:00am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 1:00am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Mt4 Indicator Guru Needed To Code Indicator For Me 4 replies

Inside Candle Indicator needs ref to Bollinger and/or Stochastics 0 replies

Inside Bar Indicator fix needed 0 replies

Inside Bar indicator needed 2 replies

What's Wrong with this Inside Bar Indicator 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 7
Attachments: indicator code to inside EA code
Exit Attachments
Tags: indicator code to inside EA code
Cancel

indicator code to inside EA code

  • Post #1
  • Quote
  • First Post: Sep 15, 2018 1:34am Sep 15, 2018 1:34am
  •  munna00
  • Joined Feb 2018 | Status: Member | 112 Posts
convert indicator array code for EA code

i tried several method but fails

i dont want to use icustom, i want directly use indi code to EA

indicator here:

Inserted Code
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  DarkGray
#property indicator_color2  PaleVioletRed
#property indicator_color3  HotPink
#property indicator_width2  2
#property indicator_level2  3
#property indicator_minimum 0
#property indicator_levelcolor DarkGray
//
 
extern int    VolPeriod          = 14;
extern int    VolPrice           = PRICE_CLOSE;
extern int    Smooth             = 3;
extern int    SmoothMethod       = MODE_LWMA;
extern double DeviationsForSteps = 2.0;
double vol[];
double volavg[];
double volsteps[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
 int init()
 
{
   SetIndexBuffer(0,vol);
   SetIndexBuffer(1,volavg);
   SetIndexBuffer(2,volsteps);
      Smooth = MathMax(Smooth,1);
   return(0);
}
int deinit() { return(0); }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
 
int start()
{
   int count,counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);
 
   //
    
      for(int i = limit; i >= 0; i--)
      {
         double range = MathMax(High[i],Close[i+1])-MathMin(Low[i],Close[i+1]);
         double atr   = iATR(NULL,0,VolPeriod,i+1);
            if (atr!=0)
                  vol[i] = range/atr;
            else  vol[i] = 0;                  
      }
      for(i = limit; i >= 0; i--) volavg[i] = iMAOnArray(vol,0,Smooth,0,SmoothMethod,i);
      for(i = limit; i >= 0; i--)
      {
         volsteps[i] = volsteps[i+1];
         if (DeviationsForSteps>0)
         {
            double deviation = DeviationsForSteps*iStdDevOnArray(vol,0,VolPeriod,0,MODE_SMA,i);
               if (vol[i] > volsteps[i+1]+deviation) volsteps[i] = vol[i];
               if (vol[i] < volsteps[i+1]-deviation) volsteps[i] = vol[i];
          }
          else volsteps[i] = 1;              
      }
      
   return(0);
}

i want this indicator code to apply in EA code inside
i set variable to collect array data but failed
Inserted Code
 x = vol[0];
 xx = volavg[0];
xxx = volsteps[0];

Without icustom is it possible?
  • Post #2
  • Quote
  • Sep 15, 2018 6:52am Sep 15, 2018 6:52am
  •  reteid2222
  • Joined Aug 2015 | Status: Member | 2,507 Posts
Quoting munna00
Disliked
convert indicator array code for EA code i tried several method but fails i dont want to use icustom, i want directly use indi code to EA indicator here: #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 DarkGray #property indicator_color2 PaleVioletRed #property indicator_color3 HotPink #property indicator_width2 2 #property indicator_level2 3 #property indicator_minimum 0 #property indicator_levelcolor DarkGray // extern int VolPeriod = 14; extern int VolPrice = PRICE_CLOSE; extern int Smooth = 3; extern...
Ignored
I think it is possible not to post the same request multiple times at the same moment.....(have answered this just search on your requests!)
Attached Image
Vucking good EA coder...
1
 
  • Post #3
  • Quote
  • Edited 7:47am Sep 15, 2018 7:34am | Edited 7:47am
  •  masterx584
  • Joined Apr 2016 | Status: By By FF :) | 141 Posts
Quoting munna00
Disliked
convert indicator array code for EA code i tried several method but fails i dont want to use icustom, i want directly use indi code to EA indicator here: #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 DarkGray #property indicator_color2 PaleVioletRed #property indicator_color3 HotPink #property indicator_width2 2 #property indicator_level2 3 #property indicator_minimum 0 #property indicator_levelcolor DarkGray // extern int VolPeriod = 14; extern int VolPrice = PRICE_CLOSE; extern int Smooth = 3; extern...
Ignored
Converted into a function that you are going to insert into your expert code.You define the 3 arrays at global variables as i did .The function will resize and initialize them based on the number of bars you want to calculate.The barsNumber need to be bigger than your VolPeriod which is 14 in this case.If you need to access only the last value of the 3 arrays you can calculate max 50 bars for example.

at global variables inside EA,only 1 element arrays since the function will resize them
Inserted Code
double vol[1];
double volavg[1];
double volsteps[1];

the function to insert into EA code
Inserted Code
void VolAvg(int barsNumber,int VolPeriod,int  VolPrice,int Smooth ,int SmoothMethod,double DeviationsForSteps)
{
      ArrayResize(vol,barsNumber,0);
      ArrayResize(volavg,barsNumber,0);
      ArrayResize(volsteps,barsNumber,0);
      ArrayInitialize(vol,0);
      ArrayInitialize(volavg,0);
      ArrayInitialize(volsteps,0);
      
      Smooth = MathMax(Smooth,1);
      for(int i = barsNumber; i >= 0; i--)
      {
         double range = MathMax(High[i],Close[i+1])-MathMin(Low[i],Close[i+1]);
         double atr   = iATR(NULL,0,VolPeriod,i+1);
            if (atr!=0)
                  vol[i] = range/atr;
            else  vol[i] = 0;                  
      }
      for(i = barsNumber; i >= 0; i--) volavg[i] = iMAOnArray(vol,0,Smooth,0,SmoothMethod,i);
      for(i = barsNumber; i >= 0; i--)
      {
         volsteps[i] = volsteps[i+1];
         if (DeviationsForSteps>0)
         {
            double deviation = DeviationsForSteps*iStdDevOnArray(vol,0,VolPeriod,0,MODE_SMA,i);
               if (vol[i] > volsteps[i+1]+deviation) volsteps[i] = vol[i];
               if (vol[i] < volsteps[i+1]-deviation) volsteps[i] = vol[i];
          }
          else volsteps[i] = 1;              
      }
}

on the onTick() expert loop you first call the function to load the 3 arrays and only after your expert will use the 3 arrays to trigger events
Inserted Code
//load the arrays
VolAvg(100,14,PRICE_CLOSE,3, MODE_LWMA,2.0);
//use them
if(vol[0]>  ... etc... do whatever you want...trigger buy/sell
if (volavg[0]>  ... etc... do whatever you want...trigger buy/sell
if( volsteps[0]> ... etc... do whatever you want...trigger buy/sell

Here you have your indicator converted into a function still working great,calculating only last 100 bars
Attached Image (click to enlarge)
Click to Enlarge

Name: AUDUSDM5.png
Size: 38 KB
Attached File(s)
File Type: mq4 test.mq4   2 KB | 522 downloads
Attached File(s)
File Type: ex4 test.ex4   10 KB | 358 downloads

tested and working...good luck
It's show time
 
 
  • Post #4
  • Quote
  • Edited 6:35pm Sep 16, 2018 12:54pm | Edited 6:35pm
  •  masterx584
  • Joined Apr 2016 | Status: By By FF :) | 141 Posts
The function inside the EA gives instant Array out of range error ,because is calculating from the last bar to the first bar..I modify this
Inserted Code
ArrayResize(vol,barsNumber+2,0);
ArrayResize(volavg,barsNumber+2,0);
ArrayResize(volsteps,barsNumber+2,0);
and clear the error but than i notice diff values vs the same function inside the indicator.
You need to go back to the iCustom method.When the indicator is inside the ea it gives alot of bugs,errors.Only the vol array is stable.I compared with the values given from the indicator.
The same function inside an indicator runs perfectly but inside an EA even if i increased Array size more than needed act strange.I'm sorry for you but i found similar problems when i put on the same chart an EA and a script.The EA was making the script to act in a really strange way.With only the script on the chart the script was perfect,...only the EA on chart , the ea was perfect...when both EA and script were on the same chart ,the EA was crazy ,the script was crazy....just because MT4 doesn't compile the code but is unifying diff codes into one at runtime and combine different variables which also may have the same names )...MQL4 is full of problems,i don't use it ,i code in C++ only.

for example when the indicator and the ea are dropped on GBPUSD both vol and volsteps arrays are perfect and the volavg is with error and without making any modification when dropping on USDCHF only the vol is good , both volavg and volsteps are giving problems ...this means bugs on MT4 since the code is unchanged ,only the symbol was changed.When i made the tests i fully reinitialised the expert and the indicator to clean the memory.
check the diffrences,green= identical.
Attached Image (click to enlarge)
Click to Enlarge

Name: t1.PNG
Size: 25 KB
Attached Image (click to enlarge)
Click to Enlarge

Name: t2.PNG
Size: 26 KB

MT4 translates the MQL4 functions into lower level code at runtime but is not doing it in the right way.I hope somebody can give you a better solution.As indicator the function is OK ...as EA is not ok anymore.Even initialising the arrays on the expert Init ,not inside the function or giving them more elements than the function is using on the global definitions ex. vol[500] and the function only need 100 elements doesn't solve the problem.
It's show time
 
 
  • Post #5
  • Quote
  • Sep 16, 2018 1:35pm Sep 16, 2018 1:35pm
  •  munna00
  • Joined Feb 2018 | Status: Member | 112 Posts
i appreciate the respond...
 
 
  • Post #6
  • Quote
  • Edited 3:21pm Sep 16, 2018 3:07pm | Edited 3:21pm
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Quoting masterx584
Disliked
{quote} Converted into a function that you are going to insert into your expert code.You define the 3 arrays at global variables as i did .The function will resize and initialize them based on the number of bars you want to calculate.The barsNumber need to be bigger than your VolPeriod which is 14 in this case.If you need to access only the last value of the 3 arrays you can calculate max 50 bars for example. at global variables inside EA,only 1 element arrays since the function will resize them double vol[1]; double volavg[1]; double volsteps[1];...
Ignored
OMG... don't actually do this, munna! This is such a antiquated and amatuer way to code. You're going to clutter up your global namespace with a bunch of unnecessary global arrays as artifacts from an indicator source that shouldn't have been included in the first place. This is really-really bad advice!

Let's start with why you want to include the indicator in the expert code...

 

  1. Is it because you think it is an optimization?

    1. If so, its not. It's faster to allow your indicator to run asynchronously with your EA



  2. Are you trying to hide the implementation details of your EA so you only have to distribute one file?

    1. If that's the case then you need to still use iCustom as you normally would but include your indicator as a resource. When you compile your EA the indicator will be packaged in with (hidden inside of) the .ex4 file.




 
 
  • Post #7
  • Quote
  • Sep 16, 2018 6:37pm Sep 16, 2018 6:37pm
  •  masterx584
  • Joined Apr 2016 | Status: By By FF :) | 141 Posts
Quoting munna00
Disliked
i appreciate the respond...
Ignored
Nicholisen was right,including as resource is better.
Working with custom indicators included as resources
One or several custom indicators may be necessary for the operation of MQL4 applications. All of them can be included into the code of an executable MQL5 program. Inclusion of indicators as resources simplifies the distribution of applications.
Below is an example of including and using SampleIndicator.ex4 custom indicator located in terminal_data_folder\MQL4\Indicators\ directory:
//+------------------------------------------------------------------+
//| SampleEA.mq4 |
//| Copyright 2013, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#resource "\\Indicators\\SampleIndicator.ex4"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- get custom indicator value
double value=iCustom(_Symbol,_Period,"::Indicators\\SampleIndicator.ex4",0,0);
PrintFormat("Indicator: iCustom value=%f",value);
//--- ...
return(INIT_SUCCEEDED);
}
It's show time
 
1
  • Post #8
  • Quote
  • Sep 16, 2018 7:14pm Sep 16, 2018 7:14pm
  •  voketexpert
  • | Additional Username | Joined Aug 2018 | 549 Posts
Quoting Nicholishen
Disliked
{quote} OMG... don't actually do this, munna! This is such a antiquated and amatuer way to code. You're going to clutter up your global namespace with a bunch of unnecessary global arrays as artifacts from an indicator source that shouldn't have been included in the first place. This is really-really bad advice! Let's start with why you want to include the indicator in the expert code... Is it because you think it is an optimization? If so, its not. It's faster to allow your indicator to run asynchronously with your EA Are you trying to hide the...
Ignored
I Agree with nicholsen.

there is no other way unless you infiltrate to existing namespace.
MQ4 and ex4 are different.
Its okay to have 2 source code. as long as you have one compiled app, there will be nobody to know.
Profit growth tells you the trader ability.
 
 
  • Post #9
  • Quote
  • Sep 17, 2018 12:48am Sep 17, 2018 12:48am
  •  VEEFX
  • Joined Jun 2006 | Status: Adios! | 3,377 Posts
Quoting Nicholishen
Disliked
{quote} OMG... don't actually do this, munna! This is such a antiquated and amatuer way to code. You're going to clutter up your global namespace with a bunch of unnecessary global arrays as artifacts from an indicator source that shouldn't have been included in the first place. This is really-really bad advice! Let's start with why you want to include the indicator in the expert code... Is it because you think it is an optimization? If so, its not. It's faster to allow your indicator to run asynchronously with your EA Are you trying to hide the...
Ignored
Interesting...I had no idea we could include an indicator as a #resource. When I run my EA in Display/Debug mode, I do call several icustom "indicators" (more like tools). Question: like my EA, I compile my tools also frequently. If I use a resource as EXE (in the example from masterx, would the EA automatically reflect the changes or do I have to recompile the EA also?

Thanks for the example Master. Great things are possible when we are open to collaboration and disagreements :-)
Staying in my lane...
 
 
  • Post #10
  • Quote
  • Sep 17, 2018 3:24am Sep 17, 2018 3:24am
  •  reteid2222
  • Joined Aug 2015 | Status: Member | 2,507 Posts
Quoting VEEFX
Disliked
{quote} Interesting...I had no idea we could include an indicator as a #resource. When I run my EA in Display/Debug mode, I do call several icustom "indicators" (more like tools). Question: like my EA, I compile my tools also frequently. If I use a resource as EXE (in the example from masterx, would the EA automatically reflect the changes or do I have to recompile the EA also? Thanks for the example Master. Great things are possible when we are open to collaboration and disagreements :-)
Ignored
Just start here with reading:
https://docs.mql4.com/runtime/resources
Vucking good EA coder...
 
1
  • Post #11
  • Quote
  • Sep 17, 2018 7:02am Sep 17, 2018 7:02am
  •  munna00
  • Joined Feb 2018 | Status: Member | 112 Posts
is it possible when compile EA to ex4 it packed with indicator ex4 so that icustom can works
 
 
  • Post #12
  • Quote
  • Sep 17, 2018 7:09am Sep 17, 2018 7:09am
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Quoting munna00
Disliked
is it possible when compile EA to ex4 it packed with indicator ex4 so that icustom can works
Ignored
Whoosh
 
 
  • Post #13
  • Quote
  • Sep 17, 2018 7:13am Sep 17, 2018 7:13am
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Quoting VEEFX
Disliked
{quote} Interesting...I had no idea we could include an indicator as a #resource. When I run my EA in Display/Debug mode, I do call several icustom "indicators" (more like tools). Question: like my EA, I compile my tools also frequently. If I use a resource as EXE (in the example from masterx, would the EA automatically reflect the changes or do I have to recompile the EA also? Thanks for the example Master. Great things are possible when we are open to collaboration and disagreements :-)
Ignored
There's a small performance penalty when you compile your indicator with the EA. Don't do it unless you intend to distribute a single executable
 
 
  • Post #14
  • Quote
  • Sep 17, 2018 11:48am Sep 17, 2018 11:48am
  •  munna00
  • Joined Feb 2018 | Status: Member | 112 Posts
Quoting voketexpert
Disliked
{quote} I Agree with nicholsen. there is no other way unless you infiltrate to existing namespace. MQ4 and ex4 are different. Its okay to have 2 source code. as long as you have one compiled app, there will be nobody to know.
Ignored
in main indicator when i use #property strict no buffer showing in data window also in chart

Inserted Code
#property strict
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 3
//#property indicator_color1  DarkGray
//#property indicator_color2  PaleVioletRed
//#property indicator_width2  2
//#property indicator_level2  3
//#property indicator_minimum 0
//#property indicator_levelcolor DarkGray

but we are using #property strict in our coded EA, is the cause that indi code not working in EA?
 
 
  • Post #15
  • Quote
  • Aug 16, 2020 9:16am Aug 16, 2020 9:16am
  •  chimwele
  • | Joined Aug 2020 | Status: Member | 5 Posts
please assist me with converting this TMA indicator to an Ea
Attached Image (click to enlarge)
Click to Enlarge

Name: Screenshot1.png
Size: 35 KB
 
 
  • Post #16
  • Quote
  • Last Post: Dec 29, 2021 5:41am Dec 29, 2021 5:41am
  •  Musharib
  • | Joined Nov 2021 | Status: Member | 50 Posts
hello there !
how to code EA to take 1 trade per signal and wait for new signal for next trade even it hit tp.

Example
if EA place buy trade in buy signal and it hit the 5pip and current trend is buy when tp hit it will not place anymore trade in buy trend it will wait for next new signal which will be sell then it will place sell trade .


any code or function for this

 
 
  • Platform Tech
  • /
  • indicator code to inside EA code
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023