please convert the metatrader program to amibroker

#1
Hi everybody,

I m using both metatrader and amibroker, i am using a program in metatrader its used to plot support and resistance level its very useful to me.

Please convert this program to amibroker this will help to all .

Meta trader program:



#property copyright "Support and Resistance"
#property link ""
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

double v1[];
double v2[];
double val1;
double val2;
int init()
{
IndicatorBuffers(2);

SetIndexArrow(0, 119);
SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,1,Red);
SetIndexBuffer(0, v1);
SetIndexLabel(0,"Resistance");

SetIndexArrow(1, 119);
SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1,Blue);
SetIndexBuffer(1, v2);
SetIndexLabel(1,"Support");
return(0);
}
int start()
{
int i=Bars;
while(i>=0)
{
val1=iFractals(NULL, 0, MODE_UPPER,i);
if (val1 > 0) v1=High;
else v1=v1[i+1];

val2=iFractals(NULL, 0, MODE_LOWER,i);
if (val2 > 0) v2=Low;
else v2=v2[i+1];

i--;
}
return(0);
}



I tried most of my friends to convert this program and i posted this in many forums. I request any of one to convert this program.


Thanks and regards,


Robert Antony
 
#4
I have a similar one, albeit the swing lines.
here's the code!

_SECTION_BEGIN("SUPPORT & RESISTANCE LEVELS");
//SUPPORT & RESISTANCE LEVELS
//Graham Kavanagh 9 Oct 2003 #49421

//Find turning points

top = H==HHV(H,3) AND H>=Ref(H,1) AND H>=Ref(H,2);
bot = L==LLV(L,3) AND L<=Ref(L,1) AND L<=Ref(L,2);

topH = ValueWhen(top,H);
botL = ValueWhen(bot,L);

//Indicator section
GraphXSpace=5;

col = IIf( Close > Ref( Close, -1 ), colorGreen, colorRed );
Plot( Close, "Price", colorWhite, styleCandle );

Plot( topH, "res", colorRed, styleDots+styleNoLine );
Plot( botL, "sup", colorBrightGreen, styleDots+styleNoLine );

Title = Name() + ", " + Date() + ", Support & Resistance Levels
Support = "
+ topH + ", Resistance = " + botL ;
_SECTION_END();

_SECTION_BEGIN("Colour Tap");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}
SetChartBkColor(ParamColor("Outer panel color ",colorDarkGrey)); // color of outer border
SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),
ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));

_SECTION_END();
 
#5
Another useful AFL for plotting peaks & troughs:


/*PLOTDYNHI*/

/*DYNAMICALLY PLOTS HIGHEST VALUE FOR THE PERIOD*/


//Suitable for overlaying price(C)charts
//DoubleClick left mouse button on any bar in the chart to select the
period
//DoubleClick left mouse button on space to the right of the chart to
deselect the period
//If no period is selected the default is all bars



P = (LastValue(BarIndex()) - BeginValue(BarIndex())) + 1;//Periods
PH = HHV(C,P);//PeriodHigh
SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
(PH));//SelectedDate

Plot(SD, "PeriodHi",34,8);

******************************************************************
/*P_DYNHIPEAK*/

/*DYNAMICALLY PLOTS HIGHEST 3 Bar PEAK VALUE FOR THE PERIOD*/


/*Suitable for overlaying price(C)charts*/
/*DoubleClick left mouse button on any bar in the chart to select the
period*/
/*DoubleClick left mouse button on space to the right of the chart to
deselect the period*/
/*If no bar is selected the defaults is all bars*/
/*Caution: it will not see peaks with flat tops (two or more equal
closes)*/
/*Caution:if there is no peak within the selected period the most
recent peak will be indicated*/

PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
PKV = IIf(PK == 1, ValueWhen(PK,C,1), ValueWhen(PK,C,0));//PeakValue
P = (LastValue(BarIndex()) - BeginValue(BarIndex())) + 1;//Periods
HPK = HHV(PKV,P);//HighestPeakValue
SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
(HPK));//SelectedDate

Plot(SD, "PeriodHiPeak",34,8);




