Thursday, 17 January 2013

Belajar Membuat EA Sederhana 22 Martingel (Jebakan II)


Pastikan sudah mengikuti part 21 disini

Pada posting kali ini saya akan mengedit EA pada part 21 untuk ditambahi martingel .
Martingel yang di maksud juga mengacu pada jarak (range) order dan pergantian candel untuk mencegah terjadinya beberapa order ketika terjadi lonjakan harga dan candel panjang , seperti pada part 18

Penambahan coding martingelnya :

1. Fungsi untuk perintah order martingelnya

if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)<Max_order ) {OrderSend(Symbol(),OP_BUY,xlot(0),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue); wt=Time[0]; }
if(trad()==2 && wk!=Time[0] && jumlahorder(0)==0 && jumlahorder(1)<Max_order ) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0];  }

2. Fungsi untuk perhitungan jarak order dan  perintah ketika jarak terpenuhi


int trad()
{
 int type,dp; double opb,ops,lastlotb,lastlots; 
  for (int i = 0; i < OrdersTotal(); i++) {
   if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
   if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
     type=OrderType();
   if(type==0)opb = OrderOpenPrice();
   if(type==1)ops = OrderOpenPrice();
  }
   double as = opb - Jarak_order * pt;
   double bi = ops + Jarak_order * pt;
   if ( Ask <= as &&  jumlahorder(0)> 0 ) dp=1; 
 if ( Bid >= bi &&  jumlahorder(1)> 0 ) dp=2; 

return(dp);
}

3. Fungsi untuk perhitungan Lots setiap pengulangan ordernya
double xlot(int m)
{
 double ylot,dlot; 
  for (int i = 0; i < OrdersTotal(); i++) {
   if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
   if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic ||OrderType()!=m) continue;
     dlot=OrderLots();
     }
if(OrderType()==m)ylot=NR(Lots*MathPow(DiMarti,jumlahorder(m)));
return(ylot);
}


Nah setelah di rakit begini deh hasinya:


//+------------------------------------------------------------------+
//|                                                    EA Jum+Profit |
//|                                                gifaesa@yahoo.com |
//|                                     http://JumForex.blogspot.com |
//+------------------------------------------------------------------+

#property copyright "JumForex.blogspot.com"
#property link      "Gifaesa@yahoo.com"

extern string  Nama_EA                 = "Jum+Profit";
extern bool    Trade_buystop           = true;
extern bool    Trade_sellstop          = true;
extern string  Jam_server              = "Set sesuai selera";
extern int     Jam                     = 0;
extern int     Menit                   = 30;
extern bool    Tp_in_Money             = false;
extern double  TP_in_money             = 5;
extern int     Jarak_order             = 35;
extern int     Max_order               = 10;
extern double  DiMarti                 = 1.3;
extern int     TP                      = 100;
extern int     SL                      = 20;
extern double  Lots                    = 0.1;
extern int     Jarak_stop              = 25;
extern bool    TrailingStop_           = true;
extern int     TrailingStop            = 12;
extern int     Magic                   = 69;
double slb,tpb,sls,tps,pt,lslb,ltpb;
int wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(Digits==3 || Digits==5) pt=10*Point;   else   pt=Point;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
label();
if(TrailingStop_)dtrailing();
if(Tp_in_Money ){
  if(TP_in_money<= money(0)){ 
   closeall(0);
   closeall(2);
   }
  if(TP_in_money<= money(1)){ 
   closeall(1);
   closeall(3);
   }
 }
if(jumlahorder(0)==1 && jumlahorder(1)==0){ 
   closeall(5);
   }
if(jumlahorder(0)==0 && jumlahorder(1)==1){ 
   closeall(4);
   }
if(Hour()==23){
   closeall(4);
   closeall(5);
   }
