Jump to content

Recommended Posts

Posted

Hi

I'm wondering if someone had the time to turn the below mql in to ecn broker compatible like gomarkets?

 

 

string nameexpert="Robotic";

int magic=1234;

 

extern string moneymanagement="Money Management";

 

extern double lots=0.2;

 

extern string ordersmanagement="Order Management";

 

extern double maxorders=200;

extern bool hidesl=false;

extern bool hidetp=false;

extern double lstoploss=0;

extern double sstoploss=0;

extern double ltakeprofit=10;

extern double stakeprofit=10;

extern double ltrailingstop=20;

extern double strailingstop=10;

extern int slippage=1;

 

extern string entrylogics="Entry Logics";

 

extern int closetimeframe=5;

extern int closeshift=0;

extern int matimeframe=5;

extern int maperiod1=5;

extern int maperiod2=4;

extern int mamethod=0;

extern int maprice=1;

extern int mashift=1;

 

bool usesound=false;

string namefilesound="Alert.wav";

 

color clopenbuy=Green;

color clclosebuy=Aqua;

color clopensell=Red;

color clclosesell=Violet;

color clmodibuy=Blue;

color clmodisell=Red;

 

int total,i;

 

double pt,mt;

int dg;

 

int init(){

dg=Digits;

if(dg==3 || dg==5){pt=Point*10;mt=10;}else{pt=Point;mt=1;}

}

 

void deinit(){

Comment("");

}

 

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

//| |

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

 

int start(){

if(Bars<50){

Print("bars less than 50");

return(0);

}

if(ltakeprofit<0.5){

Print("TakeProfit less than 0.5");

return(0);

}

if(stakeprofit<0.5){

Print("TakeProfit less than 0.5");

return(0);

}

 

double close=iClose(NULL,closetimeframe,closeshift);

double ma1=iMA(NULL,matimeframe,maperiod1,0,mamethod,maprice,mashift);

double ma2=iMA(NULL,matimeframe,maperiod2,0,mamethod,maprice,mashift);

 

if(AccountFreeMargin()<(1000*lots)){

Print("We have no money. Free Margin = ",AccountFreeMargin());

return(0);

}

if(!existpositions()){

if(close<ma1){

openbuy();

return(0);

}

if(close>ma2){

opensell();

return(0);

}

}

if(hidesl)hideclosebuy();

if(hidetp)hideclosesell();

trailingpositionsbuy(ltrailingstop);

trailingpositionssell(strailingstop);

return(0);

}

 

bool existpositions(){

for(int i=maxorders;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

if(OrderSymbol()==Symbol())return(True);

}

}

return(false);

}

 

void trailingpositionsbuy(int trailingstop){

for(int i=maxorders;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

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

if(OrderType()==OP_BUY){

if(Bid-OrderOpenPrice()>trailingstop*pt){

if(OrderStopLoss()<Bid-trailingstop*pt)modifystoploss(Bid-trailingstop*pt);

}

}

}

}

}

}

 

void trailingpositionssell(int trailingstop){

for(int i=maxorders;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

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

if(OrderType()==OP_SELL){

if(OrderOpenPrice()-Ask>trailingstop*pt){

if(OrderStopLoss()>Ask+trailingstop*pt || OrderStopLoss()==0)modifystoploss(Ask+trailingstop*pt);

}

}

}

}

}

}

 

void modifystoploss(double ldstopLoss){

bool fm;

fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldstopLoss,OrderTakeProfit(),0,CLR_NONE);

if(fm && usesound)PlaySound(namefilesound);

}

 

void openbuy(){

double ldlot,ldstop,ldtake;

string lscomm;

ldlot=getsizelot();

if(lstoploss>0 && hidesl==false)ldstop=getstoplossbuy();else ldstop=0;

if(ltakeprofit>0 && hidetp==false)ldtake=gettakeprofitbuy();else ldtake=0;

lscomm=getcommentfororder();

OrderSend(Symbol(),OP_BUY,ldlot,Ask,slippage*mt,ldstop,ldtake,lscomm,magic,0,clopenbuy);

if(usesound)PlaySound(namefilesound);

}

 

void opensell(){

double ldlot,ldstop,ldtake;

string lscomm;

ldlot=getsizelot();

if(sstoploss>0 && hidesl==false)ldstop=getstoplosssell();else ldstop=0;

if(stakeprofit>0 && hidetp==false)ldtake=gettakeprofitsell();else ldtake=0;

lscomm=getcommentfororder();

OrderSend(Symbol(),OP_SELL,ldlot,Bid,slippage*mt,ldstop,ldtake,lscomm,magic,0,clopensell);

if(usesound)PlaySound(namefilesound);

}

 

string getcommentfororder(){return(nameexpert);}

double getsizelot(){return(lots);}

double getstoplossbuy(){return(Ask-lstoploss*pt);}

double getstoplosssell(){return(Bid+sstoploss*pt);}

double gettakeprofitbuy(){return(Ask+ltakeprofit*pt);}

double gettakeprofitsell(){return(Bid-stakeprofit*pt);}

 

void hideclosebuy(){

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

&& (ltakeprofit>0 && OrderProfit()>ltakeprofit*OrderLots()*10) || (lstoploss>0 && OrderProfit()<(-1)*lstoploss*OrderLots()*10-MarketInfo(Symbol(),MODE_SPREAD)*OrderLots()*10/mt)){

OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt);

}

}

}

}

 

void hideclosesell(){

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

&& (stakeprofit>0 && OrderProfit()>stakeprofit*OrderLots()*10) || (sstoploss>0 && OrderProfit()<(-1)*sstoploss*OrderLots()*10-MarketInfo(Symbol(),MODE_SPREAD)*OrderLots()*10/mt)){

OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt);

}

}

}

}

 

 

 

thanks

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...