bucho1504
18-11-2010, 19:10
Witam
Mam pytanie co jest źle w tym EA że jak próbuję wykonać back test to nic mi nie wyświetla :(
int TakeProfit_L = 39; // Take Profit in points
int StopLoss_L = 147; // Stop Loss in points
int TakeProfit_S = 32; // Take Profit in points
int StopLoss_S = 267; // Stop Loss in points
int TradeTime=18; // Time to enter the market
int t1=6;
int t2=2;
int delta_L=6;
int delta_S=21;
extern double lot = 0.1; // Lot size
int Orders=50; // maximal number of positions opened at a time
int MaxOpenTime=504;
int BigLotSize = 2; // By how much lot size is multiplicated in Big lot
extern bool AutoLot=true;
int ticket,total,cnt;
bool cantrade=true;
double closeprice;
double tmp;
int LotSize()
// The function opens a short position with lot size=volume
{
if (AccountBalance()>=2700) lot=0.10;
if (AccountBalance()>=3000) lot=0.11;
if (AccountBalance()>=3300) lot=0.12;
if (AccountBalance()>=3500) lot=0.13;
if (AccountBalance()>=3785) lot=0.14;
if (AccountBalance()>=4058) lot=0.15;
if (AccountBalance()>=4332) lot=0.16;
if (AccountBalance()>=4605) lot=0.17;
if (AccountBalance()>=4879) lot=0.18;
if (AccountBalance()>=5153) lot=0.19;
if (AccountBalance()>=5626) lot=0.20;
if (AccountBalance()>=5700) lot=0.21;
if (AccountBalance()>=5974) lot=0.22;
if (AccountBalance()>=6247) lot=0.23;
if (AccountBalance()>=6521) lot=0.24;
if (AccountBalance()>=6795) lot=0.25;
if (AccountBalance()>=7068) lot=0.26;
if (AccountBalance()>=7342) lot=0.27;
if (AccountBalance()>=7615) lot=0.28;
if (AccountBalance()>=7889) lot=0.29;
if (AccountBalance()>=8163) lot=0.30;
if (AccountBalance()>=8436) lot=0.31;
if (AccountBalance()>=8710) lot=0.32;
if (AccountBalance()>=8984) lot=0.33;
if (AccountBalance()>=9257) lot=0.34;
if (AccountBalance()>=9531) lot=0.35;
if (AccountBalance()>=9804) lot=0.36;
if (AccountBalance()>=10078) lot=0.37;
}
int globPos()
// the function calculates big lot size
{
int v1=GlobalVariableGet("globalPosic");
GlobalVariableSet("globalPosic",v1+1);
return(0);
}
int OpenLong(double volume=0.1)
// the function opens a long position with lot size=volume
{
int slippage=0;
string comment="(Long)";
color arrow_color=Red;
int magic=0;
if (GlobalVariableGet("globalBalans")>AccountBalance()) volume=lot*BigLotSize;
// if (GlobalVariableGet("globalBalans")>AccountBalance()) if (AutoLot) LotSize();
ticket=OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,Ask-StopLoss_L*Point,
Ask+TakeProfit_L*Point,comment,magic,0,arrow_color);
GlobalVariableSet("globalBalans",AccountBalance());
globPos();
// if (GlobalVariableGet("globalPosic")>25)
// {
GlobalVariableSet("globalPosic",0);
if (AutoLot) LotSize();
// }
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
return(0);
}
else
{
Print("OpenLong(),OrderSelect() - returned an error : ",GetLastError());
return(-1);
}
}
else
{
Print("Error opening Buy order : ",GetLastError());
return(-1);
}
}
int OpenShort(double volume=0.1)
// The function opens a short position with lot size=volume
{
int slippage=0;
string comment="(Short)";
color arrow_color=Red;
int magic=0;
if (GlobalVariableGet("globalBalans")>AccountBalance()) volume=lot*BigLotSize;
ticket=OrderSend(Symbol(),OP_SELL,volume,Bid,slippage,Bid+StopLoss_S*Point,
Bid-TakeProfit_S*Point,comment,magic,0,arrow_color);
GlobalVariableSet("globalBalans",AccountBalance());
globPos();
// if (GlobalVariableGet("globalPosic")>25)
// {
GlobalVariableSet("globalPosic",0);
if (AutoLot) LotSize();
// }
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
return(0);
}
else
{
Print("OpenShort(),OrderSelect() - returned an error : ",GetLastError());
return(-1);
}
}
else
{
Print("Error opening Sell order : ",GetLastError());
return(-1);
}
}
int init()
{
// control of a variable before using
if (AutoLot) LotSize();
if(!GlobalVariableCheck("globalBalans"))
GlobalVariableSet("globalBalans",AccountBalance());
if(!GlobalVariableCheck("globalPosic"))
GlobalVariableSet("globalPosic",0);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
if((TimeHour(TimeCurrent())>TradeTime)) cantrade=true;
// check if there are open orders ...
total=OrdersTotal();
if(total<Orders)
{
// ... if no open orders, go further
// check if it's time for trade
if((TimeHour(TimeCurrent())==TradeTime)&&(cantrade))
{
// ... if it is
if (((Open[t1]-Open[t2])>delta_S*Point)) //if it is
{
//condition is fulfilled, enter a short position:
// check if there is free money for opening a short position
if(AccountFreeMarginCheck(Symbol(),OP_SELL,lot)<=0 || GetLastError()==134)
{
Print("Not enough money");
return(0);
}
OpenShort(lot);
cantrade=false; //prohibit repeated trade until the next bar
return(0);
}
if (((Open[t2]-Open[t1])>delta_L*Point)) //if the price increased by delta
{
// condition is fulfilled, enter a long position
// check if there is free money
if(AccountFreeMarginCheck(Symbol(),OP_BUY,lot)<=0 || GetLastError()==134)
{
Print("Not enough money");
return(0);
}
OpenLong(lot);
cantrade=false;
return(0);
}
}
}
// block of a trade validity time checking, if MaxOpenTime=0, do not check.
if(MaxOpenTime>0)
{
for(cnt=0;cnt<total;cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
tmp = (TimeCurrent()-OrderOpenTime())/3600.0;
if (((NormalizeDouble(tmp,8)-MaxOpenTime)>=0))
{
RefreshRates();
if (OrderType()==OP_BUY)
closeprice=Bid;
else
closeprice=Ask;
if (OrderClose(OrderTicket(),OrderLots(),closeprice,10,Green))
{
Print("Forced closing of the trade - ą",OrderTicket());
OrderPrint();
}
else
Print("OrderClose() in block of a trade validity time checking returned an error - ",GetLastError());
}
}
else
Print("OrderSelect() in block of a trade validity time checking returned an error - ",GetLastError());
}
}
return(0);
}
Mam pytanie co jest źle w tym EA że jak próbuję wykonać back test to nic mi nie wyświetla :(
int TakeProfit_L = 39; // Take Profit in points
int StopLoss_L = 147; // Stop Loss in points
int TakeProfit_S = 32; // Take Profit in points
int StopLoss_S = 267; // Stop Loss in points
int TradeTime=18; // Time to enter the market
int t1=6;
int t2=2;
int delta_L=6;
int delta_S=21;
extern double lot = 0.1; // Lot size
int Orders=50; // maximal number of positions opened at a time
int MaxOpenTime=504;
int BigLotSize = 2; // By how much lot size is multiplicated in Big lot
extern bool AutoLot=true;
int ticket,total,cnt;
bool cantrade=true;
double closeprice;
double tmp;
int LotSize()
// The function opens a short position with lot size=volume
{
if (AccountBalance()>=2700) lot=0.10;
if (AccountBalance()>=3000) lot=0.11;
if (AccountBalance()>=3300) lot=0.12;
if (AccountBalance()>=3500) lot=0.13;
if (AccountBalance()>=3785) lot=0.14;
if (AccountBalance()>=4058) lot=0.15;
if (AccountBalance()>=4332) lot=0.16;
if (AccountBalance()>=4605) lot=0.17;
if (AccountBalance()>=4879) lot=0.18;
if (AccountBalance()>=5153) lot=0.19;
if (AccountBalance()>=5626) lot=0.20;
if (AccountBalance()>=5700) lot=0.21;
if (AccountBalance()>=5974) lot=0.22;
if (AccountBalance()>=6247) lot=0.23;
if (AccountBalance()>=6521) lot=0.24;
if (AccountBalance()>=6795) lot=0.25;
if (AccountBalance()>=7068) lot=0.26;
if (AccountBalance()>=7342) lot=0.27;
if (AccountBalance()>=7615) lot=0.28;
if (AccountBalance()>=7889) lot=0.29;
if (AccountBalance()>=8163) lot=0.30;
if (AccountBalance()>=8436) lot=0.31;
if (AccountBalance()>=8710) lot=0.32;
if (AccountBalance()>=8984) lot=0.33;
if (AccountBalance()>=9257) lot=0.34;
if (AccountBalance()>=9531) lot=0.35;
if (AccountBalance()>=9804) lot=0.36;
if (AccountBalance()>=10078) lot=0.37;
}
int globPos()
// the function calculates big lot size
{
int v1=GlobalVariableGet("globalPosic");
GlobalVariableSet("globalPosic",v1+1);
return(0);
}
int OpenLong(double volume=0.1)
// the function opens a long position with lot size=volume
{
int slippage=0;
string comment="(Long)";
color arrow_color=Red;
int magic=0;
if (GlobalVariableGet("globalBalans")>AccountBalance()) volume=lot*BigLotSize;
// if (GlobalVariableGet("globalBalans")>AccountBalance()) if (AutoLot) LotSize();
ticket=OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,Ask-StopLoss_L*Point,
Ask+TakeProfit_L*Point,comment,magic,0,arrow_color);
GlobalVariableSet("globalBalans",AccountBalance());
globPos();
// if (GlobalVariableGet("globalPosic")>25)
// {
GlobalVariableSet("globalPosic",0);
if (AutoLot) LotSize();
// }
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
return(0);
}
else
{
Print("OpenLong(),OrderSelect() - returned an error : ",GetLastError());
return(-1);
}
}
else
{
Print("Error opening Buy order : ",GetLastError());
return(-1);
}
}
int OpenShort(double volume=0.1)
// The function opens a short position with lot size=volume
{
int slippage=0;
string comment="(Short)";
color arrow_color=Red;
int magic=0;
if (GlobalVariableGet("globalBalans")>AccountBalance()) volume=lot*BigLotSize;
ticket=OrderSend(Symbol(),OP_SELL,volume,Bid,slippage,Bid+StopLoss_S*Point,
Bid-TakeProfit_S*Point,comment,magic,0,arrow_color);
GlobalVariableSet("globalBalans",AccountBalance());
globPos();
// if (GlobalVariableGet("globalPosic")>25)
// {
GlobalVariableSet("globalPosic",0);
if (AutoLot) LotSize();
// }
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
return(0);
}
else
{
Print("OpenShort(),OrderSelect() - returned an error : ",GetLastError());
return(-1);
}
}
else
{
Print("Error opening Sell order : ",GetLastError());
return(-1);
}
}
int init()
{
// control of a variable before using
if (AutoLot) LotSize();
if(!GlobalVariableCheck("globalBalans"))
GlobalVariableSet("globalBalans",AccountBalance());
if(!GlobalVariableCheck("globalPosic"))
GlobalVariableSet("globalPosic",0);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
if((TimeHour(TimeCurrent())>TradeTime)) cantrade=true;
// check if there are open orders ...
total=OrdersTotal();
if(total<Orders)
{
// ... if no open orders, go further
// check if it's time for trade
if((TimeHour(TimeCurrent())==TradeTime)&&(cantrade))
{
// ... if it is
if (((Open[t1]-Open[t2])>delta_S*Point)) //if it is
{
//condition is fulfilled, enter a short position:
// check if there is free money for opening a short position
if(AccountFreeMarginCheck(Symbol(),OP_SELL,lot)<=0 || GetLastError()==134)
{
Print("Not enough money");
return(0);
}
OpenShort(lot);
cantrade=false; //prohibit repeated trade until the next bar
return(0);
}
if (((Open[t2]-Open[t1])>delta_L*Point)) //if the price increased by delta
{
// condition is fulfilled, enter a long position
// check if there is free money
if(AccountFreeMarginCheck(Symbol(),OP_BUY,lot)<=0 || GetLastError()==134)
{
Print("Not enough money");
return(0);
}
OpenLong(lot);
cantrade=false;
return(0);
}
}
}
// block of a trade validity time checking, if MaxOpenTime=0, do not check.
if(MaxOpenTime>0)
{
for(cnt=0;cnt<total;cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
tmp = (TimeCurrent()-OrderOpenTime())/3600.0;
if (((NormalizeDouble(tmp,8)-MaxOpenTime)>=0))
{
RefreshRates();
if (OrderType()==OP_BUY)
closeprice=Bid;
else
closeprice=Ask;
if (OrderClose(OrderTicket(),OrderLots(),closeprice,10,Green))
{
Print("Forced closing of the trade - ą",OrderTicket());
OrderPrint();
}
else
Print("OrderClose() in block of a trade validity time checking returned an error - ",GetLastError());
}
}
else
Print("OrderSelect() in block of a trade validity time checking returned an error - ",GetLastError());
}
}
return(0);
}