Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
Wednesday_v7
#property copyright "NutCracker"
#property link "forex-way@yandex.ru"
#property link "http://wellforex.ru"
//---- input parameters
extern double Lots=0.1;
extern int K=20;
extern int D=24;
extern int S=35;
extern double Stop_Loss=400;
extern double Take_Profit=750;
extern double TS=900;
extern double L_open=21;
extern double EndTime=19;
#define MAGICMA 20050610
double SMain_current_M15; double SMain_past_M15, MA_cur, MA_past;
double SS_current_M15, SS_past_M15, Axel;
double Trend_M15;
double TrailingStop;
double Delta_M15, Bar_Low_1, Bar_Hi_1, Bar_Low_M, Bar_Hi_M, Bar_Low_N, Bar_Hi_N,PriceUp, PriceDown, Bar_Open, Bar_Close;
double Lev_Delta_Bay_Open_M15; double Lev_Delta_Sell_Open_M15;
double Lev_Delta_Bay_Close_M15; double Lev_Delta_Sell_Close_M15;
double Axel_lavel_Bay; double Axel_lavel_Sell; double Axel_M15;
double Bay_Lavel; double Sell_Lavel;
bool BuyOk, SellOk, BuyOk_N, SellOk_N;
int MODE_AV;
int Price_f; int Slaw; int Flag_Bay; int Flag_Sell;
int res, cnt; int Slippage=6; int MaxTries=5, mode=0;
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
void CloseOrdbyTime()
{
bool result;
int total=OrdersTotal();
for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
mode=OrderType();
if (mode==OP_BUY )
{
for (int try=1;try<=MaxTries;try++)
{
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
result=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);
Sleep(2000);
if (result) break;
}
}
if (mode==OP_SELL)
{
for (int tryy=1;tryy<=MaxTries;tryy++)
{
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
result=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);
Sleep(2000);
if (result) break;
}
}
}
}
void CheckForOpen()
{
if(Volume[0]>1) return;
SMain_current_M15=iStochastic(NULL,PERIOD_M15,K,D,S,MODE_AV,Price_f,MODE_MAIN,1);
SS_current_M15=iStochastic(NULL,PERIOD_M15,K,D,S,MODE_AV,Price_f,MODE_SIGNAL,1);
SMain_past_M15=iStochastic(NULL,PERIOD_M15,K,D,S,MODE_AV,Price_f,MODE_MAIN,2);
if (SMain_current_M15>L_open && SMain_past_M15<L_open)
{
for (int try=1;try<=MaxTries;try++)
{
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Stop_Loss*Point,Ask+Take_Profit*Point,"",MAGICMA,0,Blue);
Sleep(2000);
if(res>0)
{
if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY ïî öåíå : ",OrderOpenPrice());
break;
}
else
{
Print("Error opening BUY order : ",GetLastError());
}
}
}
if (SMain_current_M15<100-L_open && SMain_past_M15>100-L_open)
{
for (int tryy=1;tryy<=MaxTries;tryy++)
{
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Stop_Loss*Point,Bid-Take_Profit*Point,"",MAGICMA,0,Red);
Sleep(2000);
if(res>0)
{
if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL ïî öåíå : ",OrderOpenPrice());
break;
}
else
{
Print("Error opening BUY order : ",GetLastError());
}
}
}
return;
}
void TrailStops()
{
int total=OrdersTotal();
bool result;
for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
mode=OrderType();
if ( OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if ( mode==OP_BUY )
{
if(Bid-OrderOpenPrice()>Point*TS)
{
if(OrderStopLoss()<OrderOpenPrice())
{
for (int try=1;try<=MaxTries;try++)
{
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
result= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
Sleep(2000);
if (result) break;
}
}
}
}
if ( mode==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(Point*TS))
{
if((OrderStopLoss()>OrderOpenPrice()) || (OrderStopLoss()==0))
{
for (int tryy=1;tryy<=MaxTries;tryy++)
{
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
result= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
Sleep(2000);
if (result) break;
}
}
}
}
}
}
}
int start()
{
MODE_AV=MODE_EMA;
Price_f=1;
TrailingStop=TS;
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrders(Symbol())==0)
{
if (DayOfWeek()==3 && Hour()<EndTime) CheckForOpen();
}
else
if ( Hour()>=EndTime && Hour()<EndTime+1 )
{ CloseOrdbyTime(); }
TrailStops();
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---