Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #91 (permalink)  
Old 06-28-2009, 11:33 PM
Member
 
Join Date: Apr 2008
Posts: 50
okfar is on a distinguished road
Quote:
Originally Posted by Xaun View Post
I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.



EA Code
Code:
double test4_up[];
double test4_down[];
double test3_up[];
double test3_down[];
double test2_up[];
double test2_down[];
double test1_up[];
double test1_down[];

int UniqueNum = 009;
..
..
...
......
..

   int i=0;
   int limit=Bars-counted_bars;

 ArrayResize(test4_up, limit);
 ArrayResize(test4_down, limit); 


    for(i=0;i<limit;i++)
    {
      test4_up[i] = iCustom(NULL, 0, "#TestIndicator",0,i);
      test4_down[i] = iCustom(NULL, 0, "#TestIndicator",1,i);
      
    }
    for(i=0;i<30;i++)
    {
      Print("Test 4 UP ", test4_up[i]," Bar ",i );
      Print("Test 4 DOWN ", test4_down[i]," Bar ",i );
      //Print("This is a test");
    }
    
//----
   return(0);
  }
//+---------
]
Maybay you need define size of array in you EA.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #92 (permalink)  
Old 06-29-2009, 02:37 AM
Junior Member
 
Join Date: May 2009
Posts: 2
Xaun is on a distinguished road
Thanks

Quote:
Originally Posted by okfar View Post
Maybay you need define size of array in you EA.
Thanks Okfar. That was exactly the problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #93 (permalink)  
Old 06-29-2009, 03:39 PM
cockeyedcowboy's Avatar
Senior Member
 
Join Date: Nov 2005
Posts: 474
cockeyedcowboy is on a distinguished road
Depending how your going to access your data you donot have to refill the array on each tick just like you dont have to recalculate indicators. see



bool ArraySetAsSeries(double&array[], bool set)Sets indexing direction of the array. If the set parameter has the TRUE value, the array will be indexed in a reversed order, i.e., the last element has a zero index. The FALSE value sets a standard indexing order. The function returns the previous status.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #94 (permalink)  
Old 06-29-2009, 05:48 PM
mladen's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,210
mladen is on a distinguished road
...

You are trying to use features that are meant to be used exclusively from an indicator.

IndicatorCounted() has no meaning at all when called from an EA. It always returns -1 when called within EA code. Try using a constant instead (like in your second loop) or Bars (if you want the whole history).
Also, arrays used within EA should be sized, initialized and the whole work that normally metatrader does when it comes to indicators and buffers within indicators. EA does not have an equivalent of SetIndexBuffer() that is used in indicators. You are having uninitialized arrays in your Ea and only metatrader prevented your EA from crashing the platform (it always returns 0 in those cases, since the element value you are trying to read does not exist, and in fact, those arrays do not exist (they are just declared, not allocated, initialized,...))

regards
mladen

Quote:
Originally Posted by Xaun View Post
I have a simple Custom Indicator with no externs called #TestIndicator that fills 8 buffers with the number 1.0 but when I bring back the buffers in my EA the buffer results are always 0 . Can you help me with this.

#TestIndicator
Code:
#property indicator_chart_window
#property indicator_buffers 8

double buf4_up[];
double buf4_down[];
double buf3_up[];
double buf3_down[];
double buf2_up[];
double buf2_down[];
double buf1_up[];
double buf1_down[];

int UniqueNum = 0070;

string shortname = "";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
      shortname = "#TFX";
         IndicatorBuffers(8);
   
         IndicatorShortName(shortname);
      //---- indicators
         SetIndexBuffer(0,buf4_up);
         SetIndexBuffer(1,buf4_down);
         SetIndexBuffer(2,buf3_up);
         SetIndexBuffer(3,buf3_down);
         SetIndexBuffer(4,buf2_up);
         SetIndexBuffer(5,buf2_down);
         SetIndexBuffer(6,buf1_up);
         SetIndexBuffer(7,buf1_down);
        
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
      int limit;
      int counted_bars = IndicatorCounted();
  //---- the last calculated bar will be recalculated
      if(counted_bars > 0) 
          counted_bars--;
      limit = Bars - counted_bars - 1;
  //---- the main cycle
      for(int i = limit; i >= 0; i--)
        {
          //---- 
         buf4_up[i]=1.0;
         buf4_down[i]=1.0;
         buf3_up[i]=1.0;
         buf3_down[i]=1.0;
         buf2_up[i]=1.0;
         buf2_down[i]=1.0;
         buf1_up[i]=1.0;
         buf1_down[i]=1.0;

         
        }
//----
//----
   
//----
   return(0);
  }
//+------------------
EA Code
Code:
double test4_up[];
double test4_down[];
double test3_up[];
double test3_down[];
double test2_up[];
double test2_down[];
double test1_up[];
double test1_down[];

int UniqueNum = 009;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
      Print("Inside init");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
      Print("Inside deinit");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   Print("Inside start");
   int counted_bars=IndicatorCounted();
   int y5m=0, y1h=0, y30m=0, y15m=0, yy=0;
   int i=0;
   int limit=Bars-counted_bars;

    for(i=0;i<limit;i++)
    {
      test4_up[i] = iCustom(NULL, 0, "#TestIndicator",0,i);
      test4_down[i] = iCustom(NULL, 0, "#TestIndicator",1,i);
      
    }
    for(i=0;i<30;i++)
    {
      Print("Test 4 UP ", test4_up[i]," Bar ",i );
      Print("Test 4 DOWN ", test4_down[i]," Bar ",i );
      //Print("This is a test");
    }
    
//----
   return(0);
  }
//+---------
Results in Tester...

Last edited by mladen; 06-29-2009 at 06:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #95 (permalink)  
Old 07-10-2009, 07:47 AM
Junior Member
 
Join Date: Jul 2009
Posts: 8
paytongannaway is on a distinguished road
Coding Question

I have an indicator that I am very fond of and have demo'd it for a couple of weeks and been pretty successful. Is there a way where I can automate buy/sell orders based on the indicator? Short summary is it's a small arrow pointing either up or down on the chart when the indicators I like line up. Is there a way that when the arrow pops up it will place an order for me?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #96 (permalink)  
Old 07-10-2009, 07:56 AM
Senior Member
 
Join Date: Sep 2007
Posts: 428
jturns23 is on a distinguished road
Quote:
Originally Posted by paytongannaway View Post
I have an indicator that I am very fond of and have demo'd it for a couple of weeks and been pretty successful. Is there a way where I can automate buy/sell orders based on the indicator? Short summary is it's a small arrow pointing either up or down on the chart when the indicators I like line up. Is there a way that when the arrow pops up it will place an order for me?
Codersguru has a whole tutorial on how to write an EA. Read it, you will learn a lot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #97 (permalink)  
Old 07-10-2009, 08:18 AM
Senior Member
 
Join Date: Nov 2006
Posts: 305
luxinterior is on a distinguished road
You can use the iCustom function to incorporate your external indicator but you'll have to write the other logic (buy/sell etc.) yourself. It's pretty straightforeward.

Good luck

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #98 (permalink)  
Old 07-10-2009, 06:18 PM
Junior Member
 
Join Date: Jul 2009
Posts: 8
paytongannaway is on a distinguished road
where is this codersguru at?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #99 (permalink)  
Old 07-29-2009, 06:13 PM
Junior Member
 
Join Date: Jul 2009
Location: Indonesia
Posts: 5
V-Force is on a distinguished road
I need help with iCustom for Histogram

Anyone can help me here? I am trying to do an object create of a uptrend or downtrend using iCustom and a indicator that displays Histogram bars above 0 and below 0.

How do i make use of the iCustom function to call on it that when its above 0, it a uptrend and when its below 0 its a downtrend?

It goes something like this for now:

string Trigger="";
color colt6;
double trigger1 = iCustom(NULL, 0,"Trigger",24, ??????? , 0);


if ((trigger1 > 0)) { Trigger="UP"; colt6=Lime; }
if ((trigger1 < 0)) { Trigger="DOWN"; colt6=Red; }

ObjectCreate("MA00", OBJ_LABEL, 0, 0, 0);
ObjectSetText("MA00",Trigger,28, "Arial", colt6);
ObjectSet("MA00", OBJPROP_CORNER, 0);
ObjectSet("MA00", OBJPROP_XDISTANCE, 0);
ObjectSet("MA00", OBJPROP_YDISTANCE, 0);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #100 (permalink)  
Old 07-29-2009, 06:19 PM
Junior Member
 
Join Date: Jul 2009
Location: Indonesia
Posts: 5
V-Force is on a distinguished road
Need help on iCustom function

Quote:
Originally Posted by codersguru View Post
Sure, I'll do.
--------------------------------------------------------------------------------

Codesguru, can help me? I am trying to do an object create of a uptrend or downtrend using iCustom and a histogram indicator that displays Histogram bars above 0 and below 0.

How do i make use of the iCustom function to call on it that when its above 0, it an Uptrend and when its below 0 its a Downtrend? Also, how do i set a popup alert to alert 1 time only?

It goes something like this for now:

string Trigger="";
color colt6;
double trigger1 = iCustom(NULL, 0,"Trigger",24, ??????? , 0);


if ((trigger1 > 0)) { Trigger="UP"; colt6=Lime; }
if ((trigger1 < 0)) { Trigger="DOWN"; colt6=Red; }

ObjectCreate("MA00", OBJ_LABEL, 0, 0, 0);
ObjectSetText("MA00",Trigger,28, "Arial", colt6);
ObjectSet("MA00", OBJPROP_CORNER, 0);
ObjectSet("MA00", OBJPROP_XDISTANCE, 0);
ObjectSet("MA00", OBJPROP_YDISTANCE, 0);

if(Trigger==Up")
Alert(Symbol()," - ","H1:"," Uptrend"," at ", Bid);


Many thanks for anyone who can give a pointer on how I will be able to do the above.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
icustom, icustom function, iCustom()

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy iCustom and Alerts! codersguru Indicators - Metatrader 4 58 04-13-2009 09:30 AM
iCustom question .. yaniv_av Indicators - Metatrader 4 16 06-20-2008 05:37 PM
icustom maje Questions 24 12-05-2007 10:26 AM
I need help on creating an Icustom statement for my EA using this indicator as input! iscuba11 Expert Advisors - Metatrader 4 4 09-11-2006 08:18 PM
iCustom() problem billritz Indicators - Metatrader 4 5 08-23-2006 08:22 AM


All times are GMT. The time now is 11:38 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.