//+------------------------------------------------------------------+
//| Cost_Average.mq4 |
//| Copyright ?2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
int ProtectOrderMinutes = 5;
int Frame_SR = 0;
int EMA_SR = 250;
string SR_Action = "none";
string SoundText = "none";
string OrderProtected = "no";
double LeftSeconds = 0.0;
int cnt = 0;
int count = 0;
int init()
{
Print("init");
return(0);
}
int deinit()
{
Print("deinit");
return(0);
}
int start()
{
Print("");
double TotalPips = 0.0;
double StopProfitLoss = 0.0;
double TakeProfitLoss = 0.0;
double ProfitLoss = 0.0;
cnt = 0;
count = 0;
int cntBuy = 0;
int cntSell = 0;
int cntUnprotected = 0;
double StopLossNewValueBuy = 0.00;
for(cnt = 0 ; cnt < OrdersTotal() ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
if(OrderType() == 0)
{
TotalPips = TotalPips + (Bid - OrderOpenPrice());
StopProfitLoss = OrderStopLoss() - OrderOpenPrice();
TakeProfitLoss = OrderTakeProfit() - OrderOpenPrice();
ProfitLoss = Bid - OrderOpenPrice();
cntBuy++;
if(OrderStopLoss() == 0.0000 || OrderStopLoss() - OrderOpenPrice() < 0)
{
cntUnprotected++;
}
if(Bid - OrderOpenPrice() > 0.0004 && (TimeCurrent() - OrderOpenTime())/60 > ProtectOrderMinutes && OrderStopLoss() == 0.0000)
{
StopLossNewValueBuy = OrderOpenPrice() + 0.0001;
OrderModify(OrderTicket(),OrderOpenPrice(),StopLossNewValueBuy,OrderTakeProfit(),0,Blue);
OrderProtected = "yes";
}
}
if(OrderType() == 1)
{
TotalPips = TotalPips + (OrderOpenPrice() - Ask);
StopProfitLoss = OrderOpenPrice() - OrderStopLoss();
TakeProfitLoss = OrderOpenPrice() - OrderTakeProfit();
ProfitLoss = OrderOpenPrice() - Ask;
cntSell++;
if(OrderStopLoss() == 0.0000 || OrderOpenPrice() - OrderStopLoss() < 0)
{
cntUnprotected++;
}
if(OrderOpenPrice() - Ask > 0.0004 && (TimeCurrent() - OrderOpenTime())/60 > ProtectOrderMinutes && OrderStopLoss() == 0.0000)
{
StopLossNewValueBuy = OrderOpenPrice() - 0.0001;
OrderModify(OrderTicket(),OrderOpenPrice(),StopLossNewValueBuy,OrderTakeProfit(),0,Blue);
OrderProtected = "yes";
}
}
if(OrdersTotal() - cnt < 2)
{
LeftSeconds = TimeCurrent() - OrderOpenTime();
}
//Print("OT = ", OrderTicket(), " ", TimeToStr(OrderOpenTime()), " TY = ", OrderType(), " LT = ", OrderLots(), " OP = ", OrderOpenPrice(), " SP = ", StopProfitLoss, " PL = ", ProfitLoss);
count++;
} // end for loop
Print("Frame = ", Frame_SR, " EMA = ", EMA_SR);
double EMA_SR_150_Value = iMA(NULL,Frame_SR,150,0,1,0,0);
double EMA_SR_250_Value = iMA(NULL,Frame_SR,250,0,1,0,0);
double EMA_SR_Value = iMA(NULL,Frame_SR,EMA_SR,0,1,0,0);
double RSI_SR = iRSI(NULL,Frame_SR,14,PRICE_CLOSE,0);
double STO_SR = iStochastic(0,Frame_SR,5,3,3,MODE_SMA,0,MODE_MAIN,0);
double WIL_SR = iWPR(NULL,0,14,0);
if(OrderProtected == "yes")
{
SoundText = "Order Protected";
OrderProtected = "no";
PlaySound("Love_of_Siam_Gun_lae_gun.wav");
}else{
if(EMA_SR_150_Value > EMA_SR_250_Value)
{
SoundText = "Up Trend " + DoubleToStr(Bid - EMA_SR_Value,4);
if(RSI_SR > 70 || STO_SR > 80 || WIL_SR > -20)
{
SoundText = "Over Bought";
PlaySound("bugsbunny2.wav");
}else{
if(RSI_SR < 30 || STO_SR < 20 || WIL_SR < -80)
{
SoundText = "Start Buy";
PlaySound("stops.wav");
}else{
if(Bid - EMA_SR_Value > 0.00)
{
PlaySound("expert.wav");
}else{
PlaySound("ok.wav");
}
}
}
}else{
SoundText = "Down Trend " + DoubleToStr(Bid - EMA_SR_Value,4);
if(RSI_SR > 70 || STO_SR > 80 || WIL_SR > -20)
{
SoundText = "Start Sell";
PlaySound("news.wav");
}else{
if(RSI_SR < 30 || STO_SR < 20 || WIL_SR < -80)
{
SoundText = "Over Sold";
PlaySound("daffyduck2.wav");
}else{
if(Bid - EMA_SR_Value > 0.00)
{
PlaySound("alert.wav");
}else{
PlaySound("tick.wav");
}
}
}
}
}
double SpreadDiffrence = Bid - Ask;
if(EMA_SR_150_Value > EMA_SR_250_Value){
SR_Action = "BUY";
}else{
SR_Action = "SELL";
}
Print("Spread = ", DoubleToStr(SpreadDiffrence,4), " TotalOrders = ", OrdersTotal(), " Buy = ", cntBuy, " Sell = ", cntSell, " Unprotected = ", cntUnprotected, " TotalPips = ", DoubleToStr(TotalPips,4), " ***");
//Comment(RSI_SR, " ", STO_SR, " ", WIL_SR);
Comment("PM = ", ProtectOrderMinutes, " UP = ", cntUnprotected, " LS = ", DoubleToStr(LeftSeconds/60,2), " TREND = ", SR_Action, " Status = ", SoundText);
return(0);
} |