Forex
Google
New signals service!

Go Back   Forex Trading > Downloads > Indicators - Metatrader 4


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
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2006, 05:03 AM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
Coding help..How do I get indicator to filter instead of alert?

This produces an alert when the price reaches an upper or lower line.

I want to allow trades to execute until they come close to these lines. When the price gets too close not allow trades to open.

how do I get that logic to happen on current bar closing(s) when all that are here are arrays?

PHP Code:
for(int x=0x<limitx++) {
      
Xdown[x] = 0Xup[x] = 0;
      
middle1[x] = iMA(NULL0period0MODE_EMAPRICE_TYPICALx);// drawn line
      
middle2iMA(NULL0period0MODE_SMAPRICE_TYPICALx);// only used to calculate outer bands

      
avg  findAvg(periodx);
      
upper[x] = middle2 + (3.5*avg);
      
lower[x] = middle2 - (3.5*avg);

      
      if (
MathAbs(upper[x] - High[x]) < 2*Point)
      {
         
Xdown[x] = upper[x];
         if (
NewBar() && == 0)
            
Alert(Symbol()," ",Period()," reach upper edge");
      }   
      if (
MathAbs(lower[x] - Low[x]) < 2*Point)
      {
         
Xup[x] = lower[x];
         if (
NewBar() && == 0)
            
Alert(Symbol()," ",Period()," reach lower edge");
      }
   }
   return(
0);
  } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-30-2006, 05:49 AM
Member
 
Join Date: Mar 2006
Posts: 49
pipeline is on a distinguished road
I see you re trying hard, well done! At this stage I feel that what you need most is to know how to help yourself, so I would advise to use MQL's "NAvigator->Search" function _extensively_, you'll find answers to many of your questions (the only thing one can call from an indicator are the buffers, and this is done through iCustom(); Objects are not arrays etc. and much much more). For example, a search for "array" will teach that Current Bar's array index is 0, Last Bar's arrray index is 1 and so on.

If the search function entries are all overwhelming, you're probably trying to do stuff too difficult for you at this stage. I believe most of the examples above are touched on in codersguru's beginner's course, so I would recommend a second reading.
You might also take a simple EA, and try to simplify/modify it slightly, that will teach you how it works. Once it's done, you can try to complexify it.
Sorry if i m off the mark.

Now, in general, to work on Close price, you test for the Opening of a new bar and then write your conditions on arrays' index 1. A possible code to detect the Opening of a new bar:

bool NewBar()
{
static datetime dt = 0;

if (Time[0] != dt)
{
dt = Time[0];
return(true);
}
return(false);
}

Hope this helps, good luck.

Last edited by pipeline; 06-30-2006 at 05:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-30-2006, 06:47 AM
fx-programmer's Avatar
Senior Member
 
Join Date: Apr 2006
Location: europe
Posts: 118
fx-programmer is on a distinguished road
Yes, you are on the right track.
I would halt all, and re-read c++ programming.
Unfortunately Object oriented is not that great for mq4, so you will have to compensate with the basics.
Keep it up mate, youll get there.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-30-2006, 07:41 AM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 350
elihayun is on a distinguished road
Quote:
Originally Posted by Aaragorn
This produces an alert when the price reaches an upper or lower line.

I want to allow trades to execute until they come close to these lines. When the price gets too close not allow trades to open.

how do I get that logic to happen on current bar closing(s) when all that are here are arrays?
You can have this as an example. It close to what u want to get. As far as I can see, its the same indicator that u are using.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-30-2006, 11:46 AM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
Quote:
Originally Posted by pipeline
I see you re trying hard, well done! At this stage I feel that what you need most is to know how to help yourself, so I would advise to use MQL's "NAvigator->Search" function _extensively_, you'll find answers to many of your questions (the only thing one can call from an indicator are the buffers, and this is done through iCustom(); Objects are not arrays etc. and much much more). For example, a search for "array" will teach that Current Bar's array index is 0, Last Bar's arrray index is 1 and so on.

If the search function entries are all overwhelming, you're probably trying to do stuff too difficult for you at this stage. I believe most of the examples above are touched on in codersguru's beginner's course, so I would recommend a second reading.
You might also take a simple EA, and try to simplify/modify it slightly, that will teach you how it works. Once it's done, you can try to complexify it.
Sorry if i m off the mark.

Now, in general, to work on Close price, you test for the Opening of a new bar and then write your conditions on arrays' index 1. A possible code to detect the Opening of a new bar:

