Thread: Alerts
View Single Post
  #17 (permalink)  
Old 11-21-2005, 12:46 AM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 986
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow Answers

Quote:
Originally Posted by hellkas
hi codersguru...

I'd like to know how I can put 3 things:

1) Arrows in the chart;
2) Alert when cross;
3) Comment in the left corner;

the indicator its Stoch..

many tkx
hi hellkas,

1- Arrows in the chart;

Use this code to draw an arrow (color=Gold, Width=1) in the main window.

PHP Code:
ObjectCreate("my arrow"OBJ_ARROW0Time[0], High[0]+Point*10);
ObjectSet("my arrow"OBJPROP_ARROWCODE1);
ObjectSet("my arrow"OBJPROP_COLOR Gold);
ObjectSet("my arrow"OBJPROP_WIDTH  1);
ObjectsRedraw(); 

2) Alert when cross;


This is my Alerts demo (working when 8EMA crosses 13EMA and telles you the direction):

PHP Code:
//+------------------------------------------------------------------+
//|                                                CrossedAlerts.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 ,stringdirection)
{

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;
      
direction=current_dirction
      return (
true);
}
else
{
      
direction=current_dirction;
      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,8,0,MODE_EMA,PRICE_CLOSE,pos);
         
ExtMapBuffer2[pos] = iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,0);
         
pos--;
     }
     
     
string direction;   
     Print(
Crossed (ExtMapBuffer1[0],ExtMapBuffer2[0],direction));
      
 
//----
   
return(0);
  }
//+------------------------------------------------------------------+ 
3) Comment in the left corner;

This line of code will print a comment on the top left corner of the main window:

PHP Code:
Comment("Hi! I'm here on the main chart windows!"); 
I hope I helped!
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote