Price Data Components
Orders Execution
0
Views
0
Downloads
0
Favorites
Geo_F1
//+------------------------------------------------------------------+
//| Geo_F1.mq4 |
//| Copyright © 2011, 2012 Geokom FX Lab|
//| geokom2004@yandex.ru |
//| |
//| |
//| |
//| |
//+------------------------------------------------------------------+
// Ââîäèì àâò ïîñòàíîâêó îðäåðà ïî èíäèêàòîðó
#property copyright "Copyright © 2011, 2012 Geokom FX Lab"
#property link "geokom2004@yandex.ru"
#define Version "21022012_Geo_F1"
// Ïîñòàíîâêà îòëîæåííûõ îðäåðîâ ïî ëèíèÿì, ìîäèôèêàöèÿ, ïåðåâîä â áó, óäàëåíèå, çàêðûòèå
// áèáëèîòåêà äëÿ ðàñ÷åòà óðîâíåé îðäåðîâ
// Ïðè çàãðóçêå ýêñïåðò ïðîâåðÿåò íàëè÷èå îðäåðîâ è âûñòàâëÿåò ëèíèè ïî îðäåðàì
// 21022012 - ââåäåíû ëèìèòíèêè
#import "Geo_Lib_OrderPrice.ex4"
double OPBS (string Symb, int TF, int Method, datetime TimeB, datetime TimeE);
double OPSS (string Symb, int TF, int Method, datetime TimeB, datetime TimeE);
//---- input parameters
extern string Còðàòåãèÿ = "Îðäåðà ïî óðîâíÿì èç áèáëèîòåêè";
extern int MagicNo=12345;
extern double LotSize=0.1;// ðàçìåð ëîòà.
extern double MaxLotSize=0.5;// ìàêñèìàëüíûé ðàçìåð ëîòà.
extern double Risk = 0.0; // óñòàíîâêà âåëè÷èíû ðèñêà - ïðîöåíò ïîòåðü (îò äåïî ) íà îäíó ñäåëêó; Åñëè =0 - òî ëîò íå ìåíÿåòñÿ, ðàâåí çàäàííîìó
extern int ÑòîïÓðîâåíüÏîÄíþ = 1;
extern double PendingDistance = 0.38;
extern double TP1Level = 1;
extern double TP2Level = 1.6;
extern double TP3Level = 2.3;
extern double TP4Level = 3.0;
extern double TP5Level = 4.0;
extern bool ÁåçÑòîïîâ = true;
extern int ObjectCorner = 1;
extern int X_ObjectPosition = 80;
extern int Y_ObjectPosition = 250;
extern int Tolerance = 50; //÷óâñòâèòåëüíîñòü ê ñäâèãó îáúåêòîâ
extern int MinStep = 10; //ìèí øàã äëÿ ìîäèôèêàöèè îðäåðîâ (äëÿ 5 çíàêîâ)
extern int sleep = 200; //
extern int MA_TF=PERIOD_D1; // Ïåðèîä, íà êîòîðîì ïðîèçâîäèòñÿ ðàñ÷åò. ÍÅ ìåíÿåòñÿ ïðè ïåðåêëþ÷åíè ÒÔ.
extern bool UseLibrary = true;
extern bool ÑëåäèòüÇàÓðîâíåì = true;
extern string RangeTimeB1 = "01:00";
extern string RangeTimeE1 = "08:59";
extern string RangeTimeB2 = "08:00";
extern string RangeTimeE2 = "16:59";
extern string RangeTimeB3 = "16:00";
extern string RangeTimeE3 = "23:59";
static datetime New_Time;
bool Ls, Lb, DeleteBS, DeleteSS, DeBS, DeSS, MovedBs, MovedSs, LbMoved, LsMoved, BÁó, SÁó, BClo, SClo, SellMoved, BuyMoved;
string CommentString, CommentString1;
double MinEquity, MinFreeMargin, SPR, LotSizeCalc, StepLots,
OrderPriceLow, OrderPriceHigh , MinLot, FreeMargin, Equity , Balance, TickPrice,
OrderPriceBS, OrderPriceSS,
OrderBTP1, OrderSTP1,OrderBTP2, OrderSTP2,OrderBTP3, OrderSTP3;
int DigLots;
color SCloColor = Gray; color BCloColor = Gray; color DeBSColor = Gray; color DeSSColor = Gray;
color SÁóColor,BÁóColor;
int NewÏåðåìåùåíèåX, NewÏåðåìåùåíèåY;
//---- buffers
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
DeleteBS = false;
DeleteSS = false;
DeBS = false;
DeSS = false;
BÁó = false;
SÁó = false;
SClo = false;
BClo = false;
// Lb = false;
// Ls = false;
MinEquity = AccountBalance();
MinFreeMargin = AccountBalance();
//----Çäåñü äîëæåí áûòü óêàçàí ïåðèîä íà êîòîðîì äîëæíû îòêðûâàòüñÿ îðäåðà
New_Time=iTime(Symbol(),MA_TF,0);
//----
if (Risk > 0)
{
CommentString1=TerminalPath( )+"\n"+"Ðàáî÷èé ÒÔ - "+ MA_TF+" Ðàáî÷èé ëîò ðàñ÷èòûâàåòñÿ!!!" + " Magic "+MagicNo;
}
else
{
CommentString1=TerminalPath( )+"\n"+"Ðàáî÷èé ÒÔ - "+ MA_TF+" Ðàáî÷èé ëîò ="+DoubleToStr(LotSize,2)+" Magic "+MagicNo;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
// ObjectsDeleteAll();
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| âîçâðàùàåò true åñëè ïîÿâëèñÿ íîâûé áàð, èíà÷å false |
bool isNewBar(int TF) // Ô-èÿ îáíàðóæåíèÿ ..
{
// .. íîâîãî áàðà
// New_Time=0; // Âðåìÿ òåêóùåãî áàðà
bool New_Bar=false;
// Íîâîãî áàðà íåò
if(New_Time!=iTime(NULL,TF,0)) // Ñðàâíèâàåì âðåìÿ íà òåêóùåì ñèìâîëå íà çàäàííîì TF
{ New_Time=iTime(NULL,TF,0); // Òåïåðü âðåìÿ òàêîå
New_Bar=true; // Ïîéìàëñÿ íîâûé áàð/
}
return(New_Bar);
}
//| âîçâðàùàåò true åñëè ïîÿâëèñÿ íîâûé áàð, èíà÷å false |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| âîçâðàùàåò çíà÷åíèå åñëè ñäâèíóò îáúåêò |
string isMovedLabel(string ObjName, bool Draw, string Label, string FontName, int ObjectSize, int dX, int dY, color InitObjColor)
{
if ( (!Draw) ) // Åñëè êîä = 0 - óäàëÿåì îáúåêò
{
if (ObjectFind(ObjName)==0)
{ObjectDelete (ObjName);}
return(0);
}
int X = 0;
int Y = 0;
if (ObjectFind(ObjName)==-1)
{
ObjectCreate (ObjName,OBJ_LABEL,0,0,0);
ObjectSetText (ObjName,Label,ObjectSize,FontName,InitObjColor);
ObjectSet (ObjName, OBJPROP_CORNER,ObjectCorner);
ObjectSet (ObjName, OBJPROP_XDISTANCE,X_ObjectPosition+dX);
ObjectSet (ObjName, OBJPROP_YDISTANCE,Y_ObjectPosition+dY);
}
if (ObjectFind(ObjName)==0)
{
ObjectSet (ObjName, OBJPROP_CORNER,1);
ObjectSetText (ObjName,Label,ObjectSize,FontName,InitObjColor);
if (MathAbs(ObjectGet(ObjName,OBJPROP_XDISTANCE) - (X_ObjectPosition+dX) ) > Tolerance) { X=ObjectGet(ObjName,OBJPROP_XDISTANCE) - (X_ObjectPosition+dX); }
if (MathAbs(ObjectGet(ObjName,OBJPROP_YDISTANCE) - (Y_ObjectPosition+dY) ) > Tolerance) { Y=ObjectGet(ObjName,OBJPROP_YDISTANCE) - (Y_ObjectPosition+dY); }
if (ObjectGet(ObjName,OBJPROP_XDISTANCE) != X_ObjectPosition+dX) {ObjectSet(ObjName,OBJPROP_XDISTANCE,X_ObjectPosition+dX) ; }
if (ObjectGet(ObjName,OBJPROP_YDISTANCE) != Y_ObjectPosition+dY) {ObjectSet(ObjName,OBJPROP_YDISTANCE,Y_ObjectPosition+dY) ; }
if (X!=0 || Y!=0 ) return(StringConcatenate(X,"@",Y));
}
return("");
}
//| âîçâðàùàåò ñèãíàë åñëè ñäâèíóò îáúåêò |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| âîçâðàùàåò ñèãíàë åñëè ñäâèíóò îáúåêò |
// !!!! Òèï ôóyêöèè - string !!!
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void DrawLine (string LineName, bool magnet , datetime Time1,double Price1, datetime Time2,double Price2, bool draw, color LineColor, int LineStyle, bool TrendLine, bool Ray) // Íàõîäèì ñâîþ ëèíèþ. Åñëè öåíà äðóãàÿ ìåíÿåì ëèíèþ. Åñëè ëèíèè ííåò - Ðèñóåì íîâóþ.
{
if (ObjectFind(LineName)==0)
{
if(!draw) {ObjectDelete(LineName);return;}
if (magnet && ObjectGet(LineName,OBJPROP_TIME1) != Time1)
{
ObjectSet(LineName,OBJPROP_TIME1,Time1);
}
if (magnet && ObjectGet(LineName,OBJPROP_PRICE1) != Price1)
{
ObjectSet(LineName,OBJPROP_PRICE1,Price1);
}
if (TrendLine)
{
if (magnet && ObjectGet(LineName,OBJPROP_TIME2) != Time2)
{
ObjectSet(LineName,OBJPROP_TIME2,Time2);
}
if (magnet && ObjectGet(LineName,OBJPROP_PRICE2) != Price2)
{
ObjectSet(LineName,OBJPROP_PRICE2,Price2);
}
}
ObjectSet(LineName,OBJPROP_COLOR,LineColor);
ObjectSet(LineName,OBJPROP_STYLE,LineStyle);
}
if (ObjectFind(LineName)!=0&&draw)
{
if (!TrendLine)
{
ObjectCreate (LineName,OBJ_HLINE,0,0,Price1,0);
}
if (TrendLine)
{
ObjectCreate (LineName,OBJ_TREND,0,Time1,Price1,Time2,Price2);
ObjectSet(LineName,OBJPROP_RAY,Ray);
}
ObjectSet(LineName,OBJPROP_COLOR,LineColor);
ObjectSet(LineName,OBJPROP_STYLE,LineStyle);
}
}
return;
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void By(int BuySell)
{
int Total = OrdersTotal();
if (Total>0)
{
for(int i=Total-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) //ïåðåáèðàåì ñðåäè îòêðûòûõ îðäåðîâ, ïðè íàõîæäåíèè ñ÷èòàåì è çàïîìèíàåì íîìåð
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNo || MagicNo == 0) )
{
if( OrderType()==OP_BUY && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3 ) )
{
}
}
}
}
}
return;
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int st = GetTickCount();
string CommentString ="";
int NewÏåðåìåùåíèåX, NewÏåðåìåùåíèåY;
string Ïåðåìåùåíèå = isMovedLabel("ÏåðåìåùåíèåÝÓ", true, "Ïåðåìåùåíèå", "arial", 12, -20, 40, Navy);
int ÏåðåìåùåíèåX = StrToInteger (StringSubstr(Ïåðåìåùåíèå,0, StringFind(Ïåðåìåùåíèå,"@",0)));
int ÏåðåìåùåíèåY = StrToInteger (StringSubstr(Ïåðåìåùåíèå, StringFind(Ïåðåìåùåíèå,"@",0)+1,0 ));
bool ÏåðåìåùåíèåÝÓ = (Ïåðåìåùåíèå!="") ;
CommentString = CommentString1 ;
/*
CommentString = CommentString + " " + Ïåðåìåùåíèå+ " " +ÏåðåìåùåíèåX + " " + ÏåðåìåùåíèåY;
if (NewÏåðåìåùåíèåX != ÏåðåìåùåíèåX && ÏåðåìåùåíèåX !=0) {NewÏåðåìåùåíèåX = ÏåðåìåùåíèåX ;}
if (NewÏåðåìåùåíèåY != ÏåðåìåùåíèåY && ÏåðåìåùåíèåY !=0) {NewÏåðåìåùåíèåY = ÏåðåìåùåíèåY ;}
CommentString = CommentString + " " +NewÏåðåìåùåíèåX + " " + NewÏåðåìåùåíèåY;
// if (ÏåðåìåùåíèåX ==0 && NewÏåðåìåùåíèåX != 0) {ÏåðåìåùåíèåÝÓ = true; X_ObjectPosition = X_ObjectPosition + NewÏåðåìåùåíèåX ;}
// if (ÏåðåìåùåíèåY ==0 && NewÏåðåìåùåíèåY != 0) {ÏåðåìåùåíèåÝÓ = true; Y_ObjectPosition = Y_ObjectPosition + NewÏåðåìåùåíèåY; }
*/
// string STR= TerminalPath( ) + "\nMagicNo: " +MagicNo ;
if (SPR ==0) { SPR = MarketInfo(Symbol(),MODE_SPREAD);}
if (!GlobalVariableCheck ("TPLelels") || GlobalVariableGet ("TPLelels") ==0 )
{GlobalVariableSet ("TPLelels",3);}
if (GlobalVariableCheck ("PendingOrderDistance") ) {PendingDistance = GlobalVariableGet ("PendingOrderDistance");}
if (!GlobalVariableCheck ("Method") ) {GlobalVariableSet ("Method",10);}
if (Digits ==2 || Digits ==4) {int k = 10;}
if (Digits ==3 || Digits ==5) {k = 1;}
// CommentString = CommentString1 + StringConcatenate ("\n###"," iBuyStop: ", iBuyStop, " iSellStop: ", iSellStop );
int i=0,l=0, b=0, s=0,bs=0,ss=0, bl=0, sl=0, Total;//ñáðîñ ñ÷åò÷èêîâ îðäåðîâ
// Ïðîâåðÿåì íàëè÷èå îòêðûòûõ è îòëîæåííûõ îðäåðîâ íà èíñòðóìåíòå.
//******************************************************************************************
//******************************************************************************************
Total = OrdersTotal();
if (Total>0)
{
double OrderPriceB, OrderPriceBSL, OrderPriceS, OrderPriceSSL;
for( i=Total-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) //ïåðåáèðàåì ñðåäè îòêðûòûõ îðäåðîâ, ïðè íàõîæäåíèè ñ÷èòàåì è çàïîìèíàåì íîìåð
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNo || MagicNo == 0) )
{
if( OrderType()==OP_BUY && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3 ) )
{
// AssignLine(OrderTicket(),OrderType() );
if (OrderPriceB ==0) { OrderPriceB = OrderOpenPrice();}
if (OrderPriceBSL != OrderStopLoss() && OrderStopLoss() >0) { OrderPriceBSL = OrderStopLoss();}
if( StrToInteger(OrderComment()) == 1 ){ OrderBTP1 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 2 ){ OrderBTP2 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 3 ){ OrderBTP3 = OrderTakeProfit();}
DeBS = false;
BCloColor = Blue;
b++; //if (OrdersPriceBSSL ==0 && OrderStopLoss() !=0) {OrdersPriceBSSL = OrderStopLoss();}
} // åñëè íà òåêóùåì èíñòðóìåíòå åñòü BUY îðäåð
if( OrderType()==OP_SELL && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3 ) )
{
if (OrderPriceS==0) { OrderPriceS = OrderOpenPrice();}
if (OrderPriceSSL != OrderStopLoss()&& OrderStopLoss() !=0){ OrderPriceSSL = OrderStopLoss();}
if( StrToInteger(OrderComment()) == 1 ){ OrderSTP1 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 2 ){ OrderSTP2 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 3 ){ OrderSTP3 = OrderTakeProfit();}
DeSS = false;
SCloColor = Red;
s++; //if (OrdersPriceSSSL ==0 && OrderStopLoss() !=0) {OrdersPriceSSSL = OrderStopLoss();}
}// åñëè íà òåêóùåì èíñòðóìåíòå åñòü SELL
if( OrderType()==OP_BUYSTOP && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3 ) )
{
if (OrderPriceB ==0) { OrderPriceB = OrderOpenPrice();}
if (OrderPriceBSL != OrderStopLoss() && OrderStopLoss() >0) { OrderPriceBSL = OrderStopLoss();}
if( StrToInteger(OrderComment()) == 1 ){ OrderBTP1 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 2 ){ OrderBTP2 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 3 ){ OrderBTP3 = OrderTakeProfit();}
DeBS = false;
bs++; //if (OrdersPriceBSSL ==0 && OrderStopLoss() !=0) {OrdersPriceBSSL = OrderStopLoss();}
}// åñëè íà òåêóùåì èíñòðóìåíòå åñòü BUYSTOP îðäåð
if( OrderType()==OP_BUYLIMIT && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3 ) )
{
if (OrderPriceB ==0) { OrderPriceB = OrderOpenPrice();}
if (OrderPriceBSL != OrderStopLoss() && OrderStopLoss() >0) { OrderPriceBSL = OrderStopLoss();}
if( StrToInteger(OrderComment()) == 1 ){ OrderBTP1 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 2 ){ OrderBTP2 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 3 ){ OrderBTP3 = OrderTakeProfit();}
DeBS = false;
bl++;
}// åñëè íà òåêóùåì èíñòðóìåíòå åñòü BUYLIMIT îðäåð
if( OrderType()==OP_SELLSTOP && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3) )
{
if (OrderPriceS==0) { OrderPriceS = OrderOpenPrice();}
if (OrderPriceSSL != OrderStopLoss()&& OrderStopLoss() !=0){ OrderPriceSSL = OrderStopLoss();}
if( StrToInteger(OrderComment()) == 1 ){ OrderSTP1 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 2 ){ OrderSTP2 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 3 ){ OrderSTP3 = OrderTakeProfit();}
DeSS = false;
ss++; //if (OrdersPriceSSSL ==0 && OrderStopLoss() !=0) {OrdersPriceSSSL = OrderStopLoss();}
} // åñëè íà òåêóùåì èíñòðóìåíòå åñòü SELLSTOP
if( OrderType()==OP_SELLLIMIT && (StrToInteger(OrderComment()) == 1 || StrToInteger(OrderComment()) == 2 || StrToInteger(OrderComment()) == 3) )
{
if (OrderPriceS==0) { OrderPriceS = OrderOpenPrice();}
if (OrderPriceSSL != OrderStopLoss()&& OrderStopLoss() !=0){ OrderPriceSSL = OrderStopLoss();}
if( StrToInteger(OrderComment()) == 1 ){ OrderSTP1 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 2 ){ OrderSTP2 = OrderTakeProfit();}
if( StrToInteger(OrderComment()) == 3 ){ OrderSTP3 = OrderTakeProfit();}
DeSS = false;
sl++; //if (OrdersPriceSSSL ==0 && OrderStopLoss() !=0) {OrdersPriceSSSL = OrderStopLoss();}
} // åñëè íà òåêóùåì èíñòðóìåíòå åñòü SELLSTOP
}
}
}
}
if (bs+bl ==0) { DeleteBS = false;}
if (ss + sl ==0) { DeleteSS = false;}
if (b ==0) { BClo = false; BCloColor = Gray; BÁó = false; BÁóColor = Gray;} else{BÁóColor = Blue;}
if (s ==0) { SClo = false; SCloColor = Gray; SÁó = false; SÁóColor = Gray;} else{SÁóColor = Red;}
if (s+ss +sl ==0) {DeSSColor = Red;} else{DeSSColor = Gray; DeSS = false; }
if (b+bs+bl ==0) {DeBSColor = Blue;}else{DeBSColor = Gray; DeBS = false; }
BÁó = false;
SÁó = false;
//if (b >= GlobalVariableGet ("TPLelels") ) {BuyMoved = false;}
//if (s >= GlobalVariableGet ("TPLelels") ) {SellMoved = false;}
// Ïðîâåðÿåì íàëè÷èå îòêðûòûõ è îòëîæåííûõ îðäåðîâ íà èíñòðóìåíòå.
//****************************************************************
LbMoved = false;LsMoved = false;
if( !ÏåðåìåùåíèåÝÓ && isMovedLabel("Lb", true, "L", "arial", 16, 60, 0, Blue)!="" ) {Lb = true; LbMoved = True; MovedBs = False;}
if( !ÏåðåìåùåíèåÝÓ && isMovedLabel("Ls", true, "L", "arial", 16, 60, 20, Red)!="" ) {Ls = True; LsMoved = True;MovedSs = False;}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("Buy", true, "Buy", "arial", 12, 105, 4, Blue)!="") {BuyMoved = True;Print("BuyMoved");}
if ( !ÏåðåìåùåíèåÝÓ && isMovedLabel("Sell", true, "Sell", "arial", 12, 105, 24, Red)!="") {SellMoved = True; Print("BuyMoved");}
//*************************************************************************************************************************
OrderPriceBS = OPBS (Symbol(), GlobalVariableGet ("MATF"),GlobalVariableGet ("Method"), GlobalVariableGet("GTimeB"),GlobalVariableGet("GTimeE"));
OrderPriceSS = OPSS (Symbol(), GlobalVariableGet ("MATF"),GlobalVariableGet ("Method"), GlobalVariableGet("GTimeB"),GlobalVariableGet("GTimeE"));
// if (OrderPriceBS ==0) {OrderPriceBS = (1-PendingDistance)* iHigh(Symbol(),PERIOD_D1,0) + PendingDistance * iLow(Symbol(),PERIOD_D1,0) ;}
// if (OrderPriceSS ==0) {OrderPriceSS = (1-PendingDistance)* iLow(Symbol(),PERIOD_D1,0) + PendingDistance * iHigh(Symbol(),PERIOD_D1,0);}
if (OrderPriceBS ==0) {OrderPriceBS = iHigh(Symbol(),PERIOD_D1,0);}
if (OrderPriceSS ==0) {OrderPriceSS = iLow(Symbol(),PERIOD_D1,0);}
//****************************************************************
//*************************************************************************************************************************
CommentString = CommentString + StringConcatenate ("\n**", Version,"** ", "Risk:",DoubleToStr(Risk,1)," MaxLotSize:",DoubleToStr(MaxLotSize,2) );
// CommentString = CommentString + StringConcatenate (" OrderPriceBS:",OrderPriceBS, " OrderPriceSS:", OrderPriceSS, "\nLbMoved:",LbMoved, " LsMoved:",LsMoved);
//******************************************************************************************
//********************************************************
int d1=0, d2=0;
if (TimeDayOfWeek(iTime(NULL, MA_TF, 1)) == 0) { d1 =1; d2 =1;} // ÅÑËÈ ñåãîäíÿ ÏÍ è ïðåä äåíü ÂÑÊ
if (TimeDayOfWeek(iTime(NULL, MA_TF, 2)) == 0) { d1 =0; d2 =1;} // ÅÑËÈ ñåãîäíÿ Âò è ïðåä äåíü ÏÍ
color BuyStopLineColor = Blue ;
//********************************************************
//********************************************************
//void DrawLine (string LineName, bool magnet , datetime Time1,double Price1, datetime Time2,double Price2, bool draw, color LineColor, int LineStyle, bool TrendLine, bool Ray) // Íàõîäèì ñâîþ ëèíèþ. Åñëè öåíà äðóãàÿ ìåíÿåì ëèíèþ. Åñëè ëèíèè ííåò - Ðèñóåì íîâóþ.
// DrawLine("BuyStopD" ,b==0 && bs==0 , 0, LinePrice,0, 0, ( bs > 0) || b>0 || ( OrdersPriceBS >0), BuyStopLineColor, 4, false, false ) ;
if ((UseLibrary && bs + bl+ b == 0) )
{
DrawLine("BuyStopD" ,(LbMoved && (b+bs+bl==0) && ÑëåäèòüÇàÓðîâíåì) , 0, OrderPriceBS,0, 0, BuyMoved || Lb, BuyStopLineColor, 4, false, false ) ;
double OrdersPriceBSSL = MathMin(iLow(Symbol(), PERIOD_D1,0), iLow(Symbol(), PERIOD_D1,ÑòîïÓðîâåíüÏîÄíþ) );
DrawLine("BSTPD1" , (b+bs+bl==0) , 0, ObjectGet("BuyStopD", OBJPROP_PRICE1) + MathAbs((TP2Level -1) * (ObjectGet("BuyStopD", OBJPROP_PRICE1) - OrdersPriceBSSL)) ,0,0, (ObjectFind ("BuyStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=1), BuyStopLineColor, 3, false, false ) ;
DrawLine("BSTPD2" , (b+bs+bl==0) , 0, ObjectGet("BuyStopD", OBJPROP_PRICE1) + MathAbs((TP3Level -1) * (ObjectGet("BuyStopD", OBJPROP_PRICE1) - OrdersPriceBSSL)) ,0,0, (ObjectFind ("BuyStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=2), BuyStopLineColor, 3, false, false ) ;
DrawLine("BSTPD3" , (b+bs+bl==0) , 0, ObjectGet("BuyStopD", OBJPROP_PRICE1) + MathAbs((TP4Level -1) * (ObjectGet("BuyStopD", OBJPROP_PRICE1) - OrdersPriceBSSL)) ,0,0, (ObjectFind ("BuyStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=3), BuyStopLineColor, 3, false, false ) ;
if (ObjectGet("BuyStopD", OBJPROP_PRICE1) < Bid) {OrdersPriceBSSL =2 *ObjectGet("BuyStopD", OBJPROP_PRICE1)- OrdersPriceBSSL;}
DrawLine("BSSLD" , true|| (LbMoved && (b+bs+bl==0)) , 0, OrdersPriceBSSL ,0, 0, (ObjectFind ("BuyStopD") ==0) && OrdersPriceBSSL >0, BuyStopLineColor, 3, false, false ) ;
}
if (OrderBTP1 == 0) {OrderBTP1 = ObjectGet("BuyStopD", OBJPROP_PRICE1) + (TP2Level -1) * (ObjectGet("BuyStopD", OBJPROP_PRICE1) - iLow(Symbol(), PERIOD_D1,0)) ; }
if (OrderBTP2 == 0) {OrderBTP2 = ObjectGet("BuyStopD", OBJPROP_PRICE1) + (TP3Level -1) * (ObjectGet("BuyStopD", OBJPROP_PRICE1) - iLow(Symbol(), PERIOD_D1,0)) ; }
if (OrderBTP3 == 0) {OrderBTP3 = ObjectGet("BuyStopD", OBJPROP_PRICE1) + (TP4Level -1) * (ObjectGet("BuyStopD", OBJPROP_PRICE1) - iLow(Symbol(), PERIOD_D1,0)) ; }
if (bl + bs + b > 0 )
{
DrawLine("BuyStopD" ,b>0 || (bs+bl >0 && LbMoved && ÑëåäèòüÇàÓðîâíåì) , 0, OrderPriceB,0, 0, OrderPriceB>0, BuyStopLineColor, 4, false, false ) ;
DrawLine("BSTPD1" , false , 0, OrderBTP1 ,0,0, (ObjectFind ("BuyStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=1), BuyStopLineColor, 3, false, false ) ;
DrawLine("BSTPD2" , false , 0, OrderBTP2 ,0,0, (ObjectFind ("BuyStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=2), BuyStopLineColor, 3, false, false ) ;
DrawLine("BSTPD3" , false , 0, OrderBTP3 ,0,0, (ObjectFind ("BuyStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=3), BuyStopLineColor, 3, false, false ) ;
DrawLine("BSSLD" , false , 0, OrderPriceBSL ,0, 0, (ObjectFind ("BuyStopD") ==0) , BuyStopLineColor, 3, false, false ) ;
}
//********************************************************
//********************************************************
color SellStopLineColor = Red ;
//********************************************************
//********************************************************
//********************************************************
// DrawLine("SellStopD" ,s==0 && ss==0 , 0, LinePrice,0, 0,( ss > 0) || s >0 || ( OrdersPriceSS >0), SellStopLineColor, 4, false, false ) ;
if ((UseLibrary && ss+s +sl == 0) )
{
DrawLine("SellStopD" ,LsMoved && s+ss + sl ==0 && ÑëåäèòüÇàÓðîâíåì , 0, OrderPriceSS,0, 0,Ls || SellMoved, SellStopLineColor, 4, false, false ) ;
double OrdersPriceSSSL = MathMax( iHigh(Symbol(), PERIOD_D1,0), iHigh(Symbol(), PERIOD_D1,ÑòîïÓðîâåíüÏîÄíþ) );
DrawLine("SSTPD1" , s+ss + sl==0, 0, ObjectGet("SellStopD", OBJPROP_PRICE1) - (TP2Level -1) * (MathAbs( OrdersPriceSSSL - ObjectGet("SellStopD", OBJPROP_PRICE1)) ) ,0,0,(ObjectFind ("SellStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=1), SellStopLineColor, 3, false, false ) ;
DrawLine("SSTPD2" , s+ss + sl==0 , 0, ObjectGet("SellStopD", OBJPROP_PRICE1) - (TP3Level -1) * (MathAbs( OrdersPriceSSSL - ObjectGet("SellStopD", OBJPROP_PRICE1)) ),0,0,(ObjectFind ("SellStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=2), SellStopLineColor, 3, false, false ) ;
DrawLine("SSTPD3" , s+ss+ sl==0 , 0, ObjectGet("SellStopD", OBJPROP_PRICE1) - (TP4Level -1) * (MathAbs( OrdersPriceSSSL - ObjectGet("SellStopD", OBJPROP_PRICE1)) ),0,0,(ObjectFind ("SellStopD") ==0)&&(GlobalVariableGet ("TPLelels") >=3), SellStopLineColor, 3, false, false ) ;
if (ObjectGet("SellStopD", OBJPROP_PRICE1) > Bid) {OrdersPriceSSSL =2 * ObjectGet("SellStopD", OBJPROP_PRICE1) - Bid ;}
DrawLine("SSSLD" ,true||LsMoved && s+ss + sl==0 , 0, OrdersPriceSSSL ,0, 0,(ObjectFind ("SellStopD") ==0), SellStopLineColor, 3, false, false ) ;
}
if (OrderSTP1 ==0) {OrderSTP1 = ObjectGet("SellStopD", OBJPROP_PRICE1) - (TP2Level -1) * ( iHigh(Symbol(), PERIOD_D1,0) - ObjectGet("SellStopD", OBJPROP_PRICE1) );}
if (OrderSTP2 ==0) {OrderSTP2 = ObjectGet("SellStopD", OBJPROP_PRICE1) - (TP3Level -1) * ( iHigh(Symbol(), PERIOD_D1,0) - ObjectGet("SellStopD", OBJPROP_PRICE1) );}
if (OrderSTP3 ==0) {OrderSTP3 = ObjectGet("SellStopD", OBJPROP_PRICE1) - (TP4Level -1) * ( iHigh(Symbol(), PERIOD_D1,0) - ObjectGet("SellStopD", OBJPROP_PRICE1) );}
if ( ss+s +sl > 0)
{
DrawLine("SellStopD" ,s>0 || (ss + sl >0 && LsMoved && ÑëåäèòüÇàÓðîâíåì) , 0, OrderPriceS,0, 0,OrderPriceS>0, SellStopLineColor, 4, false, false ) ;
DrawLine("SSTPD1" ,false, 0, OrderSTP1 ,0,0,(OrderSTP1>0)&&(GlobalVariableGet ("TPLelels") >=1), SellStopLineColor, 3, false, false ) ;
DrawLine("SSTPD2" ,false , 0, OrderSTP2,0,0,(OrderSTP2>0)&&(GlobalVariableGet ("TPLelels") >=2), SellStopLineColor, 3, false, false ) ;
DrawLine("SSTPD3" ,false, 0, OrderSTP3,0,0,(OrderSTP3>0)&&(GlobalVariableGet ("TPLelels") >=3), SellStopLineColor, 3, false, false ) ;
DrawLine("SSSLD" ,false , 0, OrderPriceSSL ,0, 0,(ObjectFind ("SellStopD") ==0), SellStopLineColor, 3, false, false ) ;
}
//************************************************************************
//************************************************************************
//************************************************************************
//*******************************************************************************************
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("DeleteBS", true, "Del", "arial", 12, -5, 4, Blue)!="") { DeleteBS = !DeleteBS;}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("DeleteSS", true, "Del", "arial", 12, -5, 24, Red)!="") { DeleteSS = !DeleteSS;}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("BÁó", true, "Áó", "arial", 12, -30, 4, BÁóColor)!="") { if (b>0) {BÁó = True;}}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("SÁó", true, "Áó", "arial", 12, -30, 24, SÁóColor)!="") { if (s>0) {SÁó = True;}}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("BClo", true, "bClo", "arial", 12, -70, 4, BCloColor)!="") { BClo = True;}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("SClo", true, "sClo", "arial", 12, -70, 24, SCloColor)!="") { SClo = True;}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("DeBS", true, "de", "arial", 12, 75, 4, DeBSColor)!="") {if (b+bs+bl==0) { DeBS = !DeBS; Lb = false;}}
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("DeSS", true, "de", "arial", 12, 75, 24, DeSSColor)!="") {if (s+ss+sl==0) { DeSS = !DeSS; Ls = false;}}
if (s+ss+sl==0) {DeSS = false;}
if (b+bs+bl==0) {DeBS = false;}
//CommentString = CommentString+ StringConcatenate("DeleteSS ",DeleteSS, " DeleteBS",DeleteBS );
if (DeSS && s+ss+sl==0 )
{
Print ("**** DeSS *****", DeSS);
if (ObjectFind("SellStopD") ==0) {ObjectDelete("SellStopD");}
if (ObjectFind("SSSLD") ==0) {ObjectDelete("SSSLD"); }
// Ls = false;
}
if (DeBS && b+bs+bl==0)
{
Print ("**** DeBS *****", DeBS);
if (ObjectFind("BuyStopD")==0 ) { ObjectDelete("BuyStopD");}
if (ObjectFind( "BSSLD")==0) {ObjectDelete("BSSLD");}
// Lb = false;
}
for(int m=0;m<ObjectsTotal(EMPTY);m++)
{
if (ObjectFind (ObjectName(m))!=0) {continue;}
string name = ObjectName(m) ;
if ( DeSS &&( ObjectFind ("SellStopD")==-1) && ( ObjectFind ("SSSLD")==-1) )
{DeSS = false;
// if (StringFind(name,"SSTPD",0) !=-1) {Print(name,ObjectDelete(name) );}
if ( ObjectFind ("SSTPD1")==0){ Print("SSTPD1", " ", ObjectDelete("SSTPD1") );}
if ( ObjectFind ("SSTPD2")==0){ Print("SSTPD2"," ",ObjectDelete("SSTPD2") );}
if ( ObjectFind ("SSTPD3")==0){ Print("SSTPD3"," ",ObjectDelete("SSTPD3") );}
if ( ObjectFind ("SSTPD4")==0){ Print("SSTPD4"," ",ObjectDelete("SSTPD4") );}
if ( ObjectFind ("SSTPD5")==0){ Print("SSTPD5"," ",ObjectDelete("SSTPD5") );}
}
if ( DeBS && ( ObjectFind ("BuyStopD")==-1) && ( ObjectFind ("BSSLD")==-1) )
{DeBS = false;
if ( ObjectFind ("BSTPD1")==0){ Print("BSTPD1"," ",ObjectDelete("BSTPD1") );}
if ( ObjectFind ("BSTPD2")==0){ Print("BSTPD2", " ",ObjectDelete("BSTPD2") );}
if ( ObjectFind ("BSTPD3")==0){ Print("BSTPD3"," ",ObjectDelete("BSTPD3") );}
if ( ObjectFind ("BSTPD4")==0){ Print("BSTPD4"," ",ObjectDelete("BSTPD4") );}
if ( ObjectFind ("BSTPD5")==0){ Print("BSTPD5"," ",ObjectDelete("BSTPD5") );}
// if (StringFind(name,"BSTPD",0) !=-1) { Print(name,ObjectDelete(name) );}
}
}
//=============================================================================================
//*******************************************************************************************
OrderPriceHigh = ObjectGet("BuyStopD", OBJPROP_PRICE1);
string B_ = "B";
if (bs > 0) { B_ = "Bs";}
if (bl > 0) { B_ = "Bl";}
if (b > 0) { B_ = b;}
color B_color = SkyBlue;
if (OrderPriceHigh > Bid && bs==0 && b==0 && bl==0) { B_color = MidnightBlue; int BOp = OP_BUYSTOP;}
if (OrderPriceHigh < Bid && bs==0 && b==0 && bl==0) { B_color = Yellow; BOp = OP_BUYLIMIT;}
if (bl >0 || bs > 0 || b > 0) { B_color = Blue; }
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("Bs", true, B_, "arial", 16, 30, 0, B_color) !="" ) { MovedBs = True;}
if ( (b + bs + bl) == GlobalVariableGet ("TPLelels") ) {MovedBs = False; BuyMoved = false;}
//*************************************************************************************************************************
//**************** Ðàñ÷åò ðàçìåðà ëîòà ****************
OrderPriceLow = ObjectGet("BSSLD", OBJPROP_PRICE1);
if (BuyMoved) {OrderPriceHigh = Ask; OrderPriceLow = iLow(Symbol(), PERIOD_D1,0);}
MinLot = MarketInfo (Symbol(),MODE_MINLOT);
FreeMargin = AccountFreeMargin();
Equity = AccountEquity();
Balance = AccountBalance();
TickPrice = MarketInfo(Symbol(), MODE_TICKVALUE);
StepLots=MarketInfo(Symbol(),MODE_LOTSTEP);
if(StepLots<=0.009) DigLots=3; else if(StepLots<=0.09) DigLots=2; else if(StepLots<=0.9) DigLots=1; else DigLots=0;
if (Risk > 0 && OrderPriceHigh - OrderPriceLow >0) // Åñëè çàäàíî óïðàâëåíèå ðèñêîì
{
LotSizeCalc = NormalizeDouble(( Risk*FreeMargin/ GlobalVariableGet ("TPLelels")) / ( 100*(OrderPriceHigh - OrderPriceLow) /Point * TickPrice ), DigLots);
if (LotSizeCalc < MarketInfo (Symbol(),MODE_MINLOT) ) {LotSizeCalc = MarketInfo (Symbol(),MODE_MINLOT); }
if (LotSizeCalc > MaxLotSize) {LotSizeCalc = MaxLotSize;}
CommentString = CommentString +StringConcatenate ("\nBUY ++äî ñòîïà:", DoubleToStr((OrderPriceHigh - OrderPriceLow) /Point,0 ),
"ïï ++ LotSizeCalc: ", LotSizeCalc," +++", "Ïîòåðè:",NormalizeDouble ( GlobalVariableGet ("TPLelels") * TickPrice * LotSizeCalc * (OrderPriceHigh - OrderPriceLow) /Point,1) );
LotSize = LotSizeCalc;
}
//**************** Ðàñ÷åò ðàçìåðà ëîòà****************
//*******************************************************************************************
if ( ObjectFind("BuyStopD") ==0 && MovedBs)
{
for (i=b + bs+bl+1; i <= GlobalVariableGet ("TPLelels"); i++ )
{
int n=0;
while (IsTradeAllowed() && n<3 && (b + bs +bl < GlobalVariableGet ("TPLelels")))
{
int ticket = OrderSend (Symbol(),BOp, LotSize, NormalizeDouble(ObjectGet("BuyStopD", OBJPROP_PRICE1 ),Digits), 0, NormalizeDouble(ObjectGet("BSSLD", OBJPROP_PRICE1),Digits ), NormalizeDouble(ObjectGet("BSTPD"+i, OBJPROP_PRICE1),Digits ),DoubleToStr(i,0),MagicNo,0,CLR_NONE);
if (OrderSelect(ticket, SELECT_BY_TICKET ) ) {break;}
else { int Err = GetLastError(); Print(Err);Sleep(1000);n++; }
}
}
}
//***************************************************************
if ((ObjectFind ("BuyStopD") ==0) && BuyMoved)
{
for (i=b + bl + bs+1; i <= GlobalVariableGet ("TPLelels"); i++ )
{
n=0;
while (IsTradeAllowed() && n<3 && (b + bs < GlobalVariableGet ("TPLelels")))
{
ticket = OrderSend (Symbol(),OP_BUY, LotSize, Ask, 0, 0, 0,DoubleToStr(i,0),MagicNo,0,CLR_NONE);
// ticket = OrderSend (Symbol(),OP_BUY, LotSize, Ask, 0, NormalizeDouble(ObjectGet("BSSLD", OBJPROP_PRICE1),Digits ), NormalizeDouble(ObjectGet("BSTPD"+i, OBJPROP_PRICE1),Digits ),DoubleToStr(i,0),MagicNo,0,CLR_NONE);
if (OrderSelect(ticket, SELECT_BY_TICKET ) )
{ break;}
else { Err = GetLastError(); Print(Err);Sleep(1000);n++; }
}
}
BuyMoved = false;
}
//***************************************************************
//if (Symbol() == "GBPUSD") {Print ("44444444") ;}
//*************************************************************************************************************************
//=============================================================================================
OrderPriceLow = ObjectGet("SellStopD", OBJPROP_PRICE1);
string S_ = "S";
if (ss > 0) { S_ = "Ss";}
if (sl > 0) { S_ = "Sl";}
if (s > 0) { S_ = s;}
color S_color = Salmon;
if (OrderPriceLow < Bid && sl==0 && ss==0 && s == 0 ) { S_color = Magenta; int SOp = OP_SELLSTOP;}
if (OrderPriceLow > Bid && sl==0 && ss==0 && s == 0 ) { S_color = Yellow; SOp = OP_SELLLIMIT;}
if (ss > 0 || s > 0 || sl >0) { S_color = Red; }
if (!ÏåðåìåùåíèåÝÓ && isMovedLabel("Ss", true, S_, "arial", 16, 30, 20, S_color) !="" ) { MovedSs = True;}
if ( (s + ss +sl) == GlobalVariableGet ("TPLelels") ) {MovedSs = False; SellMoved = false;}
//*******************************************************************************************
//**************** Ðàñ÷åò ðàçìåðà ëîòà ****************
OrderPriceHigh = ObjectGet("SSSLD", OBJPROP_PRICE1);
if (SellMoved) {OrderPriceLow = Bid; OrderPriceHigh = iHigh(Symbol(), PERIOD_D1,0);}
if (Risk > 0 && OrderPriceHigh - OrderPriceLow >0) // Åñëè çàäàíî óïðàâëåíèå ðèñêîì
{
LotSizeCalc = NormalizeDouble(( Risk*FreeMargin/ GlobalVariableGet ("TPLelels")) / ( 100*(OrderPriceHigh - OrderPriceLow) /Point * TickPrice ), DigLots);
if (LotSizeCalc < MarketInfo (Symbol(),MODE_MINLOT) ) {LotSizeCalc = MarketInfo (Symbol(),MODE_MINLOT); }
if (LotSizeCalc > MaxLotSize) {LotSizeCalc = MaxLotSize;}
CommentString = CommentString +StringConcatenate ("\nSELL ++äî ñòîïà:", DoubleToStr((OrderPriceHigh - OrderPriceLow) /Point,0 ),
"ïï ++ LotSizeCalc: ", LotSizeCalc," +++", "Ïîòåðè:",NormalizeDouble ( GlobalVariableGet ("TPLelels") * TickPrice * LotSizeCalc * (OrderPriceHigh - OrderPriceLow) /Point,1) );
LotSize = LotSizeCalc;
}
//**************** Ðàñ÷åò ðàçìåðà ëîòà****************
//*******************************************************************************************
if ( ObjectFind("SellStopD") ==0 && MovedSs)
{
for (i=s + ss + sl +1; i <= GlobalVariableGet ("TPLelels"); i++ )
{
n=0;
while (IsTradeAllowed() && n<3 && (s + ss + sl < GlobalVariableGet ("TPLelels")) )
{
ticket = OrderSend (Symbol(),SOp, LotSize, NormalizeDouble(ObjectGet("SellStopD", OBJPROP_PRICE1),Digits ), 0, NormalizeDouble(ObjectGet("SSSLD", OBJPROP_PRICE1),Digits ), NormalizeDouble(ObjectGet("SSTPD"+i, OBJPROP_PRICE1),Digits ),DoubleToStr(i,0),MagicNo,0,CLR_NONE);
if (OrderSelect(ticket, SELECT_BY_TICKET ) ) {break;}
else { Err = GetLastError(); Print(Err);Sleep(1000);n++; }
}
}
}
//*******************************************************************************************
if ( ObjectFind("SellStopD") ==0 && SellMoved)
{
for (i=s + ss +sl +1; i <= GlobalVariableGet ("TPLelels"); i++ )
{
n=0;
while (IsTradeAllowed() && n<3 && (s + ss+sl < GlobalVariableGet ("TPLelels")) )
{
ticket = OrderSend (Symbol(),OP_SELL, LotSize, Bid, 0, 0, 0,DoubleToStr(i,0),MagicNo,0,CLR_NONE);
// ticket = OrderSend (Symbol(),OP_SELL, LotSize, Bid, 0, NormalizeDouble(ObjectGet("SSSLD", OBJPROP_PRICE1),Digits ), NormalizeDouble(ObjectGet("SSTPD"+i, OBJPROP_PRICE1),Digits ),DoubleToStr(i,0),MagicNo,0,CLR_NONE);
if (OrderSelect(ticket, SELECT_BY_TICKET ) ) {break;}
else { Err = GetLastError(); Print(Err);Sleep(1000);n++; }
}
}
SellMoved = false;
}
//if (Symbol() == "GBPUSD") {Print ("333333333") ;}
//*******************************************************************************************
if (s+ss +sl>0)
{
for (i = OrdersTotal(); i >= 0; i-- )
{
if (!OrderSelect(i, SELECT_BY_POS ) ) {continue;}
// if (Symbol() == "GBPUSD") {Print(i," ",OrderTicket()) ;}
if ( OrderMagicNumber() == MagicNo && OrderSymbol() == Symbol() )
{
if ( IsTradeAllowed()&& ( (OrderType() ==OP_SELLSTOP) || (OrderType() ==OP_SELLLIMIT)) && (MathAbs(OrderOpenPrice() - ObjectGet("SellStopD", OBJPROP_PRICE1 )) > MinStep * Point / k) )
{//Sleep(sleep);
//Print("4 ",OrderOpenPrice()," ", ObjectGet("SellStopD", OBJPROP_PRICE1 ));
if (OrderModify(OrderTicket(),ObjectGet("SellStopD", OBJPROP_PRICE1 ), OrderStopLoss(),OrderTakeProfit(), OrderExpiration(),CLR_NONE )) { break;}
}
/*
if ( (OrderType() == OP_SELL) && (Ask < ObjectGet("SSTPD"+1, OBJPROP_PRICE1 ) )) { ObjectSet("SSSLD", OBJPROP_PRICE1, OrderOpenPrice()) ; }
if ( (OrderType() == OP_SELL) && (Ask < ObjectGet("SSTPD"+2, OBJPROP_PRICE1 ) )) { ObjectSet("SSSLD", OBJPROP_PRICE1, ObjectGet("SSTPD"+1, OBJPROP_PRICE1 )) ; }
if ( (OrderType() == OP_SELL) && (Ask < ObjectGet("SSTPD"+3, OBJPROP_PRICE1 ) )) { ObjectSet("SSSLD", OBJPROP_PRICE1, ObjectGet("SSTPD"+2, OBJPROP_PRICE1 )) ; }
*/
if ( (OrderType() == OP_SELL) && s == GlobalVariableGet ("TPLelels") && (Bid <= ObjectGet("SSTPD1", OBJPROP_PRICE1 )) )
{
Print("65432 Ïåðåâîä â áó");
ObjectSet("SSSLD", OBJPROP_PRICE1, OrderOpenPrice()-10*Point / k) ; }
if ( (OrderType() == OP_SELL) && s == GlobalVariableGet ("TPLelels")-1 && Bid < OrderOpenPrice() ) { ObjectSet("SSSLD", OBJPROP_PRICE1, OrderOpenPrice()-10*Point / k) ; }
if ( (OrderType() == OP_SELL) && s == GlobalVariableGet ("TPLelels")-2 && Bid < ObjectGet("SSTPD1", OBJPROP_PRICE1 ) ) { ObjectSet("SSSLD", OBJPROP_PRICE1, ObjectGet("SSTPD1", OBJPROP_PRICE1 )) ; }
// if ( (OrderType() == OP_SELL) && s == 1 ) { ObjectSet("SSSLD", OBJPROP_PRICE1, ObjectGet("SSTPD2", OBJPROP_PRICE1 )) ; }
// if ( ((UseZigZag_Pointer4BU && ZZUp) || BuyStop )&& MoveToBu && (OrderType() == OP_SELL) && s == 3 && Bid < OrderOpenPrice()- 20*Point /k )
if ( (OrderType() == OP_SELL) || (OrderType() ==OP_SELLSTOP) || (OrderType() ==OP_SELLLIMIT))
{
if (!OrderSelect(i, SELECT_BY_POS ) ) {continue;}
//Ïåðåâîä â Áó - ïóòåì ïåðåìåùåíèÿ ëèíèè
if ( (OrderType() == OP_SELL) && s>0 && SÁó && (OrderStopLoss() ==0 || OrderStopLoss() > OrderOpenPrice()-10*Point / k) ) {ObjectSet("SSSLD", OBJPROP_PRICE1, OrderOpenPrice()-10*Point / k) ; }
if (IsTradeAllowed()&& (!ÁåçÑòîïîâ || ( ÁåçÑòîïîâ && (ObjectGet("SSSLD", OBJPROP_PRICE1 ) <= OrderOpenPrice())) ) && ( MathAbs( OrderStopLoss() - ObjectGet("SSSLD", OBJPROP_PRICE1 )) > MinStep * Point / k) )
{//Sleep(sleep);
// Print("5 ",OrderStopLoss()," ", ObjectGet("SSSL", OBJPROP_PRICE1 ) );
if (OrderModify(OrderTicket(),OrderOpenPrice(), ObjectGet("SSSLD", OBJPROP_PRICE1 ),OrderTakeProfit() , OrderExpiration(),CLR_NONE ) ) {break;}
}
if (IsTradeAllowed()&& OrderStopLoss() > OrderOpenPrice()&& ÁåçÑòîïîâ && (ObjectGet("SSSLD", OBJPROP_PRICE1 ) > OrderOpenPrice()) )
{//Sleep(sleep);
// Print("51 ",OrderStopLoss()," ", ObjectGet("SSSL", OBJPROP_PRICE1 ) );
if (OrderModify(OrderTicket(),OrderOpenPrice(), 0,OrderTakeProfit() , OrderExpiration(),CLR_NONE ) ) {break;}
}
for ( l=1; l <= 10; l++ )
{
if (IsTradeAllowed()&& StrToInteger( OrderComment()) == l && (MathAbs (OrderTakeProfit() - ObjectGet("SSTPD"+l, OBJPROP_PRICE1 ) ) > MinStep * Point / k ) )
{//Sleep(sleep);
//Print("6 ", OrderTakeProfit() ," ", ObjectGet("SSTPD"+l, OBJPROP_PRICE1 ));
OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss(),ObjectGet("SSTPD"+l, OBJPROP_PRICE1 ), OrderExpiration(),CLR_NONE );
}
if ( IsTradeAllowed()&& StrToInteger( OrderComment()) == l && (OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)&& DeleteSS && (ss+sl>0) )
{
if (OrderDelete(OrderTicket(),CLR_NONE )) { break;}
}
if ( IsTradeAllowed()&& StrToInteger( OrderComment()) == l && OrderType() == OP_SELL && SClo && (s>0) )
{
if (OrderClose(OrderTicket(), OrderLots(), Ask, 0, CLR_NONE )) { continue;}
else {Sleep(sleep); continue;}
}
}
}
}
}
}
//***************************************************************
// if (Symbol() == "GBPUSD") {Print ("55555555") ;}
if (b+bs+bl>0)
{
for (i = OrdersTotal(); i >= 0; i-- )
{
if (!OrderSelect(i, SELECT_BY_POS ) ) {continue;}
if ( OrderMagicNumber() == MagicNo && OrderSymbol() == Symbol() )
{
if (IsTradeAllowed()&& (OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT )&& (MathAbs(OrderOpenPrice() - ObjectGet("BuyStopD", OBJPROP_PRICE1 )) > MinStep * Point / k) )
{Sleep(sleep);
if (OrderModify(OrderTicket(),ObjectGet("BuyStopD", OBJPROP_PRICE1 ), OrderStopLoss(),OrderTakeProfit(), OrderExpiration(),CLR_NONE )) {break;}
}
//if (Symbol() == "GBPUSD") {Print("1 ", OrderOpenPrice() ," ", ObjectGet("BuyStopD", OBJPROP_PRICE1 ));}
if ( (OrderType() == OP_BUY || OrderType() ==OP_BUYSTOP) || OrderType() == OP_BUYLIMIT )
{
/*
if ( (OrderType() == OP_BUY) && Bid > ObjectGet("BSTPD"+1, OBJPROP_PRICE1 ) ) { ObjectSet("BSSLD", OBJPROP_PRICE1, OrderOpenPrice()) ; }
if ( (OrderType() == OP_BUY) && Bid > ObjectGet("BSTPD"+2, OBJPROP_PRICE1 ) ) { ObjectSet("BSSLD", OBJPROP_PRICE1, ObjectGet("BSTPD"+1, OBJPROP_PRICE1 )) ; }
if ( (OrderType() == OP_BUY) && Bid > ObjectGet("BSTPD"+3, OBJPROP_PRICE1 ) ) { ObjectSet("BSSLD", OBJPROP_PRICE1, ObjectGet("BSTPD"+2, OBJPROP_PRICE1 )) ; }
*/
// if ( (OrderType() == OP_BUY) && b == 1 ) { ObjectSet("BSSLD", OBJPROP_PRICE1, ObjectGet("BSTPD2", OBJPROP_PRICE1 )) ; }
if ( (OrderType() == OP_BUY) && b == GlobalVariableGet ("TPLelels")-2 && Bid > ObjectGet("BSTPD1", OBJPROP_PRICE1 ) )
{ ObjectSet("BSSLD", OBJPROP_PRICE1, ObjectGet("BSTPD1", OBJPROP_PRICE1 )) ; }
if ( (OrderType() == OP_BUY) && b == GlobalVariableGet ("TPLelels")-1 && Bid > OrderOpenPrice()) { ObjectSet("BSSLD", OBJPROP_PRICE1, OrderOpenPrice()+10*Point / k) ; }
if ( (OrderType() == OP_BUY) && b == GlobalVariableGet ("TPLelels") && (Bid >= ObjectGet("BSTPD1", OBJPROP_PRICE1 )) )
{
Print("98765 Ïåðåâîä â áó");
ObjectSet("BSSLD", OBJPROP_PRICE1, OrderOpenPrice()+10*Point / k) ; }
// if ( ((UseZigZag_Pointer4BU && ZZDn) || SellStop ) && MoveToBu && (OrderType() == OP_BUY) && b == 3 && Bid > OrderOpenPrice() + 20* Point / k )
if (!OrderSelect(i, SELECT_BY_POS ) ) {continue;}
//Ïåðåâîä â Áó - ïóòåì ïåðåìåùåíèÿ ëèíèè
if ( (OrderType() == OP_BUY) && b>0 && BÁó && OrderStopLoss()< OrderOpenPrice()+10*Point / k) {ObjectSet("BSSLD", OBJPROP_PRICE1, OrderOpenPrice()+10*Point / k) ; }
if ( IsTradeAllowed()&& (!ÁåçÑòîïîâ || ( ÁåçÑòîïîâ && (ObjectGet("BSSLD", OBJPROP_PRICE1 ) >= OrderOpenPrice()) )) && ( MathAbs(OrderStopLoss() - ObjectGet("BSSLD", OBJPROP_PRICE1 ) ) > MinStep * Point / k ) )
{Sleep(sleep);
//if (Symbol() == "GBPUSD") {Print("2 ", OrderStopLoss() ," ", ObjectGet("BSSLD", OBJPROP_PRICE1 ) );}
if (OrderModify(OrderTicket(),OrderOpenPrice(), ObjectGet("BSSLD", OBJPROP_PRICE1 ),OrderTakeProfit() , OrderExpiration(),CLR_NONE )) { break;}
}
if (IsTradeAllowed()&& OrderStopLoss() < OrderOpenPrice() && ÁåçÑòîïîâ && (ObjectGet("BSSLD", OBJPROP_PRICE1 ) < OrderOpenPrice()) )
{//Sleep(sleep);
if (OrderModify(OrderTicket(),OrderOpenPrice(), 0,OrderTakeProfit() , OrderExpiration(),CLR_NONE ) ) {break;}
}
for ( l=1; l <= 10; l++ )
{
if (IsTradeAllowed()&& ( StrToInteger( OrderComment()) == l) && (MathAbs( OrderTakeProfit() - ObjectGet("BSTPD"+l, OBJPROP_PRICE1 ) ) > MinStep * Point / k ) )
{Sleep(sleep);
//if (Symbol() == "GBPUSD") {Print("3 ",OrderTakeProfit() ," ", ObjectGet("BSTP"+l, OBJPROP_PRICE1 ));}
if (OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss(),ObjectGet("BSTPD"+l, OBJPROP_PRICE1 ), OrderExpiration(),CLR_NONE )) { continue;}
}
if ( IsTradeAllowed()&& StrToInteger( OrderComment()) == l && (OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT )&& DeleteBS && (bs+bl>0) )
{
if (OrderDelete(OrderTicket(),CLR_NONE )) { break;}
}
if ( IsTradeAllowed()&& StrToInteger( OrderComment()) == l && OrderType() == OP_BUY && BClo && (b>0) )
{
if (OrderClose(OrderTicket(), OrderLots(), Bid, 0, CLR_NONE )) { continue;}
else {Sleep(sleep); continue;}
}
}
}
}
}
}
////*************if ( (bs > 0 || b > 0) && ObjectFind("BSSL")!=0 && ObjectGet("BuyStopD", OBJPROP_PRICE1 ) < OrderOpenPrice() )
//=============================================================================================
//=============================================================================================
string ÍîâûéÁàð = "";
if ( isNewBar(MA_TF) ) { ÍîâûéÁàð = "\n************** Íîâûé Áàð *************" ;}
Comment( CommentString , ÍîâûéÁàð , "\n ", Còðàòåãèÿ," ","Ìåòîä:", DoubleToStr(GlobalVariableGet ("Method"),0), " POD:", DoubleToStr(GlobalVariableGet ("PendingOrderDistance"),2),"\n Îáðàáîòàíî çà, ìÑåê " , GetTickCount() - st);
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
---