อันนี้เป็น code EA ที่เขียนครับ
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
extern int MagicNumber = 1234;
extern double Lotsize = 0.01;
extern int TP = 200;
extern int SL = 100;
extern int PercentSL = 20;
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
extern string Indicator1 = "WPR_DOUBLE";
extern int Period_EMAWPR1 = 5;
extern int Period_EMAWPR2 = 5;
extern int Period_EMAWPR2_Shift=1;
extern int ModeMA = 0;
//+------------------------------------------------------------------+
//| สั่ง tl ทำงาน |
//+------------------------------------------------------------------+
extern bool UseMoveToBreakeevent = true;
extern int WhenTomoveToBe = 50;
extern int PipsToLockIn = 10;
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
extern bool UseTraillingStop =true;
extern int WhenToTrail =50;
extern int TrailAmount =50;
extern int Position = 100;
double PriceAsk,PriceBid;
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
double EMAWPR,EMAWPR1,EMAWPR2;
void GetWPR_DOUBLE(){
EMAWPR1 = iCustom(Symbol(),0, "WPR_DOUBLE", 14, 5, 5, 1, 0, 0, 0);
EMAWPR1 = iCustom(Symbol(),0, "WPR_DOUBLE", 14, 5, 5, 1, 0, 1, 0);
EMAWPR2 = iCustom(Symbol(),0, "WPR_DOUBLE", 14, 5, 5, 1, 0, 2, 0);
}
//+------------------------------------------------------------------+
double AutoSL(){
double sum;
sum = ((AccountBalance()/100)*PercentSL)/Lotsize;
return(sum);
}
///+------------------------------------------------------------------+
void OpenBuy(){
double sl =0;
double tp = Ask+TP*Point;
if(PercentSL > 0){
sl = Ask-AutoSL()*Point;
}
else sl = Ask-SL*Point;
OrderSend(Symbol(),OP_BUY,Lotsize,Ask,3,sl,tp,"My order",MagicNumber,0,clrGreen);
PriceAsk = Ask;
}
///+------------------------------------------------------------------+
void OpenSell(){
double sl = 0;
double tp = Bid-TP*Point;
if(PercentSL >0){
sl =Bid+AutoSL()*Point;
}
else sl = Bid+SL*Point;
OrderSend(Symbol(),OP_SELL,Lotsize,Bid,3,sl,tp,"My order",MagicNumber,0,clrRed);
PriceBid = Bid;
}
///+------------------------------------------------------------------+
void CloseOrderAll(int type){
for(int i= OrdersTotal()-1;i >=0;i--){
if(OrderSelect(i,SELECT_BY_POS) == true){
if(OrderMagicNumber() == MagicNumber && OrderSymbol()== Symbol()){
switch(type){
case OP_BUY:
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),0,0);
break;
case OP_SELL:
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),0,0);
break;
}
}
}
}
}
///+------------------------------------------------------------------+
int CountOrder(int type){
int CntOrder=0;
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType() == type && OrderMagicNumber() == MagicNumber){
if(OrderSymbol() == Symbol()){
CntOrder++;
}
}
}
return(CntOrder);
}
//+------------------------------------------------------------------+
void OnTick(){
if(UseMoveToBreakeevent) MoveToBreakevent();
if(UseTraillingStop)AdjustTrail();
EntryOpenWPR_DOUBLE();
}
//+------------------------------------------------------------------+
void EntryOpenWPR_DOUBLE(){
GetWPR_DOUBLE();
if(CountOrder(OP_BUY) == 0){
if(EMAWPR1 > EMAWPR2 && EMAWPR1 < -50 && Close[0] < -50 ){
OpenBuy();
CloseOrderAll(OP_SELL);
}
}
if(CountOrder(OP_SELL) == 0){
if(EMAWPR1 < EMAWPR2 && EMAWPR1 > -50 && Close[0] > -50 ){
OpenSell();
CloseOrderAll(OP_BUY);
}
}
}
//+------------------------------------------------------------------+
void MoveToBreakevent(){
for(int i=OrdersTotal()-1;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber() == MagicNumber){
if(OrderSymbol() == Symbol()){
if(OrderType() == OP_BUY){
if(Bid-OrderOpenPrice() > WhenTomoveToBe*Point){
if(OrderOpenPrice() > OrderStopLoss()){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+PipsToLockIn*Point,OrderTakeProfit(),0,Green);
}
}
}
if(OrderType() == OP_SELL){
if(OrderOpenPrice()-Ask > WhenTomoveToBe*Point){
if(OrderOpenPrice() < OrderStopLoss()){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-PipsToLockIn*Point,OrderTakeProfit(),0,Red);
}
}
}
}
}
}
}
}
///+------------------------------------------------------------------+
void AdjustTrail(){
for(int i=OrdersTotal()-1;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber() == MagicNumber){
if(OrderSymbol() == Symbol()){
if(OrderType() == OP_BUY){
if(Bid-OrderOpenPrice() > WhenToTrail*Point){
if(OrderStopLoss() < Bid-TrailAmount*Point){
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailAmount*Point,OrderTakeProfit(),0,0);
}
}
}
if(OrderType() == OP_SELL){
if(OrderOpenPrice() - Ask > WhenToTrail*Point){
if(OrderStopLoss() > Ask+TrailAmount*Point){
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailAmount*Point,OrderTakeProfit(),0,0);
}
}
}
}
}
}
}
}
///+------------------------------------------------------------------+
ผมเขียนอะไรผิดตรงไหนครับ