need afl code

vsreeram77

Active Member
#2
#property indicator_chart_window
#property strict
#property version "2.0"


//---- input parameters
bool Alerts = false;
extern color Cam1=Red;
extern color Cam2=Blue;
double GMTshiftSun=0;
double GMTshift=1;
bool Pivot = true;
bool CamTargets = true;
bool ListCamTargets = true;
int PivotFontSize = 8;
int PivotWidth = 1;
int PipDistance = 20;
int CamFontSize = 10;




double P, H3, H4, H5;
double L3, L4, L5;
double LastHigh,LastLow,x;
bool firstL3=true;
bool firstH3=true;

double D1=0.091667;
double D2=0.183333;
double D3=0.2750;
double D4=0.55;


// Fib variables

double yesterday_high=0;
double yesterday_low=0;
double yesterday_close=0;
double p=0;
double r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0,r11=0,r12=0,r13=0,r14=0,r15=0,r16=0;
double s1=0,s2=0,s3=0,s4=0,s5=0,s6=0,s7=0,s8=0,s9=0,s10=0,s11=0,s12=0,s13=0,s14=0,s15=0,s16=0;
double R;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
if (CamTargets)
{
ObjectDelete("H5 line");

ObjectDelete("H4 line");

ObjectDelete("H3 line");

ObjectDelete("L3 line");

ObjectDelete("L4 line");

ObjectDelete("L5 line");
}

return(0);
}