//----
   double as = Ask + Jarak_stop*pt;
   double bi = Bid - Jarak_stop*pt;
   if(SL==0)slb=0;else slb=as-SL*pt;
   if(SL==0)sls=0;else sls=bi+SL*pt;
   if(TP==0)tpb=0;else tpb=as+TP*pt;
   if(TP==0)tps=0;else tps=bi-TP*pt;
if(DayOfWeek()!=1 && Hour()==Jam && Minute()==Menit && jumlahorder(0)==0 && jumlahorder(1)==0){
  if(jumlahorder(4)==0  && Trade_buystop  ) {OrderSend(Symbol(),OP_BUYSTOP,NR(Lots),as,3,slb, tpb,Nama_EA,Magic,0,Blue);}
  if(jumlahorder(5)==0  && Trade_sellstop ) {OrderSend(Symbol(),OP_SELLSTOP,NR(Lots),bi,3,sls, tps,Nama_EA,Magic,0,Red);}
 }
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)<Max_order ) {OrderSend(Symbol(),OP_BUY,xlot(0),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue); wt=Time[0]; }
if(trad()==2 && wk!=Time[0] && jumlahorder(0)==0 && jumlahorder(1)<Max_order ) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0];  }

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

int jumlahorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
  {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
     total++;
  }

return(total);
}
double NR(double thelot)
{
    double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
    minilot = MarketInfo(Symbol(), MODE_MINLOT),
    lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
    double lots = lstep * NormalizeDouble(thelot / lstep, 0);
    lots = MathMax(MathMin(maxlots, lots), minilot);
    return (lots);
}

void dtrailing()
{
for(int i=0; i<OrdersTotal(); i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
        if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic ) continue;
        if(OrderType()==OP_BUY)  {
         if(Bid-OrderOpenPrice()>pt*TrailingStop)  {
           if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0)) {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
              return(0);
              }
              }
           }
        if(OrderType()==OP_SELL)  {
         if((OrderOpenPrice()-Ask)>(pt*TrailingStop)){
           if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0)){
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
              return(0);
              }
              }
           }
     }
  
}
void closeall(int m)
{
 for (int i = OrdersTotal() - 1; i >= 0; i--) {
  OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic /*|| m!= OrderType()*/) continue;
  if (OrderType() == m) OrderDelete(OrderTicket());
  if (OrderType() == m) OrderDelete(OrderTicket());
  if (OrderType() == m) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
  if (OrderType() == m)OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
 }
}
double money(int m)
{
 double dp = 0;
 int i;
 for (i = 0; i < OrdersTotal(); i++) {
  OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  if (OrderSymbol() != Symbol()  || OrderMagicNumber()!=Magic || m!=OrderType()) continue;
  dp += OrderProfit();
 }
 return(dp);
}

void label()
{
 Comment("\n ",
   "\n ",
   "\n ------------------------------------------------",
   "\n :: =>+Jum+Profit<=",
   "\n :: =>JumForex.blogspot.com<=",
   "\n ------------------------------------------------",
   "\n :: Spread                 : ", MarketInfo(Symbol(), MODE_SPREAD),
   "\n :: Leverage               : 1 : ", AccountLeverage(),
   "\n :: Equity                 : ", AccountEquity(),
   "\n :: Jam Server             :", Hour(), ":", Minute(),
   "\n ------------------------------------------------",
   "\n :: Floting buy : ",money(0),
   "\n :: Floting sell : ",money(1),
   "\n ------------------------------------------------",
   "\n :: >>By: Jum69<<",
   "\n ------------------------------------------------");
}
int trad()
{
 int type,dp; double opb,ops,lastlotb,lastlots; 
  for (int i = 0; i < OrdersTotal(); i++) {
   if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
   if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
     type=OrderType();
   if(type==0)opb = OrderOpenPrice();
   if(type==1)ops = OrderOpenPrice();
  }
   double as = opb - Jarak_order * pt;
   double bi = ops + Jarak_order * pt;
   if ( Ask <= as &&  jumlahorder(0)> 0 ) dp=1; 
 if ( Bid >= bi &&  jumlahorder(1)> 0 ) dp=2; 

return(dp);
}
double xlot(int m)
{
 double ylot,dlot; 
  for (int i = 0; i < OrdersTotal(); i++) {
   if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
   if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic ||OrderType()!=m) continue;
     dlot=OrderLots();
     }
