Jump to content

swb grid 4 modified


Recommended Posts

Re: swb grid 4 modified

 

Hi,

 

Can someone educate this EA. I have tried to run backtest on this EA on Fxpro but getting invalid trade volume?

 

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

//+------------------------------------------------------------------+

//| swb grid 4.mq4 |

//| totom sukopratomo |

//| [email protected] |

//+------------------------------------------------------------------+

 

//+------------------------------------------------------------------+

//+----- belum punya account fxopen? --------------------------------+

//+----- buka di http://fxind.com?agent=123621 ----------------------+

//+------------------------------------------------------------------+

 

//+------------------------------------------------------------------+

//+----- ingin bisa scalping dengan real tp 3 pips? -----------------+

//+----- ingin dapat bonus $30 dengan deposit awal $100? ------------+

//+----- buka account di http://instaforex.com/index.php?x=NQW ------+

//+------------------------------------------------------------------+

 

//+---- KEBANYAKAN PROMOSI? TAHULAH BRO... DARIPADA MINTA DONASI ---+

//====================================================================

/*

Note: EA ini tidak berdiri sendiri melainkan memerlukan file include

OrderZ.mqh yang harus di save di folder C:/program files/metatrader/

expert/include atau didirectori lain kalau memang installnya bukan

pada path diatas.

file include tidak perlu di compile karena hanya akan nampak warning

yang tidak perlu ditanggapi :). Harapan saya dengan menggunakan file

include akan mempercepat eksekusi ordernya terutama close-nya.

*/

 

#property copyright "totom sukopratomo"

#property link "[email protected]"

#include <OrderZ.mqh>

 

extern bool usedailytarget=false;

extern double dailytarget=100;

extern double initiallot=0.1;

extern bool lotsoptimized=true;

extern double risk=1;

extern double maxlot=0.95;

extern double lotdigits=3;

extern bool basketpercent=false;

extern double profit=10;

extern double loss=30;

extern int waitingtime=1440;

extern int level=10;

extern bool martingale=true;

extern double multiplier=1.59;

extern int range=31;

extern bool lotincrement=false;

extern double increment=0.1;

extern bool tradefriday=true;

extern bool useslandtp=false;

extern int sl=50;

extern int tp=50;

extern double tpinmoney=5.0;

extern int magic=1;

extern bool stealthmode=true;

extern bool usebb=true;

extern int bbtimeframe=0;

extern int bbperiod=20;

extern int bbdeviation=2;

extern int bbshift=0;

extern bool usestoch=true;

extern int stochtimeframe=0;

extern int k=5;

extern int d=3;

extern int slowing=3;

extern int price_field=0;

extern int lolevel=30;

extern int uplevel=70;

extern int stochshift=0;

extern bool use_rsi=true;

extern int rsitimeframe=0;

extern int rsiperiod=12;

extern int lower=30;

extern int upper=70;

extern int rsishift=0;

 

double point;

double minlot;

double stoplevel;

int prec=0;

int a=0;

int b=0;

 

int i;

double lastprofit;

int history;

 

datetime t0,t1,lastbuyopentime,lastsellopentime,waiting;

double lastbuyopenprice,lastsellopenprice,lastbuyprofit,lastsellprofit;

double lotsfactor=1,initiallotsfactor=1,ilots,lastbuylot,lastselllot,lastlot,mlots;

double ask,bid,cb,min,max;

int bc=-1,tpb,tps,cnt,istart,iend,total,ticket;

int lastorder,buyorderprofit,sellorderprofit;

 

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

 

int init(){

if(Digits==3 || Digits==5) point=10*Point;

else point=Point;

minlot=MarketInfo(Symbol(),MODE_MINLOT);

if(minlot==0.01)prec=2;

if(minlot==0.1)prec=1;

return(0);

}

 

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

 

int deinit(){

return(0);

}

 

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

 

int start(){

 

if(basketpercent){

double ipf=profit*(0.01*AccountBalance());

double ilo=loss*(0.01*AccountBalance());

cb=AccountEquity()-AccountBalance();

if(cb>=ipf||cb<=(ilo*(-1))){

closebuy();

closesell();

waiting=TimeCurrent();

return(0);

}

}

if(basketpercent && (TimeCurrent()-waiting)<(waitingtime*60))return(0);

if(lotsoptimized){

history=OrdersHistoryTotal();

if(history>0){

//for(i=0;i<history;i++){

OrderSelect(history,SELECT_BY_POS,MODE_HISTORY);

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){

lastprofit=OrderProfit();

}

//}

}

}

Comment("\ntimecurrent = "+DoubleToStr(TimeCurrent(),0),"\nwaiting = "+DoubleToStr(waiting,0)

,"\ndifference = "+DoubleToStr(TimeCurrent()-waiting,0),"\nwaitingtime = "+DoubleToStr(waitingtime*60,0));

if(lotsoptimized && (martingale==false || (martingale && lastprofit>=0))){initiallot=NormalizeDouble((AccountBalance()/1000)*0.01*risk,lotdigits);if(initiallot>maxlot)initiallot=maxlot;}

if(dailyprofit()>=dailytarget && usedailytarget || a>0){

a++;

for(int i=OrdersTotal()-1; i>=0; i--){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

if(OrderType()==OP_BUY) OrderCloseZ(OrderTicket(),OrderLots(),Bid,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE);

else

if(OrderType()==OP_SELL) OrderCloseZ(OrderTicket(),OrderLots(),Ask,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE);

else OrderDelete(OrderTicket());

}

if(total()==0) a=0;

return(0);

}

if(!tradefriday && DayOfWeek()==5 && total()==0){return(0);}

if(profit()>=tpinmoney || b>0){

b++;

for(i=OrdersTotal()-1; i>=0; i--){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

if(OrderType()==OP_BUY)OrderCloseZ(OrderTicket(),OrderLots(),Bid,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE);

else

if(OrderType()==OP_SELL)OrderCloseZ(OrderTicket(),OrderLots(),Ask,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE);

else OrderDelete(OrderTicket());

}

if(total()==0) b=0;

}

if(total()==0 && a==0){

if(signal()>0){

if(stealthmode){

if(!useslandtp)OrderSendZ(Symbol(),OP_BUY,initiallot,Ask,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Blue);

else OrderSendZ(Symbol(),OP_SELL,initiallot,Ask,MarketInfo(Symbol(),MODE_SPREAD),Ask-sl*point,Ask+tp*point,"",magic,0,Blue);

}

else{

if(!useslandtp){

if(OrderSendZ(Symbol(),OP_BUY,initiallot,Ask,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Blue)>0){

for(i=1;i<level;i++){

if(martingale)OrderSendZ(Symbol(),OP_BUYLIMIT,NormalizeDouble(initiallot*MathPow(multiplier,i),prec),Ask-(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Blue);

if(lotincrement)OrderSendZ(Symbol(),OP_BUYLIMIT,NormalizeDouble(initiallot+(i*increment),prec),Ask-(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Blue);

}

}

}

else{

if(OrderSendZ(Symbol(),OP_BUY,initiallot,Ask,MarketInfo(Symbol(),MODE_SPREAD),Ask-sl*point,Ask+tp*point,"",magic,0,Blue)>0){

for(i=1;i<level;i++){

if(martingale)OrderSendZ(Symbol(),OP_BUYLIMIT,NormalizeDouble(initiallot*MathPow(multiplier,i),prec),Ask-(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),(Ask-(range*i)*point)-sl*point,(Ask-(range*i)*point)+tp*point,"",magic,0,Blue);

if(lotincrement)OrderSendZ(Symbol(),OP_BUYLIMIT,NormalizeDouble(initiallot+(i*increment),prec),Ask-(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),(Ask-(range*i)*point)-sl*point,(Ask-(range*i)*point)+tp*point,"",magic,0,Blue);

}

}

}

}

}

if(signal()<0)

{

if(stealthmode)

{

if(!useslandtp) OrderSendZ(Symbol(),OP_SELL,initiallot,Bid,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Red);

else OrderSendZ(Symbol(),OP_SELL,initiallot,Bid,MarketInfo(Symbol(),MODE_SPREAD),Bid+sl*point,Bid-tp*point,"",magic,0,Red);

}

else{

if(!useslandtp){

if(OrderSendZ(Symbol(),OP_SELL,initiallot,Bid,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Red)>0){

for(i=1;i<level;i++){

if(martingale)OrderSendZ(Symbol(),OP_SELLLIMIT,NormalizeDouble(initiallot*MathPow(multiplier,i),prec),Bid+(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Red);

if(lotincrement)OrderSendZ(Symbol(),OP_SELLLIMIT,NormalizeDouble(initiallot+(i*increment),prec),Bid+(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Red);

}

}

}

else{

if(OrderSendZ(Symbol(),OP_SELL,initiallot,Bid,MarketInfo(Symbol(),MODE_SPREAD),Bid+sl*point,Bid-tp*point,"",magic,0,Red)>0){

for(i=1;i<level;i++){

if(martingale)OrderSendZ(Symbol(),OP_SELLLIMIT,NormalizeDouble(initiallot*MathPow(multiplier,i),prec),Bid+(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),(Bid+(range*i)*point)+sl*point,(Bid+(range*i)*point)-tp*point,"",magic,0,Red);

if(lotincrement)OrderSendZ(Symbol(),OP_SELLLIMIT,NormalizeDouble(initiallot+(i*increment),prec),Bid+(range*i)*point,MarketInfo(Symbol(),MODE_SPREAD),(Bid+(range*i)*point)+sl*point,(Bid+(range*i)*point)-tp*point,"",magic,0,Red);

}

}

}

}

}

}

if(total()>0 && total()<level && stealthmode){

if(lasttype()==OP_BUY){

if(lastprice()-Ask>=range*point) {

if(!useslandtp){

if(martingale)OrderSendZ(Symbol(),OP_BUY,NormalizeDouble(lastlot()*multiplier,prec),Ask,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Blue);

if(lotincrement)OrderSendZ(Symbol(),OP_BUY,NormalizeDouble(lastlot()+increment,prec),Ask,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Blue);

}

else{

if(martingale)OrderSendZ(Symbol(),OP_BUY,NormalizeDouble(lastlot()*multiplier,prec),Ask,MarketInfo(Symbol(),MODE_SPREAD),Ask-sl*point,Ask+tp*point,"",magic,0,Blue);

if(lotincrement)OrderSendZ(Symbol(),OP_BUY,NormalizeDouble(lastlot()+increment,prec),Ask,MarketInfo(Symbol(),MODE_SPREAD),Ask-sl*point,Ask+tp*point,"",magic,0,Blue);

}

}

}

if(lasttype()==OP_SELL){

if(Bid-lastprice()>=range*point) {

if(!useslandtp){

if(martingale)OrderSendZ(Symbol(),OP_SELL,NormalizeDouble(lastlot()*multiplier,prec),Bid,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Red);

if(lotincrement)OrderSendZ(Symbol(),OP_SELL,NormalizeDouble(lastlot()+increment,prec),Bid,MarketInfo(Symbol(),MODE_SPREAD),0,0,"",magic,0,Red);

}

else{

if(martingale)OrderSendZ(Symbol(),OP_SELL,NormalizeDouble(lastlot()*multiplier,prec),Bid,MarketInfo(Symbol(),MODE_SPREAD),Bid+sl*point,Bid-tp*point,"",magic,0,Red);

if(lotincrement)OrderSendZ(Symbol(),OP_SELL,NormalizeDouble(lastlot()+increment,prec),Bid,MarketInfo(Symbol(),MODE_SPREAD),Bid+sl*point,Bid-tp*point,"",magic,0,Red);

}

}

}

}

return(0);

}

 

int total(){

int i=0, total=0;

while(i<OrdersTotal()){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol()|| OrderMagicNumber()!=magic)continue;

total++;

i++;

}

return(total);

}

 

double profit(){

int i=0;

double prof=0;

while(i<OrdersTotal()){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol()|| OrderMagicNumber()!=magic)continue;

prof+=OrderProfit();

i++;

}

return(prof);

}

 

int lasttype(){

int i=0, type=-1;

while(i<OrdersTotal()){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol()|| OrderMagicNumber()!=magic)continue;

type=OrderType();

i++;

}

return(type);

}

 

double lastprice(){

int i=0;

double prc=0;

while(i<OrdersTotal()){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol()|| OrderMagicNumber()!=magic)continue;

prc=OrderOpenPrice();

i++;

}

return(prc);

}

 

double lastlot(){

int i=0;

double lot=0;

while(i<OrdersTotal()){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol()|| OrderMagicNumber()!=magic)continue;

lot=OrderLots();

i++;

}

return(lot);

}

 

