Need Help to covert Metatrader indicator to AFL

#1
I request seniors and experts to help me to covert the below MT4 indicator to afl code.
This indicator is used to draw lines in range of 50s and 100s in chart
Appreciate the help




//+------------------------------------------------------------------+
//| SweetSpots.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright Shimodax"
#property link "http://www.strategybuilderfx.com"

#property indicator_chart_window


extern int LinesAboveBelow= 10;
extern color LineColorMain= LightGray;
extern color LineColorSub= Gray;

double dPt;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
dPt = Point;
if(Digits==3||Digits==5){
dPt=dPt*10;
}
return(0);
}

int deinit()
{
int obj_total= ObjectsTotal();

for (int i= obj_total; i>=0; i--) {
string name= ObjectName(i);

if (StringSubstr(name,0,11)=="[SweetSpot]")
ObjectDelete(name);
}

return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
static datetime timelastupdate= 0;
static datetime lasttimeframe= 0;


// no need to update these buggers too often
if (CurTime()-timelastupdate < 600 && Period()==lasttimeframe)
return (0);

int i, ssp1, style, ssp;
double ds1;
color linecolor;

ssp1= Bid / dPt;
ssp1= ssp1 - ssp1%50;

for (i= -LinesAboveBelow; i<LinesAboveBelow; i++) {
ssp= ssp1+(i*50);

if (ssp%100==0) {
style= STYLE_SOLID;
linecolor= LineColorMain;
}
else {
style= STYLE_DOT;
linecolor= LineColorSub;
}

ds1= ssp*dPt;
SetLevel(DoubleToStr(ds1,Digits), ds1, linecolor, style, Time[10]);
}

return(0);
}


//+------------------------------------------------------------------+
//| Helper |
//+------------------------------------------------------------------+
void SetLevel(string text, double level, color col1, int linestyle, datetime startofday)
{
int digits= Digits;
string linename= "[SweetSpot] " + text + " Line",
pricelabel;

// create or move the horizontal line
if (ObjectFind(linename) != 0) {
ObjectCreate(linename, OBJ_HLINE, 0, 0, level);
ObjectSet(linename, OBJPROP_STYLE, linestyle);
ObjectSet(linename, OBJPROP_COLOR, col1);
ObjectSet(linename, OBJPROP_WIDTH, 0);
}
else {
ObjectMove(linename, 0, Time[0], level);
}
}
 

colion

Active Member
#2
Based on your description I assume that you want lines drawn at increments of 50. If so, the following can get you going so that you can modify to suit your needs and let you adjust the number of lines and increment with Param().

numLines = Param( "Number of Lines", 10, 2, 20, 1 );
lineIncrement = Param( "Line Increment", 50, 5, 200, 5 );
lineValue[0] = 0;


for ( i = 1; i <= numLines; i++ )
{
lineValue[ i ] = lineValue[ i-1 ] + lineIncrement;

Plot( lineValue[ i ], "", colorWhite, styleThick );
}

Title = "Number of Lines: " + numLines + " Line Increment: " + lineIncrement;
 
#4
Based on your description I assume that you want lines drawn at increments of 50. If so, the following can get you going so that you can modify to suit your needs and let you adjust the number of lines and increment with Param().

numLines = Param( "Number of Lines", 10, 2, 20, 1 );
lineIncrement = Param( "Line Increment", 50, 5, 200, 5 );
lineValue[0] = 0;


for ( i = 1; i <= numLines; i++ )
{
lineValue[ i ] = lineValue[ i-1 ] + lineIncrement;

Plot( lineValue[ i ], "", colorWhite, styleThick );
}

Title = "Number of Lines: " + numLines + " Line Increment: " + lineIncrement;
Dear colion

Thanks for the afl
I tried with the afl but the chart displays all lines right from the begining to end, even i changed it to start from 8150 with 10 lines by modifying
lineValue[0] = 8150;
But still i could not zoom my chart, as all lines are in display
Is there any option to draw lines without affecting the view like the below first chart.

Please see the snap shots.before and after using the afl.
Appreciate your help always.

Raju

Indra day chart- Nifty future 16-01-15

[/url][/IMG]

[/url][/IMG]
 
#5
Dear Colion

At last i got it by modifying

Plot( lineValue[ i ], "", colorBlue, styleNoRescale|styleThick );
Thanks a lot for your wonderful work.

Raju
 

Similar threads

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Name:Phone:
Email:City:
State:
Are you a day trader?