if(OrderType()==m)ylot=NR(Lots*MathPow(DiMarti,jumlahorder(m)));
return(ylot);
}

Ini hasil BTnya:



Okey seilahkan de coba ya...
Bila mana ada yang kurang jelas dan ada ide positif silahkan comment ya!

How brokers can mess with your account and take your money

Oh they can mess with you alright...

You've got to be warey when a broker rings you for business lol. Called me asking to try their new MT4 trading platform. Even the demo spreads are 33% larger than an average broker, no thanks.

I kept on getting trade context error 146, so I added some nice code to fix that... guess what... still get them, not as frequent but still messing with orders. Should expect that from a market making broker... wont be opening an account with them.

SD, have you ever noticed a significant delay in ticks on the chart your EA is trading every time you recompile that EA to be a little better? somethin fishy like EA transmission to broker me thinks...
I get my EA's to place an arrow on the chart its trading to provide a visual means that the signal happened on that very bar & time. If the trade doesn't go through I know that its broker manipulation then.



// my context busy code just before orderclose & ordersend, shouldn't get error 146

for (double tb=0; IsTradeContextBusy() && tb < 30; tb++) Sleep(100); //Wait upto 3 seconds (ie 30 x 100milliseconds)
if (tb > 0) Print("Trade context was busy ", DoubleToStr(100 * tb / 1000, 2)," seconds");
if (!IsTradeAllowed()) return;


// my arrow codes to tell me that my EA had a signal but if No Trade was executed? That would more than make me suspicious, I'd have proof!

// Place code before or after ordersend BUY

ObjectCreate("X137_Buy_" + Time[0], OBJ_ARROW, 0, TimeCurrent(), Bid);
ObjectSet("X137_Buy_" + Time[0], OBJPROP_ARROWCODE, 228);
ObjectSet("X137_Buy_" + Time[0], OBJPROP_COLOR, ArrowUP);

// Place code before or after ordersend SELL

ObjectCreate("X137_Sell_" + Time[0], OBJ_ARROW, 0, TimeCurrent(), Bid);
ObjectSet("X137_Sell_" + Time[0], OBJPROP_ARROWCODE, 230);
ObjectSet("X137_Sell_" + Time[0], OBJPROP_COLOR, ArrowDOWN);

Thursday, 10 January 2013

EA berdasarkan volume candle

logic BUY:
1.apabila candle pertama di TF 15 M ditutup di atas, dengan range minimal 30 point.
2.lalu buka candle berikutnya, naik 10 point langsung ambil posisi BUY.


logic SELL:
1.apabila candle pertama di TF 15 M ditutup di bawah, dengan range minimal 30 point.
2.lalu buka candle berikutnya, turun 10 point langsung ambil posisi SELL.

stop loss : 30 point
taking profit : 100 point
trailing stopnya : 20 point

NB: klo bisa, SL,TP,dan TS ( TrailingStop) nya di hidden.
dan jam tradingnya mulai jam 9.15 wita - 12.00 wita & dilanjutkan lagi trading jam 13.00 wita - 16.15 wita.

mohon bantuan revisi dan edit dari teman2 master yang mengerti MQL4.



//+------------------------------------------------------------------+
//| Belajar2.mq4 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

extern double Lots = 0.1;
extern bool use_hidden_TakeProfit = true;
extern int hidden_TakeProfit = 100;
extern bool use_hidden_StopLoss = true;
extern int hidden_Stoploss = 30 ;
extern int TrailingStop = 20 ;
extern int Magic = 12345;
extern int Slippage = 5;