int signal(){

double up_bb=iBands(Symbol(),bbtimeframe,bbperiod,bbdeviation,0,PRICE_CLOSE,MODE_UPPER,bbshift);

double lo_bb=iBands(Symbol(),bbtimeframe,bbperiod,bbdeviation,0,PRICE_CLOSE,MODE_LOWER,bbshift);

double stoch=iStochastic(Symbol(),stochtimeframe,k,d,slowing,MODE_SMA,PRICE_CLOSE,MODE_SIGNAL,stochshift);

double rsi=iRSI(Symbol(),rsitimeframe,rsiperiod,PRICE_CLOSE,rsishift);

int a=0,b=0,c=0;

if(Close[0]<lo_bb)a--;

if(Close[0]>up_bb)a++;

if(stoch<lolevel)b--;

if(stoch>uplevel)b++;

if(rsi<lower) c--;

if(rsi>upper) c++;

if(a<0 && b<0 && c<0 && usebb && usestoch && use_rsi)return( 1);

if(a>0 && b>0 && c>0 && usebb && usestoch && use_rsi)return(-1);

if(a<0 && b<0 && usebb && usestoch && !use_rsi)return( 1);

if(a>0 && b>0 && usebb && usestoch && !use_rsi)return(-1);

if(a<0 && c<0 && usebb && !usestoch && use_rsi)return( 1);

if(a>0 && c>0 && usebb && !usestoch && use_rsi)return(-1);

if(b<0 && c<0 && !usebb && usestoch && use_rsi)return( 1);

if(b>0 && c>0 && !usebb && usestoch && use_rsi)return(-1);

if(a<0 && usebb && !usestoch && !use_rsi)return( 1);

if(a>0 && usebb && !usestoch && !use_rsi)return(-1);

if(b<0 && !usebb && usestoch && !use_rsi)return( 1);

if(b>0 && !usebb && usestoch && !use_rsi)return(-1);

if(c<0 && !usebb && !usestoch && use_rsi)return( 1);

if(c>0 && !usebb && !usestoch && use_rsi)return(-1);

return(0);

}

 

double dailyprofit(){

int i=0;

int day=TimeDay(TimeCurrent()),month=TimeMonth(TimeCurrent()),year=TimeYear(TimeCurrent());

double prof=0;

while(i<OrdersHistoryTotal()){

OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic)continue;

if(TimeDay(OrderOpenTime())!=day) break;

if(TimeMonth(OrderOpenTime())!=month) break;

if(TimeYear(OrderOpenTime())!=year) break;

prof+=OrderProfit();

i++;

}

return(prof);

}

 

//|---------close

 

void closebuy(){

total=OrdersTotal();

if(total>0){

for(i=0;i<total;i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY){

OrderClose(OrderTicket(),OrderLots(),Bid,0);

}

}

}

}

 

void closesell(){

total=OrdersTotal();

if(total>0){

for(i=0;i<total;i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL){

OrderClose(OrderTicket(),OrderLots(),Ask,0);

}

}

}

}

 

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

 

OrderZ.mqh

 

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

 

//+------------------------------------------------------------------+

//| OrderZ.mq4 |

//| totom sukopratomo |

//| [email protected] |

//+------------------------------------------------------------------+

#property copyright "totom sukopratomo"

#property link "[email protected]"

//+------------------------------------------------------------------+

//| EX4 imports |

//+------------------------------------------------------------------+

#import "stdlib.ex4"

string ErrorDescription(int error_code);

#import

//+------------------------------------------------------------------+

//+---JANGAN MENG-COMPILE FILE INI, CUKUP COMPILE MAIN EA-NYA SAJA---+

//+---SIMPAN FILE INI DI C:/program files/metatrader/expert/include--+

//+------------------------------------------------------------------+

 

int OrderSendZ(string simbol, int cmd, double lot, double prc, int slippage, double sl,

double tp, string cmt, int magic, datetime expiration, color clr)

{

int ticket=OrderSend(simbol,cmd,lot,prc,slippage,sl,tp,cmt,magic,expiration,clr);

if(ticket<=0) Print("last error is ", ErrorDescription(GetLastError()));

return(ticket);

}

 

bool OrderCloseZ(int ticket, double lot, double prc, int slippage, color clr)

{

bool res=OrderClose(ticket,lot,prc,slippage,clr);

if(!res) Print("last error is ", ErrorDescription(GetLastError()));

return(res);

}

 

==========

Link to comment
Share on other sites

Guest dave_rimmer

Re: swb grid 4 modified

 

Can someone make work for 5 digit brokers

 

it's ready for work with 5 digits brokers. Look yourself:

 

if(Digits==3 || Digits==5) point=10*Point;
else point=Point;

 

 

I see but it does not work!!!

when you attach to a chart no orders and you cannot alter its parameters once attached.

Someone needs to find a working copy of this , since it is hailed at producing very good results

Link to comment
Share on other sites

Guest dave_rimmer

Re: swb grid 4 modified

 

I have fixed the hanging problem that due to some looping error.

 

Here is the fixed copy.

 

http://rapid*share.com/files/317574991/swb_grid_4-f.mq4.html

 

use syntax CODE for links :)

 

K

 

 

thanks for the fix

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...