********************************************************************
//PLOTMAJORPEAKS

//PLOTS ALL MAJOR PEAK RESISTANCE LINES

//Suitable for overlaying charts
//A MajorPeak is defined as the Highest Peak of any three Peaks


PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
PKV0 = ValueWhen(PK,C,0);//PeakValue0
PKV1 = ValueWhen(PK,C,1);//PeakValue1
PKV2 = ValueWhen(PK,C,2);//PeakValue2
MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1,
PKV1,1); //MajorPeakValue


Plot(MPKV, "LastPeak",34,1);

**********************************************************************

/*P_DYNHIPEAK*/

/*DYNAMICALLY PLOTS HIGHEST 3 Bar PEAK VALUE FOR THE PERIOD*/


/*Suitable for overlaying price(C)charts*/
/*DoubleClick left mouse button on any bar in the chart to select the
period*/
/*DoubleClick left mouse button on space to the right of the chart to
deselect the period*/
/*If no bar is selected the defaults is all bars*/
/*Caution: it will not see peaks with flat tops (two or more equal
closes)*/
/*Caution:if there is no peak within the selected period the most
recent peak will be indicated*/

PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
PKV = IIf(PK == 1, ValueWhen(PK,C,1), ValueWhen(PK,C,0));//PeakValue
P = (LastValue(BarIndex()) - BeginValue(BarIndex())) + 1;//Periods
HPK = HHV(PKV,P);//HighestPeakValue
SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
(HPK));//SelectedDate

Plot(SD, "PeriodHiPeak",34,8);

**********************************************************

//P_3BarPeaks

//Suitable for overlaying charts
//References future bars

//PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
//PKV = ValueWhen(PK,C,1);//PeakValue
//Plot(PKV, "LastPeak",34,1);

/********************************************************************/

/* draw horizontal lines at hi & lo pivot points*/
//JohnRUK TraderJUK
//Shifts resistance line 1 bar
//3 Bar peaks

//P = ParamField("Price field",-1);
//Hipiv = IIf(P<Ref(P,-1) AND (Ref(P,-1)>Ref(P,-2)),1,0);
//Lopiv = IIf(P>Ref(P,-1) AND (Ref(P,-1)<Ref(P,-2)),1,0);
//hiline=ValueWhen(hipiv==1,Ref(P,-1),1);
//loline=ValueWhen(lopiv==1,Ref(P,-1),1);
//Plot (Hiline,"hiline",colorRed);
//Plot (Loline,"loline",colorBlue);

/*********************************************************************/

/*P_Peaks*/

/*PLOTALLPEAKS*/

/*PLOTS ALL PEAK VALUES FOR THE PERIOD*/


//Suitable for overlaying price(C)charts
//References future bars
//Recognises flat peaks of any length


PKR = ROC(C,1) >= 0 AND Ref(ROC(C,1),1) < 0 ;//PeakRight
PKRV = ValueWhen(PKR == 1, C,1);//PeakRightValue
PKL = ROC(C,1) > 0 AND Ref(ROC(C,1),1) <= 0 ;//PeakLeft
BSPKL = BarsSince(PKL == 1);//BarsSincePeakLeft
PKP = ValueWhen(PKR == 1, BSPKL,1);//PeakPeriods
PKPH = HHV(C,PKP + 1); //PeakPeriodHigh
PKV = ValueWhen(PKRV == PKPH AND PKR == 1, PKRV,1);//PeakValue

Plot(PKV, "PeakHi",34,8);

*****************************************************************

/*P_HHV*/

P = Param("periods",7,0,50,1);
H = HHV(C,P);
Plot(H,"HHV",34,1);

*******************************************************************

//PLOTLASTPEAK

//Suitable for overlaying charts
//Once overlayed on one chart use the keyboard arrows to scroll up or
down through symbol lists
//SelectedDate ignores dates (bars) before the peak
//Add additional resistance lines if a deeper history is required
//Code variations can identify major peaks or change the timeframe
upwards

//PLOTS THE MOST RECENT PEAK RESISTANCE LINE

PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
PKV = ValueWhen(PK,C,1);//PeakValue
PKD = ValueWhen(PK,DateNum(),1);//PeakDate
SD = IIf(DateNum() < LastValue(PKD,lastmode = True ), Null, LastValue
(PKV,Lastmode = True));//SelectedDate

Plot(SD, "LastPeak",34,8);

//PLOT 2ND LAST PEAK RESISTANCE LINE

PKV2 = ValueWhen(PK,C,2);//PeakValue2
PKD2 = ValueWhen(PK,DateNum(),2);//PeakDate2
SD2 = IIf(DateNum() < LastValue(PKD2,lastmode = True ), Null, LastValue
(PKV2,Lastmode = True));//SelectedDate

Plot(SD2, "LastPeak2",34,8);

****************************************************************

//PLOTCurrentMAJORPEAKS

//Suitable for overlaying charts
//A MajorPeak is defined as the Highest Peak central to any three Peaks

//PLOT THE LAST MAJOR PEAK RESISTANCE LINE


PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
PKV0 = ValueWhen(PK,C,0);//PeakValue0
PKV1 = ValueWhen(PK,C,1);//PeakValue1
PKV2 = ValueWhen(PK,C,2);//PeakValue2
MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1,
PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum
(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue
(MPKV,Lastmode = True));//SelectedDate

Plot(SD, "LastMajorPeak",34,8);



//PLOT THE SECOND LAST MAJOR PEAK RESISTANCE LINE


//PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
//PKV0 = ValueWhen(PK,C,0);//PeakValue0
//PKV1 = ValueWhen(PK,C,1);//PeakValue1
//PKV2 = ValueWhen(PK,C,2);//PeakValue2
//MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1,
PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum
(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue
(MPKV2,Lastmode = True));//SelectedDate

Plot(SD2, "LastMajorPeak",34,8);

******************************************************************

//PLOT ALL PEAKS

//Suitable for overlaying charts
//References future bars

//PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
//PKV = ValueWhen(PK,C,1);//PeakValue
//Plot(PKV, "LastPeak",34,1);

/********************************************************************/

/* draw horizontal lines at hi & lo pivot points*/
//JohnRUK TraderJUK
//Shifts resistance line 1 bar

//P = ParamField("Price field",-1);
//Hipiv = IIf(P<Ref(P,-1) AND (Ref(P,-1)>Ref(P,-2)),1,0);
//Lopiv = IIf(P>Ref(P,-1) AND (Ref(P,-1)<Ref(P,-2)),1,0);
//hiline=ValueWhen(hipiv==1,Ref(P,-1),1);
//loline=ValueWhen(lopiv==1,Ref(P,-1),1);
//Plot (Hiline,"hiline",colorRed);
//Plot (Loline,"loline",colorBlue);

/*********************************************************************/

/*P_TROUGHS*/

/*PLOTS ALL TROUGH VALUES FOR THE PERIOD*/


//Suitable for overlaying price(C)charts
//References future bars
//Recognises flat troughs of any length


TR = ROC(C,1) <= 0 AND Ref(ROC(C,1),1) > 0 ;//TroughRight
TRV = ValueWhen(TR == 1, C,1);//TroughRightValue
TL = ROC(C,1) < 0 AND Ref(ROC(C,1),1) >= 0 ;//TroughLeft
BSTL = BarsSince(TL == 1);//BarsSinceTroughLeft
TP = ValueWhen(TR == 1, BSTL,1);//PeakPeriods
TPL = LLV(C,TP + 1); //TroughPeriodLow
TV = ValueWhen(TRV == TPL AND TR == 1, TRV,1);//TroughValue

Plot(TV, "TroughLo",32,8);


*****************************************************************

/*PLOTSALLMAJORTROUGHS*/

/*PLOTS ALL MAJOR TROUGH VALUES FOR THE PERIOD*/


//Suitable for overlaying price(C)charts
//References future bars
//Recognises flat troughs of any length
//A Major Trough comprises any two Troughs where a Trough is followed
by a higher Trough


