Orders Execution
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
VilkaChuwashowajStoch
//+------------------------------------------------------------------+
//| VilkaChuwashowa.mq4 |
//| Rodion |
//| |
//+------------------------------------------------------------------+
#property copyright "Rodion"
#property link ""
#property indicator_buffers 3
extern bool Alarmset=true;
extern double Lot=0.1;
extern int StopLoss = 0;
extern int TakeProfit = 0;
int MG;
extern string Ind_Coment1= "--- Âíåøíèå ïàðàìåòðû èíäèêàòîðà ---";
extern bool ShowFractals = true; // Âêë/âûêë çíà÷êîâ ôðàêòàëîâ
extern bool OnAlert = false; // Âêë/âûêë ñèãíàëà
extern bool OnPrint = false; // Âêë/âûêë âûâîä ñèãíàëà â æóðíàëå ýêñïåðòà
extern int nVilka.Upper = 1; // Êîëè÷åñòâî âûâîäèìûõ âîñõîäÿùèõ "âèëîê"
extern int nVilka.Lower = 1; // Êîëè÷åñòâî âûâîäèìûõ íèñõîäÿùèõ "âèëîê"
extern color Color.LineUpper = Red; // Öâåò âîñõîäÿùèõ "âèëîê"
extern color Color.LineLower = Blue; // Öâåò íèñõîäÿùèõ "âèëîê"
extern int Width.LineUpper = 2; // Øèðèíà âîñõîäÿùèõ "âèëîê"
extern int Width.LineLower = 2; // Øèðèíà íèñõîäÿùèõ "âèëîê"
extern string Ind_Coment2= "--- Ïàðàìåòðû îòîáðàæåíèÿ îðäåðîâ ---";
extern bool ShowOrders = true; // Âêë/âûêë îòîáðàæåíèÿ îðäåðîâ
extern bool OnAlert.Orders = true; // Âêë/âûêë ñèãíàëà
extern color Color.OrderBuy = Blue; // Öâåò îðäåðîâ íà ïîêóïêó
extern color Color.OrderSell = Green; // Öâåò îðäåðîâ íà ïðîäàæó
extern int Width.OrderBuy = 2; // Øèðèíà îðäåðîâ íà ïîêóïêó
extern int Width.OrderSell = 2; // Øèðèíà îðäåðîâ íà ïðîäàæó
extern color Color.SLBuy = Red; // Öâåò ñòîïëîññà íà ïîêóïêó
extern color Color.SLSell = Red; // Öâåò ñòîïëîññà íà ïðîäàæó
extern int Orders.FontSize = 12; // Ðàçìåð øðèôòà îðäåðîâ
extern string Ind_Coment3= "--- Ïàðàìåòðû E-mail ñîîáùåíèé ---";
extern bool SendEnter = false; // ñèãíàëû Buy, Sell
extern bool SendLoss = false; // ñèãíàëû StopLoss
//+---------------------------------------------------------------------------+
// ãëîáàëüíûå ïåðåìåííûå
int nLine.Upper = 0, // Êîëè÷åñòâî òðåíäîâûõ ëèíèé, íàïðàâëåííûõ ââåðõ
nLine.Lower = 0, // Êîëè÷åñòâî òðåíäîâûõ ëèíèé, íàïðàâëåííûõ âíèç
nBars = 0; //
datetime mLineUpper.DateTime[][2]; // ìàññèâ ñ ïàðàìåòðàìè âîñõîäÿùèõ "âèëîê"
// mLineUpper.DateTime[i][0] // Âðåìÿ ïåðâîé êîîðäèíàòû
// mLineUpper.DateTime[i][1] // Âðåìÿ âòîðîé êîîðäèíàòû
double mLineUpper.Price[][2]; // ìàññèâ ñ ïàðàìåòðàìè âîñõîäÿùèõ "âèëîê"
// mLineUpper.Price[i][0] // Öåíà ïåðâîé êîîðäèíàòû
// mLineUpper.Price[i][1] // Öåíà âòîðîé êîîðäèíàòû
datetime mLineLower.DateTime[][2]; // ìàññèâ ñ ïàðàìåòðàìè íèñõîäÿùèõ "âèëîê"
// mLineLower.DateTime[i][0] // Âðåìÿ ïåðâîé êîîðäèíàòû
// mLineLower.DateTime[i][1] // Âðåìÿ âòîðîé êîîðäèíàòû
double mLineLower.Price[][2]; // ìàññèâ ñ ïàðàìåòðàìè íèñõîäÿùèõ "âèëîê"
// mLineLower.Price[i][0] // Öåíà ïåðâîé êîîðäèíàòû
// mLineLower.Price[i][1] // Öåíà âòîðîé êîîðäèíàòû
string mOrders[2][5]; // ìàññèâ ñ ïàðàìåòðàìè "îòêðûòûõ" ïîçèöèé
// mOrders[0][0] // Buy - 0-íåò îðäåðà, 10-åñòü îðäåð
// mOrders[1][0] // Sell- 0-íåò îðäåðà, 20-åñòü îðäåð
// mOrders[i][1] // Äàòà è âðåìÿ "îòêðûòèÿ" îðäåðà
// mOrders[i][2] // Öåíà îðäåðà îðäåðà
// mOrders[i][3] // Ñòîïëîññ îðäåðà îðäåðà
// mOrders[i][4] // 0-ñòîïëîññ ÍÅ ñðàáîòàë, 1-ñòîïëîññ ñðàáîòàë
string NameLine.Buy=""; // èìÿ ñèãíàëüíîé òðåíäîâîé ëèíèè äëÿ ïîêóïêè
string NameLine.Sell=""; // èìÿ ñèãíàëüíîé òðåíäîâîé ëèíèè äëÿ ïðîäàæè
//----- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+---------------------------------------------------------------------------+
int init()
{
MG=StringGetChar(Symbol(),0)+StringGetChar(Symbol(),3)+231;
int Qnt=ObjectsTotal();
// ----- Indicators Properties
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,218);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
// ----- Name for DataWindow and indicator subwindow label
IndicatorShortName("Fractals");
SetIndexLabel(0,"FractalsUp");
SetIndexLabel(1,"FractalsDown");
// ----- óñòàíàâëèâàåì êîëè÷åñòâî ýëåìåíòîâ â ìàññèâàõ òðåíäîâûõ ëèíèé
ArrayResize(mLineUpper.DateTime,nVilka.Upper*2); ArrayResize(mLineUpper.Price,nVilka.Upper*2);
ArrayResize(mLineLower.DateTime,nVilka.Lower*2); ArrayResize(mLineLower.Price,nVilka.Lower*2);
// ----- îïðåäåëÿåìñÿ ñ èìåíàìè ñèãíàëüíûõ òðåíäîâûõ ëèíèé
if (nVilka.Lower==1) NameLine.Buy ="Line.Lower1";
if (nVilka.Lower>1) NameLine.Buy ="Line.Lower"+DoubleToStr(nVilka.Lower*2-1,0);
if (nVilka.Upper==1) NameLine.Sell="Line.Upper1";
if (nVilka.Upper>1) NameLine.Sell="Line.Upper"+DoubleToStr(nVilka.Upper*2-1,0);
return;
}
//+---------------------------------------------------------------------------+
void deinit() { // Custom indicator deinitialization function
int Qnt=ObjectsTotal();
// ----- Óäàëÿåì òðåíäîâûå ëèíèè
for (int i=0; i<Qnt; i++) { // Öèêë ïî îáúåêòàì
if(StringFind(ObjectName(i),"Line.Upper",0)>=0) {
ObjectDelete(ObjectName(i)); // íàïðàâëåííûå ââåðõ
i--; continue;
}
if(StringFind(ObjectName(i),"Line.Lower",0)>=0) {
ObjectDelete(ObjectName(i)); // íàïðàâëåííûå âíèç
i--; continue;
}
if(i>=ObjectsTotal()) break;
}
DeleteOrders(10); DeleteOrders(20);
return;
}
///+------------------------------------------------------------------+
void start() { // Custom indicator iteration function
double s=iStochastic(NULL,10,14,3,3,MODE_EMA,0,MODE_MAIN,1);
int counted_bars=IndicatorCounted();
int limit;
int Spred=MarketInfo(Symbol(),MODE_SPREAD);
// ----- Ïðîâåðêà âíåøíèõ ïàðàìåòðîâ èíäèêàòîðà
if(!CheckParameters()) return;
// ----- íîâûé áàð íå ïîÿâèëñÿ
if(!isNewBar()) return;
// ----- Ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
// ----- Îñíîâíîé öèêë
//for (int i=limit; i>2; i--) {
for (int i=limit; i>=0; i--)
{
if(ShowFractals)
{ // îòîáðàæàåì âðàêòàëû íà ãðàôèêå
ExtMapBuffer1[i]=iFractals(NULL,0,MODE_UPPER,i)+Spred*Point;
ExtMapBuffer2[i]=iFractals(NULL,0,MODE_LOWER,i)-Spred*Point;
}
//---- Áëîê Upper-ôðàêòàëîâ (íèñõîäÿùèå "âèëêè")
if (iFractals(NULL,0,MODE_UPPER,i)!=0) {
if(LowerVilka(i)) {
if(i==0) {
if(OnAlert) Alert(Symbol(),Period()," Íèñõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
if(OnPrint) Print(Symbol(),Period()," Íèñõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
}
}
}
//---- Áëîê Lower-ôðàêòàëîâ (âîñõîäÿùèå "âèëêè")
if (iFractals(NULL,0,MODE_LOWER,i)!=0) {
if(UpperVilka(i)) {
if(i==0) {
if(OnAlert) Alert(Symbol(),Period()," Âîñõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
if(OnPrint) Print(Symbol(),Period()," Âîñõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
}
}
}
//----- ïåðåñå÷åíèå íèñõîäÿùåé "âèëêè" - ñèãíàë íà ïîêóïêó
if((StrToDouble(mOrders[0][0])==0 || (StrToDouble(mOrders[0][0])==10 && StrToDouble(mOrders[0][4])==1)) &&
(Close[i+1]>ObjectGetValueByShift(NameLine.Buy,i+1) || Open[i]>ObjectGetValueByShift(NameLine.Buy,i))) {
if(DrawOrdersBuy(i))
{
if(OnAlert.Orders)
{
if(i==0 && colOrders(OP_BUY) == 0 && s < 80)
{
Alert(Symbol(),Period(),": Ñèãíàë íà ïîêóïêó! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
OrderCl(OP_SELL);
OrderOp(OP_BUY, Symbol(), TakeProfit, StopLoss, Lot);
}
}
if(SendEnter)
{
if(i==0)
{
SendMailSignals(i, 10);
}
}
}
}
//----- ïåðåñå÷åíèå ñòîïëîññà îðäåðà íà ïîêóïêó
if(StrToDouble(mOrders[0][0])==10 && StrToDouble(mOrders[0][4])==0 &&
(StrToDouble(mOrders[0][3])>=Low[i+1] || StrToDouble(mOrders[0][3])>=Open[i])) {
// ----- óñòàíàâëèâàåì ôëàã ñðàáàòûâàíèÿ ñòîïëîññà
mOrders[0][4]=1;
// -----
if(OnAlert.Orders)
{
if(i==0)
{
Alert(Symbol(),Period(),": Ñðàáîòàë ñòîïëîññ äëÿ îðåäðà Buy! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
}
}
if(SendLoss)
{
if(i==0)
{
SendMailSignals(i, 11);
}
}
}
//----- ïåðåñå÷åíèå âîñõîäÿùåé "âèëêè" - ñèãíàë íà ïðîäàæó
if((StrToDouble(mOrders[1][0])==0 || (StrToDouble(mOrders[1][0])==20 && StrToDouble(mOrders[1][4])==1)) &&
(Close[i+1]<ObjectGetValueByShift(NameLine.Sell,i+1) || Open[i]<ObjectGetValueByShift(NameLine.Sell,i))) {
if(DrawOrdersSell(i)) {
if(OnAlert.Orders) {
if(i==0 && colOrders(OP_SELL)==0 && s > 20)
{
Alert(Symbol(),Period(),": Ñèãíàë íà ïðîäàæó! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
OrderCl(OP_BUY);
OrderOp(OP_SELL, Symbol(), TakeProfit, StopLoss, Lot);
}
}
if(SendEnter)
{
if(i==0)
{
SendMailSignals(i, 20);
}
}
}
}
//----- ïåðåñå÷åíèå ñòîïëîññà îðäåðà íà ïðîäàæó
if(StrToDouble(mOrders[1][0])==20 && StrToDouble(mOrders[1][4])==0 &&
(StrToDouble(mOrders[1][3])<=High[i+1] || StrToDouble(mOrders[1][3])<=Open[i])) {
// ----- óñòàíàâëèâàåì ôëàã ñðàáàòûâàíèÿ ñòîïëîññà
mOrders[1][4]=1;
// -----
if(OnAlert.Orders) {
if(i==0) {
Alert(Symbol(),Period(),": Ñðàáîòàë ñòîïëîññ äëÿ îðåäðà Sell! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
}
}
if(SendLoss) {
if(i==0) {
SendMailSignals(i, 21);
}
}
}
}
return;
}
//+------------------------------------------------------------------+
//+---------------------------------------------------------------------------+
bool UpperVilka(int nBar) { // Ôóíêöèÿ îïðåäåëÿåò è ðèñóåò âîñõîäÿùèå "âèëêè"
int j=0;
double Fractal.Lower=0;
double mFractals.Price[3];
datetime mFractals.DateTime[3];
// ----- çàïîëíÿåì ìàññèâû èíôîðìàöèåé î ïîñëåäíèõ òðåõ ôðàêòàëàõ
ArrayInitialize(mFractals.Price,0); ArrayInitialize(mFractals.DateTime,0);
for (int i=nBar; i<Bars; i++) { // Öèêë ïî áàðàì
Fractal.Lower=iFractals(NULL,0,MODE_LOWER,i);
if(Fractal.Lower!=0) {
mFractals.Price[j]=Fractal.Lower-MarketInfo(Symbol(),MODE_SPREAD)*Point;
mFractals.DateTime[j]=Time[i];
j++;
}
if(j>2) break;
}
// ----- ðèñóåì âîñõîäÿùóþ "âèëêó"
if(mFractals.Price[2]<mFractals.Price[1] && mFractals.Price[1]<mFractals.Price[0]) {
string Name1="Line.Upper"+DoubleToStr(nLine.Upper,0); nLine.Upper++;
string Name2="Line.Upper"+DoubleToStr(nLine.Upper,0); nLine.Upper++;
ObjectCreate(Name1,OBJ_TREND,0,mFractals.DateTime[2],mFractals.Price[2],mFractals.DateTime[1],mFractals.Price[1]);
ObjectCreate(Name2,OBJ_TREND,0,mFractals.DateTime[1],mFractals.Price[1],mFractals.DateTime[0],mFractals.Price[0]);
if (ObjectGetValueByShift(Name1,nBar)<ObjectGetValueByShift(Name2,nBar)) {
ObjectDelete(Name1); ObjectDelete(Name2); nLine.Upper--; nLine.Upper--; return(false);
}
ObjectSet(Name1,OBJPROP_COLOR,Color.LineUpper); ObjectSet(Name2,OBJPROP_COLOR,Color.LineUpper);
ObjectSet(Name1,OBJPROP_WIDTH,Width.LineUpper); ObjectSet(Name2,OBJPROP_WIDTH,Width.LineUpper);
ObjectSet(Name1,OBJPROP_RAY,True); ObjectSet(Name2,OBJPROP_RAY,True);
CheckNumVilka(10);
// ----- óäàëÿåì ïðåäûäóùèé îðäåð íà ïðîäàæó
DeleteOrders(20);
return(true);
}
return(false);
}
//+---------------------------------------------------------------------------+
bool LowerVilka(int nBar) { // Ôóíêöèÿ îïðåäåëÿåò è ðèñóåò íèñõîäÿùèå "âèëêè"
int j=0;
double Fractal.Upper=0;
double mFractals.Price[3];
datetime mFractals.DateTime[3];
// ----- çàïîëíÿåì ìàññèâû èíôîðìàöèåé î ïîñëåäíèõ òðåõ ôðàêòàëàõ
ArrayInitialize(mFractals.Price,0); ArrayInitialize(mFractals.DateTime,0);
for (int i=nBar; i<Bars; i++) { // Öèêë ïî áàðàì
Fractal.Upper=iFractals(NULL,0,MODE_UPPER,i);
if(Fractal.Upper!=0) {
mFractals.Price[j]=Fractal.Upper+MarketInfo(Symbol(),MODE_SPREAD)*Point;
mFractals.DateTime[j]=Time[i];
j++;
}
if(j>2) break;
}
// ----- ðèñóåì íèñõîäÿùèå "âèëêó"
if(mFractals.Price[2]>mFractals.Price[1] && mFractals.Price[1]>mFractals.Price[0]) {
string Name1="Line.Lower"+DoubleToStr(nLine.Lower,0); nLine.Lower++;
string Name2="Line.Lower"+DoubleToStr(nLine.Lower,0); nLine.Lower++;
ObjectCreate(Name1,OBJ_TREND,0,mFractals.DateTime[2],mFractals.Price[2],mFractals.DateTime[1],mFractals.Price[1]);
ObjectCreate(Name2,OBJ_TREND,0,mFractals.DateTime[1],mFractals.Price[1],mFractals.DateTime[0],mFractals.Price[0]);
if (ObjectGetValueByShift(Name1,nBar)>ObjectGetValueByShift(Name2,nBar)) {
ObjectDelete(Name1); ObjectDelete(Name2); nLine.Lower--; nLine.Lower--; return(false);
}
ObjectSet(Name1,OBJPROP_COLOR,Color.LineLower); ObjectSet(Name2,OBJPROP_COLOR,Color.LineLower);
ObjectSet(Name1,OBJPROP_WIDTH,Width.LineLower); ObjectSet(Name2,OBJPROP_WIDTH,Width.LineLower);
ObjectSet(Name1,OBJPROP_RAY,True); ObjectSet(Name2,OBJPROP_RAY,True);
CheckNumVilka(20);
// ----- óäàëÿåì ïðåäûäóùèé îðäåð íà ïîêóïêó
DeleteOrders(10);
return(true);
}
return(false);
}
//+---------------------------------------------------------------------------+
bool isNewBar() { // Ôóíêöèÿ âîçâðàùàåò true, åñëè ïîÿâèòüñÿ íîâûé áàð, èíà÷å false
if(nBars!=Bars) {
nBars=Bars; return(true);
}
return(false);
}
//+---------------------------------------------------------------------------+
void CheckNumVilka(int Type) { // Ôóíêöèÿ ïðîâåðÿåò äîïóñòèìîå êîëè÷åñòâî âèëîê óêàçàííîãî òèïà
int i;
switch(Type) {
case 10:
//--------------------------------------------------------- 1 --
if(nLine.Upper<=nVilka.Upper*2) {
mLineUpper.DateTime[nLine.Upper-2][0]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_TIME1);
mLineUpper.DateTime[nLine.Upper-2][1]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_TIME2);
mLineUpper.Price[nLine.Upper-2][0]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_PRICE1);
mLineUpper.Price[nLine.Upper-2][1]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_PRICE2);
//+------------------------------------------------------------------+
mLineUpper.DateTime[nLine.Upper-1][0]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_TIME1);
mLineUpper.DateTime[nLine.Upper-1][1]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_TIME2);
mLineUpper.Price[nLine.Upper-1][0]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_PRICE1);
mLineUpper.Price[nLine.Upper-1][1]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_PRICE2);
}
//--------------------------------------------------------- 2 --
if(nLine.Upper >nVilka.Upper*2) {
for (i=0; i<nLine.Upper-4; i++) {
mLineUpper.DateTime[i][0]=mLineUpper.DateTime[i+2][0]; mLineUpper.DateTime[i][1]=mLineUpper.DateTime[i+2][1];
mLineUpper.Price[i][0]=mLineUpper.Price[i+2][0]; mLineUpper.Price[i][1]=mLineUpper.Price[i+2][1];
}
mLineUpper.DateTime[nLine.Upper-4][0]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_TIME1);
mLineUpper.DateTime[nLine.Upper-4][1]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_TIME2);
mLineUpper.Price[nLine.Upper-4][0]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_PRICE1);
mLineUpper.Price[nLine.Upper-4][1]=ObjectGet("Line.Upper"+(nLine.Upper-2),OBJPROP_PRICE2);
//+------------------------------------------------------------------+
mLineUpper.DateTime[nLine.Upper-3][0]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_TIME1);
mLineUpper.DateTime[nLine.Upper-3][1]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_TIME2);
mLineUpper.Price[nLine.Upper-3][0]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_PRICE1);
mLineUpper.Price[nLine.Upper-3][1]=ObjectGet("Line.Upper"+(nLine.Upper-1),OBJPROP_PRICE2);
//+------------------------------------------------------------------+
ObjectDelete("Line.Upper"+(nLine.Upper-2)); ObjectDelete("Line.Upper"+(nLine.Upper-1));
nLine.Upper--;nLine.Upper--;
//+------------------------------------------------------------------+
for (i=0; i<nLine.Upper; i++) {
ObjectMove("Line.Upper"+i,0,mLineUpper.DateTime[i][0],mLineUpper.Price[i][0]);
ObjectMove("Line.Upper"+i,1,mLineUpper.DateTime[i][1],mLineUpper.Price[i][1]);
}
}
break; // ýòî äîáàâèë ïîñëå âíèìàòåëüíîãî ïðî÷òåíèÿ ñïðàâêè
case 20:
//--------------------------------------------------------- 1 --
if(nLine.Lower<=nVilka.Lower*2) {
mLineLower.DateTime[nLine.Lower-2][0]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_TIME1);
mLineLower.DateTime[nLine.Lower-2][1]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_TIME2);
mLineLower.Price[nLine.Lower-2][0]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_PRICE1);
mLineLower.Price[nLine.Lower-2][1]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_PRICE2);
//+------------------------------------------------------------------+
mLineLower.DateTime[nLine.Lower-1][0]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_TIME1);
mLineLower.DateTime[nLine.Lower-1][1]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_TIME2);
mLineLower.Price[nLine.Lower-1][0]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_PRICE1);
mLineLower.Price[nLine.Lower-1][1]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_PRICE2);
}
//--------------------------------------------------------- 2 --
if(nLine.Lower >nVilka.Lower*2) {
for (i=0; i<nLine.Lower-4; i++) {
mLineLower.DateTime[i][0]=mLineLower.DateTime[i+2][0]; mLineLower.DateTime[i][1]=mLineLower.DateTime[i+2][1];
mLineLower.Price[i][0]=mLineLower.Price[i+2][0]; mLineLower.Price[i][1]=mLineLower.Price[i+2][1];
}
mLineLower.DateTime[nLine.Lower-4][0]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_TIME1);
mLineLower.DateTime[nLine.Lower-4][1]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_TIME2);
mLineLower.Price[nLine.Lower-4][0]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_PRICE1);
mLineLower.Price[nLine.Lower-4][1]=ObjectGet("Line.Lower"+(nLine.Lower-2),OBJPROP_PRICE2);
//+------------------------------------------------------------------+
mLineLower.DateTime[nLine.Lower-3][0]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_TIME1);
mLineLower.DateTime[nLine.Lower-3][1]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_TIME2);
mLineLower.Price[nLine.Lower-3][0]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_PRICE1);
mLineLower.Price[nLine.Lower-3][1]=ObjectGet("Line.Lower"+(nLine.Lower-1),OBJPROP_PRICE2);
//+------------------------------------------------------------------+
ObjectDelete("Line.Lower"+(nLine.Lower-2)); ObjectDelete("Line.Lower"+(nLine.Lower-1));
nLine.Lower--;nLine.Lower--;
//+------------------------------------------------------------------+
for (i=0; i<nLine.Lower; i++) {
ObjectMove("Line.Lower"+i,0,mLineLower.DateTime[i][0],mLineLower.Price[i][0]);
ObjectMove("Line.Lower"+i,1,mLineLower.DateTime[i][1],mLineLower.Price[i][1]);
}
}
break; // ýòî äîáàâèë ïîñëå âíèìàòåëüíîãî ïðî÷òåíèÿ ñïðàâêè
}
return;
}
//+---------------------------------------------------------------------------+
void DeleteOrders(int Type) { // Ôóíêöèÿ óäàëÿåò îðäåðà óêàçàííîãî òèïà
if(Type==10) {
//--------------------------------------------------------- 1 --
mOrders[0][0]=0; mOrders[0][1]=""; mOrders[0][2]=""; mOrders[0][3]=""; mOrders[0][4]=0;
ObjectDelete("Order.Buy"); ObjectDelete("OrderArrow.Buy");
ObjectDelete("StopLoss.Buy"); ObjectDelete("StopLossArrow.Buy");
ObjectDelete("LabelPrice.Buy"); ObjectDelete("LabelStopLoss.Buy");
}
if(Type==20) {
//--------------------------------------------------------- 2 --
mOrders[1][0]=0; mOrders[1][1]=""; mOrders[1][2]=""; mOrders[1][3]=""; mOrders[1][4]=0;
ObjectDelete("Order.Sell"); ObjectDelete("OrderArrow.Sell");
ObjectDelete("StopLoss.Sell"); ObjectDelete("StopLossArrow.Sell");
ObjectDelete("LabelPrice.Sell"); ObjectDelete("LabelStopLoss.Sell");
}
return;
}
//+---------------------------------------------------------------------------+
bool DrawOrdersBuy(int nBar) { // Ôóíêöèÿ ðèñóò îðäåðà Buy
double Price.Buy=Open[nBar];
double StopLoss.Buy;
// ----- îïðåäåëÿåì ñòîïëîññ
for (int i=nBar+1; i<Bars; i++) { // Öèêë ïî áàðàì
StopLoss.Buy=iFractals(NULL,0,MODE_LOWER,i);
if(StopLoss.Buy!=0) {
StopLoss.Buy=StopLoss.Buy-MarketInfo(Symbol(),MODE_SPREAD)*Point;
break;
}
}
// ----- ïðîâåðÿåì óñëîâèÿ äëÿ îòêðûòèÿ ïîçèöèè
// 1. Ôðàêòàë äîëæåí áûòü íèæå âåðõíåãî ëó÷à âèëêè.
// 2. Çíà÷åíèå ôðàêòàëà äîëæíî áûòü ìåíüøå çíà÷åíèÿ îòêðûòèÿ ïîçèöèè(ïåðåñå÷åíèÿ).
if(StopLoss.Buy>=ObjectGetValueByShift(NameLine.Buy,i) || StopLoss.Buy>=Price.Buy) {
return(false);
}
// ----- óäàëÿåì ïðåäûäóùèé îðäåð íà ïîêóïêó
DeleteOrders(10);
// ----- îïðåäåëÿåìñÿ ñ ïàðàìåòðàìè îðäåðà
mOrders[0][0]=10; // óñòàíàâëèâàåì ôëàã "îòêðûòîãî" îðäåðà íà ïîêóïêó
mOrders[0][1]=TimeToStr(Time[nBar],TIME_DATE|TIME_MINUTES); // Äàòà è âðåìÿ "îòêðûòèÿ" îðäåðà
mOrders[0][2]=Price.Buy; // Öåíà îðäåðà îðäåðà
mOrders[0][3]=StopLoss.Buy; // Ñòîïëîññ îðäåðà îðäåðà
mOrders[0][4]=0; // ôëàã ñðàáàòûâàíèÿ ñòîïëîññà: 0-ñòîïëîññ ÍÅ ñðàáîòàë, 1-ñòîïëîññ ñðàáîòàë
// ----- ðèñóåì, åñëè ðàçðåøåíî
if(ShowOrders) {
// ----- ðèñóåì îðäåð íà ïîêóïêó
ObjectCreate("Order.Buy",OBJ_TREND,0,Time[nBar+25],Price.Buy,Time[nBar],Price.Buy);
ObjectCreate("OrderArrow.Buy",OBJ_ARROW,0,Time[nBar+23],Price.Buy);
ObjectSet("Order.Buy",OBJPROP_COLOR,Color.OrderBuy); ObjectSet("OrderArrow.Buy",OBJPROP_COLOR,Color.OrderBuy);
ObjectSet("Order.Buy",OBJPROP_WIDTH,Width.OrderBuy); ObjectSet("OrderArrow.Buy",OBJPROP_WIDTH,Width.OrderBuy);
ObjectSet("Order.Buy",OBJPROP_RAY,false); ObjectSet("OrderArrow.Buy",OBJPROP_ARROWCODE,225);
ObjectCreate("LabelPrice.Buy",OBJ_TEXT,0,Time[nBar+10],Price.Buy);
ObjectSetText("LabelPrice.Buy","Buy: "+DoubleToStr(Price.Buy,Digits),Orders.FontSize, "Times New Roman",
Color.OrderBuy);
// ----- ðèñóåì ñòîïëîñ íà ïîêóïêó
ObjectCreate("StopLoss.Buy",OBJ_TREND,0,Time[nBar+25],StopLoss.Buy,Time[nBar],StopLoss.Buy);
ObjectCreate("StopLossArrow.Buy",OBJ_ARROW,0,Time[nBar+23],StopLoss.Buy);
ObjectSet("StopLoss.Buy",OBJPROP_COLOR,Color.SLBuy); ObjectSet("StopLossArrow.Buy",OBJPROP_COLOR,Color.SLBuy);
ObjectSet("StopLoss.Buy",OBJPROP_WIDTH,Width.OrderBuy); ObjectSet("StopLossArrow.Buy",OBJPROP_WIDTH,Width.OrderBuy);
ObjectSet("StopLoss.Buy",OBJPROP_RAY,false); ObjectSet("StopLossArrow.Buy",OBJPROP_ARROWCODE,251);
ObjectCreate("LabelStopLoss.Buy",OBJ_TEXT,0,Time[nBar+10],StopLoss.Buy);
ObjectSetText("LabelStopLoss.Buy","SL Buy: "+DoubleToStr(StopLoss.Buy,Digits),Orders.FontSize, "Times New Roman",
Color.SLBuy);
}
return(true);
}
//+---------------------------------------------------------------------------+
bool DrawOrdersSell(int nBar) { // Ôóíêöèÿ ðèñóò îðäåðà Sell
double Price.Sell=Open[nBar];
double StopLoss.Sell;
// ----- îïðåäåëÿåì ñòîïëîññ
for (int i=nBar; i<Bars; i++) { // Öèêë ïî áàðàì
StopLoss.Sell=iFractals(NULL,0,MODE_UPPER,i);
if(StopLoss.Sell!=0) {
StopLoss.Sell=StopLoss.Sell+MarketInfo(Symbol(),MODE_SPREAD)*Point;
break;
}
}
// ----- ïðîâåðÿåì óñëîâèÿ äëÿ îòêðûòèÿ ïîçèöèè
// 1. Ôðàêòàë äîëæåí áûòü âûøå âåðõíåãî ëó÷à âèëêè.
// 2. Çíà÷åíèå ôðàêòàëà äîëæíî áûòü áîëüøå çíà÷åíèÿ îòêðûòèÿ ïîçèöèè(ïåðåñå÷åíèÿ).
if(StopLoss.Sell<=ObjectGetValueByShift(NameLine.Sell,i) || StopLoss.Sell<=Price.Sell) {
return(false);
}
// ----- óäàëÿåì ïðåäûäóùèé îðäåð íà ïðîäàæó
DeleteOrders(20);
// ----- îïðåäåëÿåìñÿ ñ ïàðàìåòðàìè îðäåðà
mOrders[1][0]=20; // óñòàíàâëèâàåì ôëàã "îòêðûòîãî" îðäåðà íà ïðîäàæó
mOrders[1][1]=TimeToStr(Time[nBar],TIME_DATE|TIME_MINUTES); // Äàòà è âðåìÿ "îòêðûòèÿ" îðäåðà
mOrders[1][2]=Price.Sell; // Öåíà îðäåðà îðäåðà
mOrders[1][3]=StopLoss.Sell; // Ñòîïëîññ îðäåðà îðäåðà
mOrders[1][4]=0; // ôëàã ñðàáàòûâàíèÿ ñòîïëîññà: 0-ñòîïëîññ ÍÅ ñðàáîòàë, 1-ñòîïëîññ ñðàáîòàë
// ----- ðèñóåì, åñëè ðàçðåøåíî
if(ShowOrders) {
// ----- ðèñóåì îðäåð íà ïðîäàæó
ObjectCreate("Order.Sell",OBJ_TREND,0,Time[nBar+25],Price.Sell,Time[nBar],Price.Sell);
ObjectCreate("OrderArrow.Sell",OBJ_ARROW,0,Time[nBar+23],Price.Sell+10*Point);
ObjectSet("Order.Sell",OBJPROP_COLOR,Color.OrderSell); ObjectSet("OrderArrow.Sell",OBJPROP_COLOR,Color.OrderSell);
ObjectSet("Order.Sell",OBJPROP_WIDTH,Width.OrderSell); ObjectSet("OrderArrow.Sell",OBJPROP_WIDTH,Width.OrderSell);
ObjectSet("Order.Sell",OBJPROP_RAY,false); ObjectSet("OrderArrow.Sell",OBJPROP_ARROWCODE,226);
ObjectCreate("LabelPrice.Sell",OBJ_TEXT,0,Time[nBar+10],Price.Sell+10*Point);
ObjectSetText("LabelPrice.Sell","Sell: "+DoubleToStr(Price.Sell,Digits),Orders.FontSize, "Times New Roman",
Color.OrderSell);
// ----- ðèñóåì ñòîïëîñ íà ïðîäàæó
ObjectCreate("StopLoss.Sell",OBJ_TREND,0,Time[nBar+25],StopLoss.Sell,Time[nBar],StopLoss.Sell);
ObjectCreate("StopLossArrow.Sell",OBJ_ARROW,0,Time[nBar+23],StopLoss.Sell+10*Point);
ObjectSet("StopLoss.Sell",OBJPROP_COLOR,Color.SLSell); ObjectSet("StopLossArrow.Sell",OBJPROP_COLOR,Color.SLSell);
ObjectSet("StopLoss.Sell",OBJPROP_WIDTH,Width.OrderSell);ObjectSet("StopLossArrow.Sell",OBJPROP_WIDTH,Width.OrderSell);
ObjectSet("StopLoss.Sell",OBJPROP_RAY,false); ObjectSet("StopLossArrow.Sell",OBJPROP_ARROWCODE,251);
ObjectCreate("LabelStopLoss.Sell",OBJ_TEXT,0,Time[nBar+10],StopLoss.Sell+10*Point);
ObjectSetText("LabelStopLoss.Sell","SL Sell: "+DoubleToStr(StopLoss.Sell,Digits),Orders.FontSize, "Times New Roman",
Color.SLSell);
}
return;
}
//+---------------------------------------------------------------------------+
void SendMailSignals(int nBar, int SignalId) { // îòñûëàåò ñîîáùåíèå íà e-mail òîðãîâûå ñèãíàëû
string Mail.Message;
switch(SignalId) {
//--------------------------------------------------------- 1 --
case 10:
Mail.Message="Buy signal!"+CharToStr(13)+"Symbol: "+Symbol()+CharToStr(13)+
"Timeframe: "+GetNameTF()+CharToStr(13)+"DateTime: "+mOrders[0][1]+CharToStr(13)+
"Price: "+mOrders[0][2]+CharToStr(13)+"StopLoss: "+mOrders[0][3];
SendMail("Buy signal!",Mail.Message);
break;
//--------------------------------------------------------- 2 --
case 11:
Mail.Message="Attention! Stop Loss Buy!"+CharToStr(13)+"Symbol: "+Symbol()+CharToStr(13)+
"Timeframe: "+GetNameTF()+CharToStr(13)+"DateTime: "+TimeToStr(Time[nBar],TIME_DATE|TIME_MINUTES)+
CharToStr(13)+"StopLoss: "+mOrders[0][3];
SendMail("Attention! Stop Loss Buy!",Mail.Message);
break;
//--------------------------------------------------------- 3 --
case 20:
Mail.Message="Sell signal!"+CharToStr(13)+"Symbol: "+Symbol()+CharToStr(13)+
"Timeframe: "+GetNameTF()+CharToStr(13)+"DateTime: "+mOrders[1][1]+CharToStr(13)+
"Price: "+mOrders[1][2]+CharToStr(13)+"StopLoss: "+mOrders[1][3];
SendMail("Sell signal!",Mail.Message);
break;
//--------------------------------------------------------- 4 --
case 21:
Mail.Message="Attention! Stop Loss Sell!"+CharToStr(13)+"Symbol: "+Symbol()+CharToStr(13)+
"Timeframe: "+GetNameTF()+CharToStr(13)+"DateTime: "+TimeToStr(Time[nBar],TIME_DATE|TIME_MINUTES)+
CharToStr(13)+"StopLoss: "+mOrders[1][3];
SendMail("Attention! Stop Loss Sell! ",Mail.Message);
break;
}
return;
}
//+----------------------------------------------------------------------------+
//| Àâòîð : Êèì Èãîðü Â. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 01.09.2005 |
//| Îïèñàíèå : Âîçâðàùàåò íàèìåíîâàíèå òàéìôðåéìà |
//+----------------------------------------------------------------------------+
//| Ïàðàìåòðû: |
//| TimeFrame - òàéìôðåéì (êîëè÷åñòâî ñåêóíä) (0 - òåêóùèé ÒÔ) |
//+----------------------------------------------------------------------------+
string GetNameTF(int TimeFrame=0) {
if (TimeFrame==0) TimeFrame=Period();
switch (TimeFrame) {
case PERIOD_M1: return("M1");
case PERIOD_M5: return("M5");
case PERIOD_M15: return("M15");
case PERIOD_M30: return("M30");
case PERIOD_H1: return("H1");
case PERIOD_H4: return("H4");
case PERIOD_D1: return("Daily");
case PERIOD_W1: return("Weekly");
case PERIOD_MN1: return("Monthly");
default: return("UnknownPeriod");
}
}
//+---------------------------------------------------------------------------+
bool CheckParameters() { // Ôóíêöèÿ ïðîâåðêè âíåøíèõ ïàðàìåòðîâ èíäèêàòîðà
if(nVilka.Upper<1 || nVilka.Lower<1) {
string TextMessage="Íåâåðíûå çíà÷åíèÿ âíåøíèõ ïàðàìåòðîâ èíäèêàòîðà!"+
"Ïàðàìåòðû nVilka.Upper è nVilka.Lower íå ìîãóò áûòü <(ìåíüøå) 1";
Alert(TextMessage);
return(false);
}
return(true);
}
void OrderOp(int ord, string val, int TakeProfit, int StopLoss, double lot)
{
double TP,SL,ticket, pAsk, pBid;
bool res=false;
while(!res)
{
pAsk = MarketInfo(val,MODE_ASK);
pBid = MarketInfo(val,MODE_BID);
TP=0; SL=0;
if(ord==OP_BUY)
{
TP=pAsk+TakeProfit*Point; if(TakeProfit==0) TP=0;
SL=pBid-StopLoss*Point; if(StopLoss==0) SL=0;
ticket=OrderSend(val,OP_BUY,lot,pAsk,3,SL,TP,"",MG,0);
}
if(ord==OP_SELL)
{
TP=pBid-TakeProfit*Point; if(TakeProfit==0) TP=0;
SL=pAsk+StopLoss*Point; if(StopLoss==0) SL=0;
ticket=OrderSend(val,OP_SELL,lot,pBid,3,SL,TP,"",MG,0);
}
if(ticket>0) res = true;
}
}
//+------------------------------------------------------------------+
int colOrders(int oType)
{
int cnt,ao=0;
for(cnt=OrdersTotal();cnt>0;cnt--)
{
OrderSelect(cnt-1, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==MG && OrderType() == oType) ao++;
}
return(ao);
}
//+------------------------------------------------------------------+
int OrderCl(int ord)
{
int cnt;
for(cnt=OrdersTotal();cnt>0;cnt--)
{
OrderSelect(cnt-1, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && ord==OP_BUY && OrderMagicNumber()==MG) while (!OrderClose(OrderTicket(),OrderLots(),Bid,3)) { }
if(OrderType()==OP_SELL && ord==OP_SELL && OrderMagicNumber()==MG) while (!OrderClose(OrderTicket(),OrderLots(),Ask,3)) { }
}
}
//+------------------------------------------------------------------+
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
---