Thread: Ask!
View Single Post
  #3 (permalink)  
Old 11-09-2005, 03:42 AM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Lightbulb Alerts on cross!

Quote:
Originally Posted by newdigital
I have two question.

The first one. Sometimes it is necessary to test some trading srateg manually before creating the EA. It is ok for M1, M5 and M15. But for H1 and higher timeframe it is difficult. Which piece of the code should be included in one indicator (anyone) for alarm (sounds or whatever) to indicate about two lines of the one indicator crossing? For example the indicator is having two lines only which suppose to be crossed (with alarm).

Second. We have two indicators. Which pieces of the code should be included into one or two indicators to indicate about two line crossing: one line is from the first indicator and an other line is from an other one (all those two lines are in the same window of course)?
If it is EA or script should be created so keep this question untill we will study EA and script's creation.
Second question needs some work (the idea key is working with GlobalVariables to make the both of the indicators knows each others!)
I'll work in it later.

This is the code of the first question. It needs some test (it's 6:40 AM here )

PHP Code:
//+------------------------------------------------------------------+
//|                                                        Demo1.mq4 |
//|                                                    Coders' Guru. |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link      "http://www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
SetIndexStyle(0,DRAW_LINE);
   
SetIndexBuffer(0,ExtMapBuffer1);
   
SetIndexStyle(1,DRAW_LINE);
   
SetIndexBuffer(1,ExtMapBuffer2);
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   
return(0);
  }

bool Crossed (double line1 double line2 )
{

static 
string last_direction "";
string current_dirction "";

if(
line1>line2)current_dirction "up";
if(
line1<=line2)current_dirction "down";



if(
current_dirction != last_direction
{
      
Alert("CRROSED: Line1 is (" current_dirction ") Line2 now");
      
last_direction current_dirction;
      return (
true);
}
else
{
      return (
false);

}
 

int start()
  {
   
int    counted_bars=IndicatorCounted();
 
//---- check for possible errors
   
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
   
if (counted_bars>0counted_bars--;
   
   
int pos=Bars-counted_bars;
   
     
 
   while(
pos>=0)
     {
         
ExtMapBuffer1[pos]= iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,pos);

         
ExtMapBuffer2[pos]= iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,pos);

         
         
pos--;
     }
     
     
     
     Print(
Crossed (ExtMapBuffer1[0],ExtMapBuffer2[0]));


//----
   
return(0);
  }
//+------------------------------------------------------------------+ 
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote