|
تفضل تعديل فتح الصفقات
[PHP]
//+------------------------------------------------------------------+
//| Stok_scalper_EA.mq4 |
//| Copyright 2013, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern int MagicNumber=1011;
extern double lStopLoss = 100;
extern double sStopLoss = 100;
extern double lTakeProfit = 10;
extern double sTakeProfit = 10;
extern string jj="------";
extern int StopLoss=100;
extern int TakeProfit=10;
extern color clOpenBuy = Blue;
extern color clCloseBuy = Aqua;
extern color clOpenSell = Red;
extern color clCloseSell = Violet;
extern color clModiBuy = Blue;
extern color clModiSell = Red;
extern string Name_Expert = "Stok_scalper EA";
extern int Slippage = 0;
extern bool UseHourTrade = True;
extern int FromHourTrade = 0;
extern int ToHourTrade = 23;
extern bool UseSound = True;
extern string NameFileSound = "alert.wav";
extern double Lots = 2;
int digits,Q;
double point;
int init()
{
if(Digits==5||Digits==3)Q=10;
else Q=1;
if(Digits==2)
{
point=0.01;
digits=2;
}
if(Digits==4)
{
point=0.0001;
digits=4;
}
if(Digits==3)
{
point=0.01;
digits=3;
}
if(Digits==5)
{
point=0.0001;
digits=5;
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int start()
{
if (UseHourTrade){
if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {
Comment("Time for trade has not come else!");
return(0);
} else Comment("");
}else Comment("");
if(Bars<100){
Print("bars less than 100");
return(0);
}
if(lStopLoss<10){
Print("StopLoss less than 10");
return(0);
}
if(lTakeProfit<10){
Print("TakeProfit less than 10");
return(0);
}
if(sStopLoss<10){
Print("StopLoss less than 10");
return(0);
}
if(sTakeProfit<10){
Print("TakeProfit less than 10");
return(0);
}
double diStochastic0=iStochastic(NULL,60,5,3,3,MODE_EMA,P RICE_CLOSE,MODE_MAIN,3);
double d1=(15);
double diStochastic2=iStochastic(NULL,60,5,3,3,MODE_EMA,P RICE_CLOSE,MODE_MAIN,3);
double d3=(85);
if(AccountFreeMargin()<(1000*Lots)){
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (!ExistPositions()){
if ((diStochastic0<d1)){
open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
return(0);
}
if ((diStochastic2>d3)){
open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
return(0);
}
}
return (0);
}
bool ExistPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) {
return(True);
}
}
}
return(false);
}
/*
void ModifyStopLoss(double ldStopLoss) {
bool fm;
fm = OrderModify(OrderTicket(),OrderOpenPrice(),ldStopL oss,OrderTakeProfit(),0,CLR_NONE);
if (fm && UseSound) PlaySound(NameFileSound);
}
*/
void OpenBuy() {
double ldLot, ldStop, ldTake;
string lsComm;
ldLot = GetSizeLot();
ldStop = GetStopLossBuy();
ldTake = GetTakeProfitBuy();
lsComm = GetCommentForOrder();
OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,ldSto p,ldTake,lsComm,MagicNumber,0,clOpenBuy);
if (UseSound) PlaySound(NameFileSound);
}
void OpenSell() {
double ldLot, ldStop, ldTake;
string lsComm;
ldLot = GetSizeLot();
ldStop = GetStopLossSell();
ldTake = GetTakeProfitSell();
lsComm = GetCommentForOrder();
OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,ldSt op,ldTake,lsComm,MagicNumber,0,clOpenSell);
if (UseSound) PlaySound(NameFileSound);
}
string GetCommentForOrder() { return(Name_Expert); }
double GetSizeLot() { return(Lots); }
double GetStopLossBuy() { return (Bid-lStopLoss*Point);}
double GetStopLossSell() { return(Ask+sStopLoss*Point); }
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); }
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }
//+------------------------------------------------------------------+
int open(int ty,double lot,double prc,int pof,int sll)
{
double sl=0,tp=0;
color clr;
bool modi;
string T;double pr;
if(ty==OP_BUY || ty==OP_BUYSTOP || ty==OP_BUYLIMIT)
{
if(sll>0){sl=prc-(sll*point);}else{sl=0;}
if(pof>0){tp=prc+(pof*point);}else{tp=0;}
clr=Green;
T="Ask ";
pr=NormalizeDouble(Ask,Digits);
}
if(ty==OP_SELL || ty==OP_SELLSTOP || ty==OP_SELLLIMIT)
{
if(sll>0){sl=prc+(sll*point);}else{sl=0;}
if(pof>0){tp=prc-(pof*point);}else{tp=0;}
clr=Red;
T="Bid";
pr=NormalizeDouble(Bid,Digits);
}
int tik=OrderSend(Symbol()
,ty
,lot
,NormalizeDouble(prc,Digits)
,10
,0
,0
,""
,MagicNumber
,0
,clr);
string t;
if(ty==OP_BUY)t="BUY";if(ty==OP_SELL)t="SELL";if(t y==OP_BUYSTOP)t="BUY STOP";if(ty==OP_SELLSTOP)t="SELL STOP";if(ty==OP_BUYLIMIT)t="BUY LIMIT";if(ty==OP_SELLLIMIT)t="SELL LIMIT";
if(tik>0)
{
if(tp>0 || sl>0)modi=OrderModify(tik,prc,NormalizeDouble(sl,D igits),NormalizeDouble(tp,Digits),0,CLR_NONE); else modi=true;
if(!modi){Print("Modify Err#= ",GetLastError()," ",Symbol()," ",Period()," Open Price= ",DoubleToStr(prc,Digits)," SL= ",DoubleToStr(sl,Digits)," Tp= ",DoubleToStr(tp,Digits));}
Print("Order Opened successfully " ,"Type ",t," LotSize ",lot," Price ",DoubleToStr(prc,Digits)," TP ",DoubleToStr(tp,Digits)," SL ",DoubleToStr(sl,Digits));
}
else
{
Print("OrderSend failed with error #",GetLastError(), " Type ",t," LotSize= ",lot," ",T,"Now= ",DoubleToStr(pr,Digits)," Price= ",DoubleToStr(prc,Digits)," TP= ",DoubleToStr(tp,Digits)," SL= ",DoubleToStr(sl,Digits)," Spread= ",MarketInfo(Symbol(),MODE_SPREAD));
}
//////
return(tik);
}
[/PHP] |
|