Tuesday, 18 September 2012

Pelajaran Coding no. 2

[CODE][///+------------------------------------------------------------------+
//| EA GP_Arrow.mq4 |
//| Dwi M ea@dwim.web.id |
//| http://ea.dwim.web.id |
//+------------------------------------------------------------------+
#property copyright "Dwi M ea@dwim.web.id"
#property link "http://ea.dwim.web.id"

extern int TakeProfit = 20;
extern int StopLoss = 20;
extern double Lot = 1.0;
extern int Slippage = 3;

double dPoint = 0;


//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
CekDigitBroker(); // Periksa Jumlah Digit Broker
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double dArrowUp=0, dArrowDown=0;
int iTrade=0;

dArrowUp = iCustom(Symbol(),0,"IINWMARROWS",0,0);
dArrowDown = iCustom(Symbol(),0,"IINWMARROWS",1,0);

Comment("EA GP Arrow \nDwi M ea@dwim.web.id \nhttp://ea.dwim.web.id"); 

if(OrdersTotal()<1)
{
if((dArrowUp>0) && (dArrowDown==0))
{
Buy();
}
}
else
{
if((dArrowDown>0) && (dArrowUp==0))
{
Sell();
}
}

for(iTrade=0;iTrade<OrdersTotal();iTrade++)
{
OrderSelect(iTrade,SELECT_BY_POS,MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
{
if((dArrowDown>0) && (dArrowUp==0))
{
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage, Violet);
}
}
else
{
if((dArrowUp>0) && (dArrowDown==0))
{
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage, Violet);

}
}

}

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

/* Kumpulan Library */

//Memeriksa jumlah digit broker
void CekDigitBroker()
{
if(Digits==3 || Digits==5)
{
dPoint = Point*10;
}
else if(Digits==2 || Digits==4)
{
dPoint = Point;
}
}

/* Melakukan OP Buy */
void Buy()
{
OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,Bid-StopLoss*dPoint,Ask+TakeProfit*dPoint,0); 

}

/* Melakukan OP Sell */
void Sell()
{
OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,Ask+St opLoss*dPoint,Bid-TakeProfit*dPoint,0);
}]

yang ini custom indicatornya
[CODE][///+------------------------------------------------------------------+
//| IINWMARROWS.mq4 |
//| Based on EMA_CROSS.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//| Last little modified by Iin Zulkarnain |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
double CrossUp[];
double CrossDown[];
extern int FasterMode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA= 3;
extern int SlowerMode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA= 3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- 
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() 
{
int limit, i, counter;
double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
double Range, AvgRange;
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(i=0; i<=limit; i++) 
{
counter=i;
Range=0;
AvgRange=0;
for(counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
fasterMAnow=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i);
fasterMAprevious=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);
fasterMAafter=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);
//----
slowerMAnow=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i);
slowerMAprevious=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i+1);
slowerMAafter=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1);
if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter)) 
{
CrossUp[i]=Low[i] - Range*0.3;
CrossUp[i]=Low[i] - Range*0.3;
}
else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter)) 
{
CrossDown[i]=High[i] + Range*0.3;
CrossDown[i]=High[i] + Range*0.3;
}
}
return(0);
}
//+------------------------------------------------------------------+]



============================================



Perunahan dengan indi IINWMARROW.mq4

Dari melihat jumlah extern variabel indikator IINWMARROWS.mq4 ada 4 variabel yang harus dimasukkan ke iCustom.



Code:
extern int FasterMode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA= 3;
extern int SlowerMode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA= 3;


Jadi bentuk iCustomnya kira-kira menjadi sbb :

Code:
dArrowUp = iCustom(Symbol(),0,"IINWMARROWS",3,3,3,3,0,0);
dArrowDown = iCustom(Symbol(),0,"IINWMARROWS",3,3,3,3,1,0);


No comments:

Post a Comment