bool NewBar()
{
static datetime dt = 0;

if (Time[0] != dt)
{
dt = Time[0];
return(true);
}
return(false);
}

Hope this helps, good luck.

ok about that search function...it doesn't return anything. I have tried to use it several times in the metaeditor. I type in what I want and hit return and nothing happens, or I click that little go box next to the search string and nothing happens. I was just noticing what a lame searh it is because it doesn't work at all. I am referring to the search feature in the metaeditor navigator window...is there some protocol to make it work that I don't know about?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-30-2006, 11:50 AM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
Quote:
I am thinking today of saying to hell with the indicators and just see if I can create something that will let me reference the highest high and the lowest low of the previous(x) bars.
The more I look at indicators the more attractive this seems....

ok i see the high() in predefined variables. how do i use it to get the highest high of the last 30 hours for example?

Last edited by Aaragorn; 06-30-2006 at 12:21 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-30-2006, 11:52 AM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
Quote:
Originally Posted by fx-programmer
Yes, you are on the right track.
I would halt all, and re-read c++ programming.
Unfortunately Object oriented is not that great for mq4, so you will have to compensate with the basics.
Keep it up mate, youll get there.
thankyou for the encouragement. moral support counts. Do you see what my theoretical goal is here? Could you suggest a better method (the basics as you call it) to accomplish this goal?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-30-2006, 12:08 PM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
This one has buffers...

