can anybody make some changes my ea?

 

Hi,

at attach you can see my ea about ma.


i want to some changes about time.


i want that ea will work at 05:00 - 15:00 (GMT 0)

and ma type will change exponential


how can i do this?


thanks.


sorry because my english is very bad :(

Files:
hort.mq4  6 kb
 
#property link "http://www.selectfx.net"

extern int MA_Type = 1; // 0=SMA 1=EMA 2=Smoothed 3=Linear Weighted

extern int StartHour=5;
extern int EndHour=15;

extern int kisa=5;
extern int orta=20;
extern int uzun=100;
extern double stoploss=0;
extern double takeprofit=40;
extern double volume=50000;

double mystoploss=0,mytakeprofit=0;
double myprice=0;
double myvolume=0;
int mycmd=0;

int init()
{
return(0);
}

int deinit()
{
return(0);
}

int start()
{
static datetime change=0;
int al_emir_sayisi=0;
int sat_emir_sayisi=0;



if(change==iTime(NULL,0,0)) return (0);
change=iTime(NULL,0,0);

if (Hour() < StartHour) return (0); // Too early

if (Hour() > EndHour) return (0); // Too late


double ort1,ort2,ort3,ort4;
double eskiort1,eskiort2,eskiort3,eskiort4;

// HideTestIndicators(false);

ort1=iMA(NULL,0,kisa,0,MA_Type,PRICE_TYPICAL,0);
ort2=iMA(NULL,0,orta,0,MA_Type,PRICE_TYPICAL,0);
ort3=iMA(NULL,0,uzun,0,MA_Type,PRICE_TYPICAL,0);

eskiort1=iMA(NULL,0,kisa,0,MA_Type,PRICE_TYPICAL,1);
eskiort2=iMA(NULL,0,orta,0,MA_Type,PRICE_TYPICAL,1);
eskiort3=iMA(NULL,0,uzun,0,MA_Type,PRICE_TYPICAL,1);

al_emir_sayisi=BuyOrderCount();
sat_emir_sayisi=SellOrderCount();


if(al_emir_sayisi<1)
{
if((ort3<ort2)&&(ort1>=ort2)&&(eskiort1<=eskiort2))
{
AL();
}
}

if(al_emir_sayisi<1)
{
if((ort3<ort2)&&(eskiort1<=eskiort3)&&(ort1>=ort3))
{
AL();
}
}

if(al_emir_sayisi<1)
{
if((ort3<ort1)&&(eskiort2<=eskiort3)&&(ort2>=ort3))
{
AL();
}
}



if(sat_emir_sayisi<1)
{
if((ort3>ort2)&&(ort1<=ort2)&&(eskiort1>=eskiort2))
{
SAT();
}
}

if(sat_emir_sayisi<1)
{
if((ort3>ort2)&&(eskiort1>=eskiort3)&&(ort1<=ort3))
{
SAT();
}
}
if(sat_emir_sayisi<1)
{
if((ort3>ort1)&&(eskiort2>=eskiort3)&&(ort2<=ort3))
{
SAT();
}
}

if(al_emir_sayisi>0)
{
if(ort1<ort2)
CloseBuy();
}

if(sat_emir_sayisi>0)
{
if(ort1>ort2)
CloseSell();
}

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

void CloseBuy()
{

for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol() == Symbol())
{

if(OrderType()==OP_BUY){
if(OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue))
{
}
else
{
Print("Order Close buy returned the error of ",GetLastError());
}
}//if opbuy
}
}

}


void CloseSell()
{

for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol() == Symbol())
{

if(OrderType()==OP_SELL){
if(OrderClose(OrderTicket(),OrderLots(),Ask,3,Orange))
{
}
else
{
Print("Order Close buy returned the error of ",GetLastError());
}
}//if opsell
}
}

}

int SellOrderCount()
{

int opensellordercount=0;
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_SELL) opensellordercount++;
}
return(opensellordercount);
}

int BuyOrderCount()
{

int openbuyordercount=0;
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY) openbuyordercount++;
}
return(openbuyordercount);
}

void AL()
{


mycmd=OP_BUY;
myprice=Ask;
mytakeprofit=takeprofit*Point+Ask;
myvolume=volume;
if(mystoploss!=0)mystoploss=Bid-stoploss*Point;

if( (OrderSend(Symbol(),mycmd,myvolume,myprice,3,mystoploss,mytakeprofit,"BUY order",1001,0,Green))>0)
{
}
else
{
Alert("OrderSend BUY returned the error of ",GetLastError());
}

return(0);
}

int SAT()
{
mycmd=OP_SELL;
myprice=Bid;
mytakeprofit=Bid-takeprofit*Point;
myvolume=volume;
if(stoploss!=0)mystoploss=Ask+stoploss*Point;

// Print("takeprofit=",mytakeprofit," stoploss=",mystoploss);
if(OrderSend(Symbol(),mycmd,myvolume,myprice,3,mystoploss,mytakeprofit,"Sell Order",1100,0,Red)>0)
{
}
else
{
Alert("OrderSend SELL returned the error of ",GetLastError());
}

return(0);
}
 

hi,

thanks for helping but,

when i test your code i will see that "OrderSend Sell Returned the error of 130"

how can i fix it?


thanks lot

 

1. maybe Print()'s sort out?

wat in: myprice,myvolume,mystoploss,mytakeprofit ?

2. maybe NormalizeDouble(..) need employ?

3. maybe data need RefreshRates()?

.

ERR_INVALID_STOPS 130 Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

.

Best

 

A

As fbj says - add the Print line after the value settings, back-test & look in the Jornal for the printout

mycmd=OP_SELL;
myprice=Bid; 
mytakeprofit=Bid-takeprofit*Point;
myvolume=volume; 
if(stoploss!=0)mystoploss=Ask+stoploss*Point;

// Add this line
Print("myprice: ", myprice, " mytakeprofit: ", mytakeprofit, " myvolume: ", myvolume, " mystoploss: ", mystoploss) 

Good luck

-BB-

Reason: