I'm trying to figure out a bit of code to determine whether or not the ssl channels are crossed and the red is over the green or vise versa
Here is the code for the ssl channels:
Code:
//+------------------------------------------------------------------+
//| SSL channel chart.mq4 |
//| mladen |
//| |
//| initial SSL for metatrader developed by Kalenzo |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_width1 2
#property indicator_width2 2
//----
extern int Lb =10;
extern bool alertsOn =false;
extern bool alertsMessage=true;
extern bool alertsSound =false;
extern bool alertsEmail =false;
//----
double ssld[];
double sslu[];
double Hlv[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0,ssld); SetIndexDrawBegin(0,Lb+1);
SetIndexBuffer(1,sslu); SetIndexDrawBegin(0,Lb+1);
SetIndexBuffer(2,Hlv);
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
//----
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(i=limit;i>=0;i--)
{
Hlv[i]=Hlv[i+1];
if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1)) Hlv[i]= 1;
if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1)) Hlv[i]=-1;
if(Hlv[i]==-1)
{
ssld[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
sslu[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW ,i+1);
}
else
{
ssld[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW ,i+1);
sslu[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
}
}
//----
if (alertsOn)
if (Hlv[0]!=Hlv[1])
if (Hlv[0]==1)
doAlert("up");
else doAlert("down");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void doAlert(string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
//----
if (previousAlert!=doWhat || previousTime!=Time[0])
{
previousAlert =doWhat;
previousTime =Time[0];
//----
message= StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," SSL trend changed to ",doWhat);
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"SSL "),message);
if (alertsSound) PlaySound("alert2.wav");
}
}
//+------------------------------------------------------------------+
Can I use something like the following code for sslu and ssld?
Code:
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
//Don't work in the first load, wait for the first cross!
static bool first_time = true;
if(first_time == true)
{
first_time = false;
return (0);
}
//----
if(line1 > line2)
current_direction = 1; //up
if(line1 < line2)
current_direction = 2; //down
//----
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return(last_direction);
}
else
{
return (0); //not changed
}
}
Obviously, i'm looking for a way to generate an OP_BUY or OP_SELL condition given that an ADX arrow is indicated and the corresponding ssl cross happens before the 3rd bar from the ADX arrow is printed or a ssl cross occurs and the corresponding ADX arrow is indicated before the 3rd bar from the ssl cross occurs.
Here is the code for the ADXcrosses:
Code:
//+------------------------------------------------------------------+
//| ADXcrosses.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int ADXcrossesPeriod = 14;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//----
double b4plusdi, b4minusdi, nowplusdi, nowminusdi;
int nShift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexArrow(0, 233);
SetIndexBuffer(0, ExtMapBuffer1);
//----
SetIndexStyle(1, DRAW_ARROW, 0, 1);
SetIndexArrow(1, 234);
SetIndexBuffer(1, ExtMapBuffer2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ADXcrosses(" + ADXcrossesPeriod + ")");
SetIndexLabel(0, "ADXcrUp");
SetIndexLabel(1, "ADXcrDn");
//----
switch(Period())
{
case 1: nShift = 1; break;
case 5: nShift = 3; break;
case 15: nShift = 5; break;
case 30: nShift = 10; break;
case 60: nShift = 15; break;
case 240: nShift = 20; break;
case 1440: nShift = 80; break;
case 10080: nShift = 100; break;
case 43200: nShift = 200; break;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
//----
for(int i = 0; i < limit; i++)
{
b4plusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i - 1);
nowplusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i);
b4minusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i - 1);
nowminusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i);
//----
if(b4plusdi > b4minusdi && nowplusdi < nowminusdi)
ExtMapBuffer1[i] = Low[i] - nShift*Point;
//----
if(b4plusdi < b4minusdi && nowplusdi > nowminusdi)
ExtMapBuffer2[i] = High[i] + nShift*Point;
}
//----
return(0);
}
//+------------------------------------------------------------------+
In order to use these indicators in an EA I would have to embed them as a function since i can't call the necessary variables through iCustom, correct?
Thanks for bearing with me and humoring my limited knowledge of MQL4.
-DREWP