int trade()
{
double trend4 = iCustom(NULL,0,"SuperTrend",5,1.5,1,3); //achat -> vente
double trend1 = iCustom(NULL,0,"SuperTrend",5,1.5,0,2); //achat -> vente
double trend3 = iCustom(NULL,0,"SuperTrend",5,1.5,1,2); //vente -> achat
double trend2 = iCustom(NULL,0,"SuperTrend",5,1.5,0,3); //vente -> achat
int total = OrdersTotal();
double ordre1;
double ordre2;
if(trend2 < 5 && trend3 < 5 && total == 0)//vente
{
ordre1 = OrderSend(Symbol(),OP_SELL,0.08,Bid,3,Bid+(5000*Point),Bid-(5000*Point),"EA de Greg3395",1,0,Red);
}
if(trend2 > 5 && trend3 > 5 && total == 1) //achat
{
if(OrderSelect(ordre1, SELECT_BY_TICKET))
{
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(), 0.08, Bid, 3, CLR_NONE);
}
}
}
if(trend1 < 5 && trend4 < 5 && total == 0) //achat
{
ordre2 = OrderSend(Symbol(),OP_BUY,0.08,Ask,3,Ask-(5000*Point),Ask+(5000*Point),"EA de Greg3395",2,0,Blue);
}
if(trend1 > 5 && trend4 > 5 && total == 1) //achat
{
if(OrderSelect(ordre2, SELECT_BY_TICKET))
{
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(), 0.08, Ask, 3, CLR_NONE);
}
}
}
return(0);
}
Programming - editing - modification EA, Script or Indicator for MT4 OR MT5 ---- Trading on the Forex market involves substantial risks, including complete possible loss of funds and other losses and is not suitable for all members. Client should make an independent judgments as to whether trading is appropriate for him/her in light of his/her financial condition, investment experience, risk tolerance and other factors.
Wednesday, 26 December 2012
supertrend value
i made something approaching what i want but i cant understand the behaviour of this EA : its following supertrend switches sometimes, but it also reacts when the market reaches supertrend value...
here are the interresting lines of this code :
//green supertrend and previous value
double super0 = iCustom(NULL,0,"SuperTrend",0,1);
double prevsuper0 = iCustom(NULL,0,"SuperTrend",0,2);
double prevsuper0 = iCustom(NULL,0,"SuperTrend",0,2);
//red supertrend and previous value
double super1 = iCustom(NULL,0,"SuperTrend",1,1);
double prevsuper1 = iCustom(NULL,0,"SuperTrend",1,2);
double prevsuper1 = iCustom(NULL,0,"SuperTrend",1,2);
// turns to red
if ((super1!=2147483647) && (prevsuper1==2147483647)) Order=SIGNAL_CLOSEBUY;
if ((super1!=2147483647) && (prevsuper1==2147483647)) Order=SIGNAL_SELL;
//turns to green
if ((super0!=2147483647) && (prevsuper0==2147483647)) Order=SIGNAL_CLOSESELL;
if ((super0!=2147483647) && (prevsuper0==2147483647)) Order=SIGNAL_BUY;
i also wonder why this weird value of 2147483647 when the line isnt of the same color as the buffer, instead of a clean EMPTY_VALUE...
thanks again!!!
iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,0,1); //uptrend value
Code:
iCustom(NULL,0,"SuperTrend",10,3,0,1) //buffer 0 ie uptrend iCustom(NULL,0,"SuperTrend",10,3,1,1) //buffer 1 ie downtrend
Code:
int start() { //---- ExtMapBuffer1[1] = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,0,1); //uptrend value ExtMapBuffer1[2] = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,1,1); //downtrend value if(Bid <= ExtMapBuffer1[1]) { TrendDirection = "Up!"; } if(Bid >= ExtMapBuffer1[2]) { TrendDirection = "Down!"; } Comment("UpTrend: ", ExtMapBuffer1[1], "n", "DownTrend: ", ExtMapBuffer2[2], "n", "Trade Direction: ", TrendDirection); //---- return(0); }
We are our own best indicator.
I have put the following for a call to the indicator, would this be correct to get the current price? It only works on the output of the bar I am asking (which is fine) I believe and does this seem right?
Code:
//+------------------------------------------------------------------+ //| SuperTrend V1.mq4 | //| Copyright © 2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ double ExtMapBuffer1[]; double ExtMapBuffer2[]; int Periods = 3; double Multiplier = 1.25; int TimeFrame = 240; string TrendDirection = "Long"; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- ExtMapBuffer1[1] = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,0,1); //downtrend value ExtMapBuffer1[2] = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,1,1); //uptrend value if(ExtMapBuffer1[1] < ExtMapBuffer1[2]) { TrendDirection = "Down"; } Comment("UpTrend: ", ExtMapBuffer1[1], "n", "DownTrend: ", ExtMapBuffer2[2], "n", "Trade Direction: ", TrendDirection); //---- return(0); }
I think I got it!
I changed to the following and it is outputting fine!
I changed to the following and it is outputting fine!
Code:
//+------------------------------------------------------------------+ //| SuperTrend V1.mq4 | //| Copyright © 2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ double ExtMapBuffer1[]; double ExtMapBuffer2[]; int Periods = 3; double Multiplier = 1.25; int TimeFrame = 240; string TrendDirection = "Long"; double UpTrend,DownTrend; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- //ExtMapBuffer1[1] = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,0,1); //uptrend value //ExtMapBuffer1[2] = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,1,1); //downtrend value UpTrend = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,0,1); DownTrend = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,1,1); /*if(Bid <= ExtMapBuffer1[1]) { TrendDirection = "Up!"; } if(Bid >= ExtMapBuffer1[2]) { TrendDirection = "Down!"; } //Comment("UpTrend: ", ExtMapBuffer1[1], "n", "DownTrend: ", ExtMapBuffer2[2], "n", "Trade Direction: ", TrendDirection); */ Comment("UpTrend: ", UpTrend, "n", "DownTrend: ", DownTrend); //---- return(0); }
We are our own best indicator.
"built in" indicators
iCustom() is used for indicator that are not "built in" indicators
If the indicator is a "built in" then you do not need iCustom(). Here is a list of "built in" indicators :
So, if you are not going to use one of the above, you are going to have to use iCustom() for what you described
If the indicator is a "built in" then you do not need iCustom(). Here is a list of "built in" indicators :
- iAC
- iAD
- iAlligator
- iADX
- iATR
- iAO
- iBearsPower
- iBands
- iBandsOnArray
- iBullsPower
- iCCI
- iCCIOnArray
- iCustom
- iDeMarker
- iEnvelopes
- iEnvelopesOnArray
- iForce
- iFractals
- iGator
- iIchimoku
- iBWMFI
- iMomentum
- iMomentumOnArray
- iMFI
- iMA
- iMAOnArray
- iOsMA
- iMACD
- iOBV
- iSAR
- iRSI
- iRSIOnArray
- iRVI
- iStdDev
- iStdDevOnArray
- iStochastic
- iWPR
So, if you are not going to use one of the above, you are going to have to use iCustom() for what you described
i have created my EA - ASCTrend.mq4
i have created my EA - ASCTrend.mq4 with MQ4 builder, which uses asctrend signal with ICustom function. it can open a BUY trade when UP signal, and SELL when DOWN.
i want to add to my EA some filter - with backtesting in some pairs, its look good fo filter with BBands ind, bud i dont know how to add this filter in my EA - something like that I think, but have no luck.
double Buy1_1 = iCustom(Symbol(),0,"PerkyAsctrend1",0,1);
double Buy2_1 = iCustom(NULL, 0, "BBands_Stop_v1", 4, 0, Current + 1);
double Buy2_2 = 1;
double Sell1_1 = iCustom(Symbol(),0,"PerkyAsctrend1",1,1);
double Sell2_1 = iCustom(NULL, 0, "BBands_Stop_v1", 5, 0, Current + 1);
double Sell2_2 = 1;
if (Buy1_1 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
if (Sell1_1 && Sell2_1 > Sell2_2) Order = SIGNAL_SELL;
iCustom Question
I have an indicator which compares several values. I wish to bring those values into my EA. So far, what I've found, of the use of iCustom function is; calling the name of the indicator and comparing two different time periods of the same MA. How would I use iCustom to compare two different values of the same indicator.
For example:
Let's say that I have an MA of the average of the High and Low for a 15 min Period, and a MA of Close Price over 13 Periods, in the same Indicator. Let's say that I want to place a Buy, in my EA, when the MA of the Close Price crosses under the MA of the average of High/ Low, in the Indicator.
How would I utilize the iCustom Function to capture a state which occurs between two different MAs in the same Indicator?
You just read the different indicators in your EA using icustom and do a compare
val1 = iCustom(NULL, 0,"sar_filter_alert",5,9,3,3,1,1,0.02,0.2,0,0);
val2 = iCustom(NULL, 0,"AsciiTrade",10,20,5,0,0);
Then if(val1 > val2 etc
or if you want to compare 2 values in the same indicator, change the values in the second read
val1 = iCustom(NULL, 0,"sar_filter_alert",5,9,3,3,1,1,0,0);
val2 = iCustom(NULL, 0,"sar_filter_alert",25,19,3,3,1,3,1,0);
Supertrend of a specific bar using iCustom
Hi homi,
Let�s assume we want to return the value of the indicator �Supertrend� of a specific bar using iCustom.
If we want to get the returned value of the Supertrend first line:
We can write this price of code inside start() function:
Here val will hold the returned value of Supertrend indicator(first line).
If you want the returned value of the second line, we can write:
This is a program which will use Supertrend indicator using iCustom:
==================================================
Use something like this in your EA:
Buff0=iCustom(NULL,0,"Indicator Name",0,0); //Top color of indicator
Buff0=iCustom(NULL,0,"Indicator Name",0,1); //1-Back
Buff1=iCustom(NULL,0,"Indicator Name",1,0); //Next to top color of indicator
Buff1=iCustom(NULL,0,"Indicator Name",1,1); //1-Back
Modify the variables in the indicator itself, and recompile the indicator which will update the buffers and the indicator on the graph!
===================================================
Let�s assume we want to return the value of the indicator �Supertrend� of a specific bar using iCustom.
If we want to get the returned value of the Supertrend first line:
We can write this price of code inside start() function:
Code:
double val=iCustom(NULL, 0, "SuperTrend",0,0,pos);
If you want the returned value of the second line, we can write:
Code:
double val=iCustom(NULL, 0, "SuperTrend",0,1,pos);
Code:
#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); } 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>0) counted_bars--; int pos=Bars-counted_bars; while(pos>=0) { ExtMapBuffer1[pos] = iCustom(NULL, 0, "SuperTrend",0,0,pos); ExtMapBuffer2[pos] = iCustom(NULL, 0, "SuperTrend",0,1,pos); pos--; } //---- return(0); } //+------------------------------------------------------------------+
==================================================
Use something like this in your EA:
Buff0=iCustom(NULL,0,"Indicator Name",0,0); //Top color of indicator
Buff0=iCustom(NULL,0,"Indicator Name",0,1); //1-Back
Buff1=iCustom(NULL,0,"Indicator Name",1,0); //Next to top color of indicator
Buff1=iCustom(NULL,0,"Indicator Name",1,1); //1-Back
Modify the variables in the indicator itself, and recompile the indicator which will update the buffers and the indicator on the graph!
===================================================
iCustom(NULL,0,"SuperTrend",10,3,0,1) //buffer 0 ie uptrend iCustom(NULL,0,"SuperTrend",10,3,1,1) //buffer 1 ie downtrend
I-Customer Section for Expert Advisors
hello traders and programmers
i hope i�m right here to open this new thread , the idea is to post ONLY expert advisor code of ALL INDICATORS what you know for programming and test your own expert advisor .
SORRY FOR MY BAD ENGLISH.......
the form looks like a "FUNCTION" - my first examples :
Indikator: TURBO JRSX:FUNCTION CALLING:Int CheckTurboJRSX()
{
double rsxcurr = 0,rsxprev1 = 0,rsxprev2 = 0;
rsxcurr = iCustom(Symbol(), Period(), "Turbo_JRSX", 17, 0, 1);
rsxprev1 = iCustom(Symbol(), Period(), "Turbo_JRSX", 17, 0, 2);
rsxprev2 = iCustom(Symbol(), Period(), "Turbo_JRSX", 17, 0, 3);
if (rsxcurr > rsxprev1 && rsxcurr > 30 && rsxprev1 < 30) return ( 1) ; //BUY
if (rsxcurr < rsxprev1 && rsxcurr < 70 && rsxprev1 > 70) return ( -1) ; //SELL
return(0);
}-----------------------------------------------------------------------if(CheckTurboJRSX()== 1) {example: open order buy ....}
if(CheckTurboJRSX()==-1) {example: open order sell ....}
Indikator: Parabolic Sar:FUNCTION CALLING:int CheckParabolicSar()
{
double sarCurrent = iSAR(NULL, 0, 0.02, 0.2, 0);
double sarPrevious = iSAR(NULL, 0, 0.02, 0.2, 1);
if(sarCurrent <= Ask && sarPrevious>sarCurrent) return ( 1) ; //BUY
if(sarCurrent >= Bid && sarPrevious<sarCurrent) return ( -1) ; //SELL
return(0);
}note: parabolic sar is standard indicator , it`s not needed to attach for downloading....if(CheckParabolicSar()== 1 {example: open order buy ....}
if(CheckParabolicSar()==-1 {example: open order sell ....}
-----------------------------------------------------------------------
Indikator: Fisher:
EXTERN VARIABLES:extern int FisherPeriod = 5;
extern double UP_Value = 0.25;
extern double DN_Value =-0.25;FUNCTION CALLING:int FisherCheck()
{
double FisherUP = iCustom(NULL,0,"Fisher_Yur4ik",FisherPeriod,1,0);
double FisherDN = iCustom(NULL,0,"Fisher_Yur4ik",FisherPeriod,2,0);
if(FisherUP>UP_Value) return ( 1) ; //BUY
if(FisherDN<DN_Value) return (-1); //SELL
return (0);
}-----------------------------------------------------------------------if(FisherCheck()== 1 {example: open order buy ....}
if(FisherCheck()==-1 {example: open order sell ....}
Indikator: iBullsPower/iBearsPower:
EXTERN VARIABLES:extern int BullBearPeriod=5;FUNCTION CALLING:int CheckiBullsBearsPower()
{
double bull = iBullsPower(NULL,0,BullBearPeriod,PRICE_CLOSE,1);
double bear = iBearsPower(NULL,0,BullBearPeriod,PRICE_CLOSE,1);
if(bull +bear>0) return ( 1) ; //BUY
if(bull+bear<0) return ( -1) ; //SELL
return(0);
}note: iBullsPower and iBearsPower are standard indicators , it`s not needed to attach for downloading....if(CheckiBullsBearsPower()== 1 {example: open order buy ....}
if(CheckiBullsBearsPower()==-1 {example: open order sell ....}
-----------------------------------------------------------------------
Indikator: Support and Resistance:FUNCTION CALLING:int CheckSupportResident()
{
double iTmpR = iCustom(Symbol(),0,"Support and Resistance",0,0);
double iTmpS = iCustom(Symbol(),0,"Support and Resistance",1,0);
if (Close[0]==iTmpR) return ( 1) ; //BUY
if (Close[0]==iTmpS) return ( -1) ; //SELL
return(0);
}-----------------------------------------------------------------------if(CheckSupportResident()== 1 {example: open order buy ....}
if(CheckSupportResident()==-1 {example: open order sell ....}
Indikator: TrendEnvelopes_v2:
EXTERN VARIABLES:extern int SignalCandle =1;
extern int MA_Period =34;FUNCTION CALLING:Int CheckTrendEnvelopes_V2()
{
double TrendEnv_long = iCustom(Symbol(),Period(),"TrendEnvelopes_v2",MA_P eriod,0,SignalCandle); //buy
double TrendEnv_short = iCustom(Symbol(),Period(),"TrendEnvelopes_v2",MA_P eriod,1,SignalCandle); //sell
(TrendEnv_long <9999) return ( 1) ; //BUY
(TrendEnv_short <9999) return ( -1) ; //SELL
return(0);
}-----------------------------------------------------------------------if(CheckTrendEnvelopes_V2()== 1 {example: open order buy ....}
if(CheckTrendEnvelopes_V2()==-1 {example: open order sell ....}
hope this samples help to inspirit this thread..... will add more indicators next time .......
have fun and greetings from austria
forex2006
Coding Zigzag
zigzag differs from most indicators in that for the large precentage of time it's value is 0, with only an occassional non-zero number..... that renders it almost unusable in the standard iCustom form.....
// ---> zig = iCustom(NULL,0,"ZigZag",15,5,3, 0, i);
to be useful you almost certainly will have to create an array to store all the "non-zero" numbers..... such as;
if(zig>0)
{
zag[n] = zig;
}
then you can do the common
if(zag[1] > zag[2]) // do this
else // or
if(zag[1] < zag[2]) // do that
//------------
EA write using this Advanced ADX indicator
I am want to write a EA write using this Advanced ADX indicator...
Buy
ADX color green and (ADX this hour> ADX previous hour)
Sell
ADX color red and (ADX this hour< ADX previous hour)
thx
sonicPHP Code:
for (i = Bars - 205; i >= 0; i --)
{
double adx1 =iCustom(NULL, 0, "Advanced_ADX",13,0,i);
double adx2 =iCustom(NULL, 0, "Advanced_ADX",13,1,i);
if ((adx1[i]>adx2[i])&&(adx1[i+1] > adx1[i]) // BUY
{ BUY routine}
if ((adx1[i]<adx2[i])&&(adx1[i+1] < adx1[i]) // SELL
{ SELL routine}
}
Subscribe to:
Posts (Atom)