int DoAlerts()
{
double DifAboveL3,PipsLimit;
double DifBelowH3;

DifBelowH3 = H3 - iClose(Symbol(),PERIOD_H1,0);
DifAboveL3 = iClose(Symbol(),PERIOD_H1,0) - L3;
PipsLimit = PipDistance*Point;

if (DifBelowH3 > PipsLimit) firstH3 = true;
if (DifBelowH3 <= PipsLimit && DifBelowH3 > 0)
{
if (firstH3)
{
Alert("Below Cam H3 Line by ",DifBelowH3, " for ", Symbol(),"-",Period());
PlaySound("alert.wav");
firstH3=false;
}
}

if (DifAboveL3 > PipsLimit) firstL3 = true;
if (DifAboveL3 <= PipsLimit && DifAboveL3 > 0)
{
if (firstL3)
{
Alert("Above Cam L3 Line by ",DifAboveL3," for ", Symbol(),"-",Period());
Sleep(2000);
PlaySound("timeout.wav");
firstL3=false;
}
}
return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
double day_high=0;
double day_low=0;
double yesterday_open=0;
double today_open=0;
double Q=0,S=0,M2=0,M3=0,S1=0,R1=0,M1=0,M4=0,S2=0,R2=0,M0=0,M5=0,S3=0,R3=0,nQ=0,nD=0,D=0,R4=0,S4=0;
int cnt=720;
double cur_day=0;
double prev_day=0;
double shift_corrected;


//---- Get new daily prices & calculate pivots
if (DayOfWeek()==1) shift_corrected=GMTshiftSun;
else if ((DayOfWeek()==2) && (Minute() >= 5)) shift_corrected=GMTshift;
else if ((DayOfWeek()==2) && (Hour() > GMTshift)) shift_corrected=GMTshift;
else shift_corrected=GMTshift;

if(cnt>Bars)cnt=Bars-5;
while (cnt!= 0)
{
cur_day = TimeDay(iTime(Symbol(),PERIOD_H1,cnt)- ((int)shift_corrected*3600));

if (prev_day != cur_day)
{
yesterday_close = iClose(Symbol(),PERIOD_H1,cnt+1);
today_open = iOpen(Symbol(),PERIOD_H1,cnt);

yesterday_high = day_high;
yesterday_low = day_low;
day_high = iHigh(Symbol(),PERIOD_H1,cnt);
day_low = iLow(Symbol(),PERIOD_H1,cnt);
prev_day = cur_day;
}

if (iHigh(Symbol(),PERIOD_H1,cnt)>day_high)
{
day_high = iHigh(Symbol(),PERIOD_H1,cnt);
}
if (iLow(Symbol(),PERIOD_H1,cnt)<day_low)
{
day_low = iLow(Symbol(),PERIOD_H1,cnt);
}

cnt--;

}



D = (day_high - day_low);
Q = (yesterday_high - yesterday_low);
//------ Pivot Points ------

P = (yesterday_high + yesterday_low + yesterday_close)/3;//Pivot
//---- To display all 8 Camarilla pivots remove comment symbols below and
// add the appropriate object functions below
if(yesterday_low==0)yesterday_low=1;
H5 = (yesterday_high/yesterday_low)*yesterday_close;
H4 = ((yesterday_high - yesterday_low)* D4) + yesterday_close;
H3 = ((yesterday_high - yesterday_low)* D3) + yesterday_close;
//H2 = ((yesterday_high - yesterday_low) * D2) + yesterday_close;
//H1 = ((yesterday_high - yesterday_low) * D1) + yesterday_close;

//L1 = yesterday_close - ((yesterday_high - yesterday_low)*(D1));
//L2 = yesterday_close - ((yesterday_high - yesterday_low)*(D2));
L3 = yesterday_close - ((yesterday_high - yesterday_low)*(D3));
L4 = yesterday_close - ((yesterday_high - yesterday_low)*(D4));
L5 = yesterday_close - (H5 - yesterday_close);


if (CamTargets)
{

//---- Draw Camarilla lines on Chart
int df=40;
if(Bars<df)df=Bars;
if(ObjectFind("H5 line") != 0)
{
ObjectCreate("H5 line", OBJ_HLINE, 0, iTime(Symbol(),PERIOD_H1,df), H5);
ObjectSet("H5 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H5 line", OBJPROP_COLOR, Cam1);
ObjectSet("H5 line", OBJPROP_WIDTH, 1);
}
else
{
ObjectMove("H5 line", 0, iTime(Symbol(),PERIOD_H1,df), H5);
}

if(ObjectFind("H4 line") != 0)
{
ObjectCreate("H4 line", OBJ_HLINE, 0, iTime(Symbol(),PERIOD_H1,df), H4);
ObjectSet("H4 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H4 line", OBJPROP_COLOR, Cam1);
ObjectSet("H4 line", OBJPROP_WIDTH, 1);
}
else
{
ObjectMove("H4 line", 0, iTime(Symbol(),PERIOD_H1,df), H4);
}

if(ObjectFind("H3 line") != 0)
{
ObjectCreate("H3 line", OBJ_HLINE, 0, iTime(Symbol(),PERIOD_H1,df), H3);
ObjectSet("H3 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("H3 line", OBJPROP_COLOR, Cam1);
ObjectSet("H3 line", OBJPROP_WIDTH, 2);
}
else
{
ObjectMove("H3 line", 0, iTime(Symbol(),PERIOD_H1,df), H3);
}

if(ObjectFind("L3 line") != 0)
{
ObjectCreate("L3 line", OBJ_HLINE, 0, iTime(Symbol(),PERIOD_H1,df), L3);
ObjectSet("L3 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L3 line", OBJPROP_COLOR, Cam2);
ObjectSet("L3 line", OBJPROP_WIDTH, 2);
}
else
{
ObjectMove("L3 line", 0, iTime(Symbol(),PERIOD_H1,df), L3);
}

if(ObjectFind("L4 line") != 0)
{
ObjectCreate("L4 line", OBJ_HLINE, 0, iTime(Symbol(),PERIOD_H1,df), L4);
ObjectSet("L4 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L4 line", OBJPROP_COLOR, Cam2);
ObjectSet("L4 line", OBJPROP_WIDTH, 1);
}
else
{
ObjectMove("L4 line", 0, iTime(Symbol(),PERIOD_H1,df), L4);
}

if(ObjectFind("L5 line") != 0)
{
ObjectCreate("L5 line", OBJ_HLINE, 0, iTime(Symbol(),PERIOD_H1,df), L5);
ObjectSet("L5 line", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("L5 line", OBJPROP_COLOR, Cam2);
ObjectSet("L5 line", OBJPROP_WIDTH, 1);
}
else
{
ObjectMove("L5 line", 0, iTime(Symbol(),PERIOD_H1,df), L5);
}
}

if (Alerts) DoAlerts();

//----
return(0);
}
//+------------------------------------------------------------------+
 

Similar threads