//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

if (iClose(Symbol (),0,1)>iOpen(Symbol(),0,1)&& iClose(Symbol(),0,1)-iOpen(Symbol(),0,1)<=20*Point)
{OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-hidden_Stoploss*Point,Ask+hidden_TakeProfit*Point, "Belajar2",Magic,0,Blue);}

else if (iClose(Symbol (),0,1)<iOpen(Symbol(),0,1)&& iOpen(Symbol(),0,1)-iClose(Symbol(),0,1)<=20*Point)
{OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+ hidden_Stoploss*Point,Bid-hidden_TakeProfit*Point,"Belajar2",Magic,0,Red);}

if( OrderSelect(12345,SELECT_BY_TICKET) && OrderCloseTime()==0 ) {
if( OrderType()==OP_BUY ) {
OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]-Point*TrailingStop,OrderTakeProfit(),0);
}
else if( OrderType()==OP_SELL ) {
OrderModify(OrderTicket(),OrderOpenPrice(),Open[0]+Point*TrailingStop,OrderTakeProfit(),0);
}
}

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

Friday, 28 December 2012

EA Builder Alternative


Expert advisor builders (generators)

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/
Expert Advisor Builder for MetaTrader 4 is a well known web-based tool that is very basic and free. It's pretty old and it looks unsupported now, although there is a forum available.

http://eacreator.com/
EA Creator is a web-based expert advisors builder for MetaTrader 4. Unfortunately, it looks that it was abandoned.

http://eatree.com/
EATree is a software for building expert advisors for MetaTrader 4 and MetaTrader 5. Here we connect boxes that represents AND logic, OR logic, IF condition, conversion or mathematical functions, time series, indicators (system or custom) and others to create the main logic. Finally, we connect that logic to the special Trade box.

http://www.forexeadvisor.com/
ForexEAdvisor is also popular web-based expert advisor builder that is simple and free to use.

http://forexgenerator.com/
Forex Generator is a software for building expert advisors and technical indicators for MetaTrader 4 and MetaTrader 5. This application is the most similar to fxDreema. It uses visually connected blocks for creating a trading diagram. Each block represents some piece of code, a code function. In addition, there is a Block Editor to create and manage custom blocks. There is a forum available.

http://molanis.com/
Molanis is a set of Java-based products for building expert advisors and technical indicators for MetaTrader 4 and MetaTrader 5. A trading diagram is created by connecting a few simple specially designed blocks. There is a forum available.

http://noprogra.com/
NoProgra is a new software for building expert advisors for MetaTrader 4. The way of algorithm creation here is as they say in "natural language". Which means, that we can build our project in a way we speak, write and think. This platform is Java-based and it's currently free to download and use.

http://strategytune.com/
StrategyTune is a free and simple web tool for building expert advisors for MetaTrader 4. No installations and no registrations needed, you can start building EA's just right now.

http://www.iexpertadvisor.com/
Visual Traders Studio is a software for building expert advisors for MetaTrader 4. Six basic Element types (blocks) are used to create the trading logic - Start element, Note element, Variable element, Logic element, Function element and End element. There is a forumavailable.


EAbuilder_FX Dreema

I have been looking for EAbuilder and in this website are some

http://fxdreema.com/alternatives

Question is does anyone has experience with any of the above ? 
Basicaly I would look for anything that can provide good support and or good lessons on how to. I do want to build something complex.

Martingale code

I wrote a piece of code to do what you ask, I hope this helps.
There is not a expert adviser, is a code to add to yours experts.
=================================================


//+------------------------------------------------------------------+
//|                                                        test1.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern int MagicNumber=123;
extern double StartLotsize=0.01;
extern double MultiplierLot=2.0;
extern double StepOrder=10;
extern int MaxGrid=3;
//---------------------------------------------------------------------------------------
  int MultiplierPoint;
  double DigitsPoints;
  int BuyCnt;
  int SellCnt;
  double PipsBuy;
  double PipsSell;
  bool SendBuy;
  bool SendSell;
  double LotBuy;
  double LotSell;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
MultiplierPoint=1;
if(MarketInfo(Symbol(),MODE_DIGITS)==5||MarketInfo(Symbol(),MODE_DIGITS)==3) MultiplierPoint=10;
DigitsPoints=MarketInfo(Symbol(),MODE_POINT)*MultiplierPoint;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   BuyCnt=0;
   SellCnt=0;
   PipsBuy=0;
   PipsSell=0;
   SendBuy=false;
   SendSell=false;
   LotBuy=StartLotsize;
   LotSell=StartLotsize;
//----
   for(int i=0; i<OrdersTotal(); i++)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {
   if(OrderMagicNumber()==MagicNumber)
   {
   if(OrderType()==OP_BUY)
   {
   BuyCnt++;
   PipsBuy=(Bid-OrderOpenPrice())/DigitsPoints;
   }
   if(OrderType()==OP_SELL)
   {
   SellCnt++;
   PipsSell=(OrderOpenPrice()-Ask)/DigitsPoints;
   }
   }
   }
   }
//----
   if((BuyCnt<MaxGrid)&&(PipsBuy>=StepOrder))
   {
   LotBuy=NormLot(StartLotsize*MathMax(1,MathPow(MultiplierLot,BuyCnt)));
   SendBuy=true;
   }
   if((SellCnt<MaxGrid)&&(PipsSell>=StepOrder))
   {
   LotSell=NormLot(StartLotsize*MathMax(1,MathPow(MultiplierLot,SellCnt)));
   SendSell=true;
   }
//----
  if(SendBuy==true)
  {
  //send orders buy... with lot=LotBuy
  return(0);
  }
//----
  if(SendSell==true)
  {
  //send orders sell... with lot=LotSell
  return(0);
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//Normalize lot                                                                                                        //
double NormLot(double LotSize)
{
int LotDigit;
//------------------------------------------------------
//Broker lot info
double MinLot=MarketInfo(Symbol(),MODE_MINLOT);
double MaxLot=MarketInfo(Symbol(),MODE_MAXLOT);
double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);
//------------------------------------------------------
//Calculate lot digits
if(LotStep==1) LotDigit=0;
if(LotStep==0.1) LotDigit=1;
if(LotStep==0.01) LotDigit=2;
if(LotStep==0.001) LotDigit=3;
//------------------------------------------------------
return(NormalizeDouble(MathMin(MathMax(LotSize,MinLot),MaxLot),LotDigit));
}

Thursday, 27 December 2012

iCustom fxsniper3cci


supaya indinya bisa di set di EA juga di deklarasikan
"extern int CCI_Period = 14"
"extern int T3_Period = 5"
"extern double b = 0.618"

Nah untuk nilai indi ini bisa di lihat pada mt4 --->terkan CTRL D , maka akan kelihatan nilai nya output keluaran hanya satu macam aja 
double x=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_ Period,b,0,shif);
shif bisa di isi 0 (sekarang), 1( satu candel sebelum sekarang, 2(dua candel sebelum sekarang) dst.......
PHP Code:
double x=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_Period,b,0,0);//(sekarang)
   
double xx=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_Period,b,0,1);//satu candel sebelum sekarang
   
double xxx=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_Period,b,0,2);//dua candel sebelum sekarang  
gitu deh gambarannya

==========================
kalau dilihat didata windows nya nilai outputnya hanya 1 nilainya bro
coba untuk cek value coba ini

PHP Code:
   double x=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_Period,b,0,0);
   
double y=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_Period,b,1,0);
   
double z=iCustom(Symbol(),0,"fxsniper3cci",CCI_Period,T3_Period,b,2,0);
   
Comment("nilai x",x,
          
"\n nilai y",y,
          
"\n nilai z",z);