TR = ROC(C,1) <= 0 AND Ref(ROC(C,1),1) > 0 ;//TroughRight
TRV = ValueWhen(TR == 1, C,1);//TroughRightValue
TL = ROC(C,1) < 0 AND Ref(ROC(C,1),1) >= 0 ;//TroughLeft
BSTL = BarsSince(TL == 1);//BarsSinceTroughLeft
TP = ValueWhen(TR == 1, BSTL,1);//TroughPeriods
TPL = LLV(C,TP + 1); //TroughPeriodLow
//TV = ValueWhen(TRV == TPL AND TR == 1, TRV,1);//TroughValue
//MTV = ValueWhen(TV < Ref(TV,1),TV,1);

TV0 = ValueWhen(TRV == TPL AND TR == 1, TRV,0);//TroughValue0
TV1 = ValueWhen(TRV == TPL AND TR == 1, TRV,1);//TroughValue1
TV2 = ValueWhen(TRV == TPL AND TR == 1, TRV,2);//TroughValue2
TV3 = ValueWhen(TRV == TPL AND TR == 1, TRV,3);//TroughValue3

MT = TV2 > TV1 AND TV1 < TV0 OR TV3 > TV2 AND TV2 == TV1 AND TV1 <
TV0; ; //MajorTrough
MTV = ValueWhen(Ref(MT,-1) == 0 AND MT == 1,
TV1,1); //MajorTroughValue

Plot(MTV, "MajorTroughLo",32,8);
 
#7
Hello,

I found this code on another website and it looks very close to the screenshot you provided. Hope it helps.

_SECTION_BEGIN("Swing_Chart_2");
/* SWING CHART */
GraphXSpace = 3;

SetBarsRequired( 200, 200 ); // needed for script
swingsize = 10;
HP = HHVBars( High, swingsize ) == 0;
LP = LLVBars( Low, swingsize ) == 0;

EnableScript("jscript");
<%
result = VBArray(AFL("High")).toArray();
function TrendLine( starti, startv, endi, endv )
{
for( j = starti; j <= endi; j++ )
{
result[ j ] = startv + ( j - starti )*(endv-startv)/(endi-starti);
}
}
High = VBArray(AFL("High")).toArray();
Low = VBArray(AFL("Low")).toArray();
HP = VBArray(AFL("HP")).toArray();
LP = VBArray(AFL("LP")).toArray();
endi = -1;
starti = -1;
dir = 0;
for( i = High.length - 0; i >= 0; i-- )
{
if( dir == 1 && LP[ i ] )
{
TrendLine( i, Low[ i ], endi, endv );
endi = i;
endv = Low[ i ];
dir = -1;
}
else
if( dir == -1 && HP[ i ] )
{
TrendLine( i, High[ i ], endi, endv );
endi = i;
endv = High[ i ];
dir = 1;
}
else
if( dir == 0 && endi == -1 && LP[ i ] )
{
endi = i;
endv = Low[ i ];
dir = -1;
}
else
if( dir == 0 && endi == -1 && HP[ i ] )
{
endi = i;
endv = High[ i ];
dir = 1;
}
}
AFL("Graph0")=result;
%>
Graph0Color=colorGold;
Graph1=Close;
Graph1Color = colorWhite;
Graph1Style=styleCandle;

pv=Graph0;
pv2 = Ref(Graph0, -1);

WriteVal(pv);
WriteVal(pv2);
Buy = Cross(pv, pv2);
PlotShapes (IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
Sell = Cross(pv2,pv);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

GraphXSpace = 5;

dist = 1.3*ATR(20);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, colorBrightGreen );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorRed);
}



_SECTION_END();
 
#9
Hello, Bimbo:

I hope I am not breaking any rules by posting...but it is an Amibroker forum website.... www.amibrokerfan.com.

I am glad you are able to use it. I cannot take the credit for creating it because I am no expert...I am just learning to understand afl code, but if you go that website and search for Swing trade afl you will probably find it there.

You also have to make 3 posts before you can see any of the afl's or attachments.

Good Trading!
brevco
 
#10
Brevco,
You flatten me by your humility.

You are like a Candle which lights another Candle.

Regards

Bimbo:)

A CANDLE LOSES NOTHING BY LIGHTING ANOTHER CANDLE
 

Similar threads