PHP Code:
//+------------------------------------------------------------------+
//|                                               BBands_Stop_v1.mq4 |
//|                           Copyright © 2006, TrendLaboratory Ltd. |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                       E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Chartreuse
#property indicator_color2 Orange
#property indicator_color3 Chartreuse
#property indicator_color4 Orange
#property indicator_color5 Chartreuse
#property indicator_color6 Orange
//---- input parameters
extern int    Length=20;      // Bollinger Bands Period
extern int    Deviation=2;    // Deviation
extern double MoneyRisk=1.00// Offset Factor
extern int    Signal=1;       // Display signals mode: 1-Signals & Stops; 0-only Stops; 2-only Signals;
extern int    Line=1;         // Display line mode: 0-no,1-yes  
extern int    Nbars=1000;
//---- indicator buffers
double UpTrendBuffer[];
double DownTrendBuffer[];
double UpTrendSignal[];
double DownTrendSignal[];
double UpTrendLine[];
double DownTrendLine[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  
int init()
  {
   
string short_name;
//---- indicator line
   
   
SetIndexBuffer(0,UpTrendBuffer);
   
SetIndexBuffer(1,DownTrendBuffer);
   
SetIndexBuffer(2,UpTrendSignal);
   
SetIndexBuffer(3,DownTrendSignal);
   
SetIndexBuffer(4,UpTrendLine);
   
SetIndexBuffer(5,DownTrendLine);
   
SetIndexStyle(0,DRAW_ARROW);
   
SetIndexStyle(1,DRAW_ARROW);
   
SetIndexStyle(2,DRAW_ARROW);
   
SetIndexStyle(3,DRAW_ARROW);
   
SetIndexStyle(4,DRAW_LINE);
   
SetIndexStyle(5,DRAW_LINE);
   
SetIndexArrow(0,159);
   
SetIndexArrow(1,159);
   
SetIndexArrow(2,108);
   
SetIndexArrow(3,108);
   
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   
short_name="BBands Stop("+Length+","+Deviation+")";
   
IndicatorShortName(short_name);
   
SetIndexLabel(0,"UpTrend Stop");
   
SetIndexLabel(1,"DownTrend Stop");
   
SetIndexLabel(2,"UpTrend Signal");
   
SetIndexLabel(3,"DownTrend Signal");
   
SetIndexLabel(4,"UpTrend Line");
   
SetIndexLabel(5,"DownTrend Line");
//----
   
SetIndexDrawBegin(0,Length);
   
SetIndexDrawBegin(1,Length);
   
SetIndexDrawBegin(2,Length);
   
SetIndexDrawBegin(3,Length);
   
SetIndexDrawBegin(4,Length);
   
SetIndexDrawBegin(5,Length);
//----
   
return(0);
  }

//+------------------------------------------------------------------+
//| Bollinger Bands_Stop_v1                                             |
//+------------------------------------------------------------------+
int start()
  {
   
int    i,shift,trend;
   
double smax[25000],smin[25000],bsmax[25000],bsmin[25000];
   
   for (
shift=Nbars;shift>=0;shift--)
   {
   
UpTrendBuffer[shift]=0;
   
DownTrendBuffer[shift]=0;
   
UpTrendSignal[shift]=0;
   
DownTrendSignal[shift]=0;
   
UpTrendLine[shift]=EMPTY_VALUE;
   
DownTrendLine[shift]=EMPTY_VALUE;
   }
   
   for (
shift=Nbars-Length-1;shift>=0;shift--)
   {    
     
smax[shift]=iBands(NULL,0,Length,Deviation,0,PRICE_CLOSE,MODE_UPPER,shift);
      
smin[shift]=iBands(NULL,0,Length,Deviation,0,PRICE_CLOSE,MODE_LOWER,shift);
    
      if (
Close[shift]>smax[shift+1]) trend=1
      if (
Close[shift]<smin[shift+1]) trend=-1;
             
      if(
trend>&& smin[shift]<smin[shift+1]) smin[shift]=smin[shift+1];
      if(
trend<&& smax[shift]>smax[shift+1]) smax[shift]=smax[shift+1];
            
      
bsmax[shift]=smax[shift]+0.5*(MoneyRisk-1)*(smax[shift]-smin[shift]);
      
bsmin[shift]=smin[shift]-0.5*(MoneyRisk-1)*(smax[shift]-smin[shift]);
        
      if(
trend>&& bsmin[shift]<bsmin[shift+1]) bsmin[shift]=bsmin[shift+1];
      if(
trend<&& bsmax[shift]>bsmax[shift+1]) bsmax[shift]=bsmax[shift+1];
      
      if (
trend>0
      {
         if (
Signal>&& UpTrendBuffer[shift+1]==-1.0)
         {
         
UpTrendSignal[shift]=bsmin[shift];
         
UpTrendBuffer[shift]=bsmin[shift];
         if(
Line>0UpTrendLine[shift]=bsmin[shift];
         }
         else
         {
         
UpTrendBuffer[shift]=bsmin[shift];
         if(
Line>0UpTrendLine[shift]=bsmin[shift];
         
UpTrendSignal[shift]=-1;
         }
      if (
Signal==2UpTrendBuffer[shift]=0;   
      
DownTrendSignal[shift]=-1;
      
DownTrendBuffer[shift]=-1.0;
      
DownTrendLine[shift]=EMPTY_VALUE;
      }
      if (
trend<0
      {
      if (
Signal>&& DownTrendBuffer[shift+1]==-1.0)
         {
         
DownTrendSignal[shift]=bsmax[shift];
         
DownTrendBuffer[shift]=bsmax[shift];
         if(
Line>0DownTrendLine[shift]=bsmax[shift];
         }
         else
         {
         
DownTrendBuffer[shift]=bsmax[shift];
         if(
Line>0)DownTrendLine[shift]=bsmax[shift];
         
DownTrendSignal[shift]=-1;
         }
      if (
Signal==2DownTrendBuffer[shift]=0;    
      
UpTrendSignal[shift]=-1;
      
UpTrendBuffer[shift]=-1.0;
      
UpTrendLine[shift]=EMPTY_VALUE;
      }
      
     }
    return(
0);    
 } 
good grief charlie brown it has 6 buffers! geeze isnt' there a SIMPLE channel indicator somewhere?

Last edited by Aaragorn; 06-30-2006 at 12:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-30-2006, 12:15 PM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
Quote:
Originally Posted by pipeline

Now, in general, to work on Close price, you test for the Opening of a new bar and then write your conditions on arrays' index 1. A possible code to detect the Opening of a new bar:

bool NewBar()
{
static datetime dt = 0;

if (Time[0] != dt)
{
dt = Time[0];
return(true);
}
return(false);
}

Hope this helps, good luck.
it almost helps if you know what I mean..assuming it returns true then what, how do you get the value of the indicator out of the array at the current close now that it's been detected that there is a new bar?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-30-2006, 12:17 PM
Senior Member
 
Join Date: Mar 2006
Posts: 787
Maji is on a distinguished road
Quote:
Originally Posted by Aaragorn
Last night I was googling around and found this...
http://www.gordago.com/?act=download
does anyone have any experience with this? is it for real?
Gordago does not handle or is still not capable of handling custom indicators. That is a major drawback.

The only way to learn programming is to slog it out, like you are doing now... learning from examples. Coders' Guru's stuff is great for learning.

Good luck,
Maji
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks