cm_EA Trailing v20 mql

Author: Copyright © 2014-2020, cmillion@narod.ru
Profit factor:
0.00
12 Views
1 Downloads
0 Favorites
cm_EA Trailing v20 mql
ÿþ//+------------------------------------------------------------------+

//|                                                 TrailingStop.mq4 |

//|                              Copyright © 2014, Khlystov Vladimir |

//|                                               http://cmillion.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2014-2020, cmillion@narod.ru"

#property link      "http://cmillion.ru"

#property strict

#property description ""

//--------------------------------------------------------------------



enum _tral_ 

{

   t0= 0, //Buy

   t1= 1, //Sell

   t2= 2, //Buy+Sell

};

input _tral_  tral = 2;     //@07@5H8BL B@0;8BL



enum tral_ 

{

   l0= 0, //off

   l1= 1, //Candle

   l2= 2, //Fractals

   l3= 3, //ATR

   l4= 4, //Parabolic

   l5= 5, //pips

};



extern string  _________________Loss__________________             = "";



input tral_    TrallLoss               = 0;     // B@0; C1KB>G=KE A45;>: (TralPortfel 83=>@8@C5BAO) 

extern int     delta_Loss              = 5;     // >BABC? >B C@>2=O D@0:B0;0 8;8 A25G8 ....

input ENUM_TIMEFRAMES TFLoss           = 0;     // B09<D@59< A25G59, SAR 8;8 D@0:B0;>2 4;O B@0;0 C1KB>G=KE A45;>:

extern int     level_Loss              = 100;   // G8A;> ?8?A ?@8 TrallLoss = pips



extern string  __________________Profit__________________      = "";

input tral_    TralProfit              = 2;     // B@0; ?@>D8B=KE A45;>: (B@0;_>B_?>@BD5;L=>3>_?@>D8B0 = true, 

extern int     delta_profit            = 10;    // >BABC?.>B.A25G8.D@0:B0;0 87<5@O5BAO 2 ?C=:B0E

input ENUM_TIMEFRAMES TFProfit         = 0;     // B09<D@59< A25G59, SAR 8;8 D@0:B0;>2 4;O B@0;0 ?@81K;L=KE A45;>:

extern int     Start_Trall             = 1;     // ?@>D8B (2 ?C=:B0E) ?@8 :>B>@>< @07@5H05< @01>BC B@0;0

extern int     level_Profit            = 100;   // G8A;> ?8?A ?@8 TralProfit = pips



extern string  ____________________Break_even__________________    = "";

input tral_    NoLoss                  = 5;     // ?5@52>4 2 157C1KB>:

extern int     Min_Profit              = 10;    // <8=8<0;L=K9 ?@>D8B (2 ?C=:B0E) ?@8 ?5@52>45 2 157C1KB>:

extern int     level_NoLoss            = 100;   // G8A;> ?8?A ?@8 NoLoss = pips



extern string  _____________________Takeprofit__________________   = "";

extern int     Level_TP                = 0;      // B@0; Takeprofit 2 ?C=:B0E,  0 - >B:;



extern string  _____________________   = "";

extern int     Step_Trall              = 1;     //H03 B@0;0



enum _Portfel_ 

{

   p0= 0, //4;O :064>3> >@45@0 8=48284C0;L=> (for each order individually)

   p1= 1, //>B AC<<0@=>3> 157C1KB:0 =0?@02;5=8O (from the total breakeven)

};

input _Portfel_    TralPortfel         = 0;  //B>G:0 >BAG5B0 157C1KB:0



extern string  ________________        = "";

extern string  indicators                    = "";

string         parameters_Parabolic          = "";    //8A?>;L7C5BAO B>;L:> 5A;8 B@0; C1KB>G=KE A45;>:, B@0; ?@81K;L=KE A45;>: 8;8 157C1KB>: = 4

extern double  Step                          = 0.02;

extern double  Maximum                       = 0.2;



string         parameters_ATR                = "";    //8A?>;L7C5BAO B>;L:> 5A;8 B@0; C1KB>G=KE A45;>:, B@0; ?@81K;L=KE A45;>: 8;8 157C1KB>: = 3

extern int     period_ATR                    = 14;    // ?5@8>4 ATR 4;O B@59;8=30  



extern string  _______________               = "";



extern int     Magic                         = -1;    //Magic (All-1)



//--------------------------------------------------------------------

int STOPLEVEL,n;

datetime TimeBar;

bool visual,LANGUAGE=false;

long    X=5;

long    Y=25;

string  txt,Font        = "Arial";//"Times New Roman";

int     Width       = 10;

color colorWin = clrDarkBlue;//F25B >:=0

color colorWinR = clrYellow;//@0<:0 >:=0

color colorWinW = clrMidnightBlue;//F25B 2=CB@5==53> >:=0

color colorWinT = clrWhite;//F25B B5:AB0

color color_buy = clrBlue;

color color_sell = clrRed;

datetime t;

string AC;

bool redraw=false;

double MINLOT;

//--------------------------------------------------------------------

void OnInit()

{

   MINLOT = MarketInfo(Symbol(),MODE_MINLOT);

   visual = (IsVisualMode()||!IsTesting());

   if (visual) 

   {

      Comment("Start EA TrailingStop ",TimeToStr(TimeCurrent(),TIME_SECONDS));

      LANGUAGE=TerminalInfoString(TERMINAL_LANGUAGE)=="Russian";

      LabelCreate(0,"ts 1",0 ,5,10,CORNER_LEFT_LOWER,"© 2014-2020, https://cmillion.ru/",Font,Width,clrGray,0,ANCHOR_LEFT,false,false,true,0);

  }

   AC = " "+AccountCurrency();

   redraw=true;

   OnTick();

}

//--------------------------------------------------------------------

void OnDeinit(const int reason)

{      

   if (!IsTesting()) ObjectsDeleteAll(0,"ts");

   Comment("Closing EA TrailingStop ",TimeToStr(TimeCurrent(),TIME_SECONDS));

}

//--------------------------------------------------------------------

void OnTick()

{

   double AB=AccountBalance();

   double AE=AccountEquity();

   double FM=AccountFreeMargin();



   if (visual) 

   {

      if (ObjectFind("cm_WIN")==0)

      {

         if (X!=ObjectGetInteger(0,"cm_WIN",OBJPROP_XDISTANCE,0) ||

             Y!=ObjectGetInteger(0,"cm_WIN",OBJPROP_YDISTANCE,0))

         {

            X=ObjectGetInteger(0,"cm_WIN",OBJPROP_XDISTANCE,0);

            Y=ObjectGetInteger(0,"cm_WIN",OBJPROP_YDISTANCE,0);

            redraw=true;

         }

      }

      else

      {

         RectLabelCreate(0,"cm_WIN",0,X,Y,300,295,colorWin,colorWinR,STYLE_SOLID,1,false,true,true,0);redraw=true;

      }

      if (redraw)

      {

         redraw=false;

         long y=Y+10;

         RectLabelCreate(0,"ts 0_",0,X+1 ,Y+1,298,20,colorWinW,colorWinR,STYLE_SOLID,1,false,false,true,0);

         LabelCreate(0    ,"ts ver",0 ,X+10,y,CORNER_LEFT_UPPER,"TS v20","ARIAL BLACK",Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         LabelCreate(0,"ts Data",0,X+290,y,CORNER_LEFT_UPPER,"",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);y-=5;

         bool TradeAllowed=IsTradeAllowed();

         y+=30;

         LabelCreate(0,"ts Balance",0 ,X+10,y,CORNER_LEFT_UPPER,LANGUAGE?"0;0=A":"Balance",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         LabelCreate(0,"ts BalanceP",0,X+290,y,CORNER_LEFT_UPPER,"0.00$",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);

         y+=15;

         LabelCreate(0,"ts Equity",0 ,X+10,y,CORNER_LEFT_UPPER,LANGUAGE?"!@54AB20":"Equity",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         LabelCreate(0,"ts EquityP%",0,X+180,y,CORNER_LEFT_UPPER,"0.00%",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);

         LabelCreate(0,"ts EquityP",0,X+290,y,CORNER_LEFT_UPPER,"0.00$",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);

         y+=15;

         LabelCreate(0,"ts FreeMargin",0 ,X+10,y,CORNER_LEFT_UPPER,LANGUAGE?"!0>1>4=>":"FreeMargin",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         LabelCreate(0,"ts FreeMarginP",0,X+290,y,CORNER_LEFT_UPPER,"0.00$",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);

         y+=25;

         RectLabelCreate(0,"ts fon2" ,0,X+5,y,290,50,colorWinW,colorWinR,STYLE_SOLID,1,false,false,true,0);y-=10;

         EditCreate(0,"ts Positions",0,X+10,y,150,20,LANGUAGE?"B:@KBK5 ?>78F88":"Positions",Font,Width,ALIGN_CENTER,true,CORNER_LEFT_UPPER,colorWinR,colorWinW,colorWinT);

         y+=30;

         LabelCreate(0,"ts Buy",0 ,X+10,y,CORNER_LEFT_UPPER,"",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         //LabelCreate(0,"ts Buy1",0 ,X+290,y,CORNER_LEFT_UPPER,"",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);

         y+=20;

         LabelCreate(0,"ts Sell",0,X+10,y,CORNER_LEFT_UPPER,"",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         //LabelCreate(0,"ts Sell1",0 ,X+290,y,CORNER_LEFT_UPPER,"",Font,Width,colorWinT,0,ANCHOR_RIGHT,false,false,true,0);

         

         

         y+=25;

         RectLabelCreate(0,"ts fon3" ,0,X+5,y,290,135,colorWinW,colorWinR,STYLE_SOLID,1,false,false,true,0);y-=10;

         EditCreate(0,"ts tral profit",0,X+10,y,150,20,LANGUAGE?"0@0<5B@K":"Parameters",Font,Width,ALIGN_CENTER,true,CORNER_LEFT_UPPER,colorWinR,colorWinW,colorWinT);

         y+=30;

         color coltxt=clrGray;

         txt=LANGUAGE?""@0; ?@81K;L=KE":"tral profit";

         if (TralProfit==0) txt=StringConcatenate(txt,LANGUAGE?" >B:;NG5=":" off"); 

         else

         {

            coltxt=colorWinT;

            if (TralProfit==1) txt=StringConcatenate(txt,LANGUAGE?" ?> A25G0< ":" by candle ",StrPer(TFProfit)," +- ",delta_profit); 

            if (TralProfit==2) txt=StringConcatenate(txt,LANGUAGE?" ?> D@0:B0;0< ":" by fractals ",StrPer(TFProfit)," +- ",delta_profit); 

            if (TralProfit==3) txt=StringConcatenate(txt,LANGUAGE?" ?> ATR (":" by ATR (",period_ATR,") ",StrPer(TFProfit),"+- ",delta_profit); 

            if (TralProfit==4) txt=StringConcatenate(txt,LANGUAGE?" ?> ?0@01>;8:C (":" on the parabolic (",Step,",",Maximum,") ",StrPer(TFProfit)," +- ",delta_profit); 

            if (TralProfit==5) txt=StringConcatenate(txt," ",level_Profit," pips."); 

            if (Start_Trall!=0) txt=StringConcatenate(txt," Start ",Start_Trall," p"); 

         }

         LabelCreate(0,"ts Profit",0 ,X+10,y,CORNER_LEFT_UPPER,txt,Font,Width,coltxt,0,ANCHOR_LEFT,false,false,true,0);



         y+=20;

         txt=LANGUAGE?""@0; C1KB>G=KE":"tral loss";

         coltxt=clrGray;

         if (TrallLoss==0) txt=StringConcatenate(txt,LANGUAGE?" >B:;NG5=":" off");

         else

         {

            coltxt=colorWinT;

            if (TrallLoss==1) txt=StringConcatenate(txt,LANGUAGE?" ?> A25G0< ":" by candle ",StrPer(TFLoss)," +- ",delta_Loss); 

            if (TrallLoss==2) txt=StringConcatenate(txt,LANGUAGE?" ?> D@0:B0;0< ":" by fractals ",StrPer(TFLoss)," +- ",delta_Loss); 

            if (TrallLoss==3) txt=StringConcatenate(txt,LANGUAGE?" ?> ATR (":" by ATR (",period_ATR,") ",StrPer(TFLoss),"+- ",delta_Loss); 

            if (TrallLoss==4) txt=StringConcatenate(txt,LANGUAGE?" ?> ?0@01>;8:C (":" on the parabolic (",Step,",",Maximum,") ",StrPer(TFLoss)," +- ",delta_Loss); 

            if (TrallLoss==5) txt=StringConcatenate(txt," ",level_Loss," pips."); 

         }

         LabelCreate(0,"ts tl",0 ,X+10,y,CORNER_LEFT_UPPER,txt,Font,Width,coltxt,0,ANCHOR_LEFT,false,false,true,0);



         y+=20;

         txt=LANGUAGE?"5@52>4 2 157C1KB>:":"Break-even";

         coltxt=clrGray;

         if (NoLoss==0) txt=StringConcatenate(txt,LANGUAGE?" >B:;NG5=":" off");

         else

         {

            coltxt=colorWinT;

            if (NoLoss==1) txt=StringConcatenate(txt,LANGUAGE?" ?> A25G0< ":" by candle ",StrPer(TFProfit)," +- ",delta_profit); 

            if (NoLoss==2) txt=StringConcatenate(txt,LANGUAGE?" ?> D@0:B0;0< ":" by fractals ",StrPer(TFProfit)," +- ",delta_profit); 

            if (NoLoss==3) txt=StringConcatenate(txt,LANGUAGE?" ?> ATR (":" by ATR (",period_ATR,") ",StrPer(TFProfit),"+- ",delta_profit); 

            if (NoLoss==4) txt=StringConcatenate(txt,LANGUAGE?" ?> ?0@01>;8:C (":" on the parabolic (",Step,",",Maximum,") ",StrPer(TFProfit)," +- ",delta_profit); 

            if (NoLoss==5) txt=StringConcatenate(txt," ",level_Loss," pips."); 

            if (Min_Profit!=0) txt=StringConcatenate(txt," Min_Profit=",Min_Profit," pips."); 

         }

         LabelCreate(0,"ts nl",0 ,X+10,y,CORNER_LEFT_UPPER,txt,Font,Width,coltxt,0,ANCHOR_LEFT,false,false,true,0);

         y+=20;



         txt=LANGUAGE?""@59;8=3 TP ":"Trailing TP ";

         coltxt=clrGray;

         if (Level_TP==0) txt=StringConcatenate(txt," >B:;NG5=");

         else

         {

            coltxt=colorWinT;

            txt=StringConcatenate(txt," ",Level_TP,LANGUAGE?" ?C=:B":" pips");

         }

         LabelCreate(0,"ts tp",0 ,X+10,y,CORNER_LEFT_UPPER,txt,Font,Width,coltxt,0,ANCHOR_LEFT,false,false,true,0);

         y+=20;

         if (LANGUAGE)

         {

            LabelCreate(0,"ts Magic",0 ,X+10,y,CORNER_LEFT_UPPER,Magic==-1?" 01>B0 ?> 2A5< Magic":StringConcatenate(" 01>B0 ?> Magic = ",Magic),Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

            y+=20;

            LabelCreate(0,"ts Portfel",0 ,X+10,y,CORNER_LEFT_UPPER,TralPortfel==1?" 01>B0 >B >1I53> 157C1KB:0":""@0; :064>9 ?>78F88 >B45;L=>",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         }

         else

         {

            LabelCreate(0,"ts Magic",0 ,X+10,y,CORNER_LEFT_UPPER,Magic==-1?"Magic all":StringConcatenate("Magic = ",Magic),Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

            y+=20;

            LabelCreate(0,"ts Portfel",0 ,X+10,y,CORNER_LEFT_UPPER,TralPortfel==1?"Work from the total breakeven": "Trawl each position separately",Font,Width,colorWinT,0,ANCHOR_LEFT,false,false,true,0);

         }

      }





      ObjectSetString(0,"ts BalanceP",OBJPROP_TEXT,StringConcatenate(DoubleToString(AB,2),AC));

      ObjectSetString(0,"ts EquityP%",OBJPROP_TEXT,StringConcatenate(DoubleToString((AE-AB)*100/AB,2),"%"));

      ObjectSetString(0,"ts EquityP",OBJPROP_TEXT,StringConcatenate(DoubleToString(AE,2),AC));

      ObjectSetString(0,"ts FreeMarginP",OBJPROP_TEXT,StringConcatenate(DoubleToString(FM,2),AC));

      ObjectSetString(0,"ts Data",OBJPROP_TEXT,TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS));

   }

   

   //-------------------------------------------------------//

   //                                                       //

   //                    ?>4AG5B ?>78F89                    //

   //                                                       //

   //-------------------------------------------------------//

   

   if (!IsTradeAllowed()) 

   {

      if (visual) ObjectSetString(0,"ts BalanceP",OBJPROP_TEXT,LANGUAGE?"">@3>2;O 70?@5I5=0":"Trading is prohibited");

      return;

   }

   //---

   int OT,b=0,s=0;

   double Profit,OOP=0,price_b=0,price_s=0,lot=0,NLb=0,NLs=0,lot_s=0,lot_b=0;

   for (int j=0; j<OrdersTotal(); j++)

   {  

      if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true)

      {  

         if ((Magic==OrderMagicNumber() || Magic==-1) && OrderSymbol()==Symbol())

         {

            OT=OrderType();

            if (OT>1) continue;

            OOP = OrderOpenPrice();

            lot   = OrderLots();

            Profit=OrderProfit()+OrderSwap()+OrderCommission();

            if (OT==OP_BUY ) 

            {

               price_b += OOP*lot; 

               lot_b+=lot; 

               b++;

            }                     

            if (OT==OP_SELL) 

            {

               price_s += OOP*lot; 

               lot_s+=lot; 

               s++;

            }

            txt=StringConcatenate("ts ",IntegerToString(OrderTicket())," ",Symbol()," ",DoubleToString(OrderLots(),2));

            TrendCreate(0,txt,0,OrderOpenTime(),OOP,iTime(NULL,0,0),OT==OP_BUY?Bid:Ask,OT==OP_SELL?color_sell:color_buy,STYLE_SOLID,1,true,false,false,true,0);

         }  

      }  

   }

   if (IsTesting() && TimeBar!=Time[0])

   {

      double Lot;

      if (Close[1]>Close[2] && b==0 && (tral==2 || tral==0))

      {

         if (lot_b==0) 

         {

            if (lot_s==0) 

            Lot = 0.1;

            else Lot = lot_s;

         }

         else Lot = lot_b;

         if (OrderSend(Symbol(),OP_BUY,MINLOT,NormalizeDouble(Ask,Digits),3,0,0,"B5AB",Magic,0,Green)!=-1) {TimeBar=Time[0]; return;} 

      }

      if (Close[1]<Close[2] && s==0 && tral>0)

      {

         if (lot_s==0) 

         {

            if (lot_b==0) 

            Lot = 0.1;

            else Lot = lot_b;

         }

         else Lot = lot_s;

         if (OrderSend(Symbol(),OP_SELL,MINLOT,NormalizeDouble(Bid,Digits),3,0,0,"B5AB",Magic,0,Green)!=-1) {TimeBar=Time[0];return;} 

      }

   }

   //--------------------------------------

   double SLb=0,SLs=0;

   t=Time[0]+Period()*300;

   if (b!=0) 

   {  

      NLb = price_b/lot_b;

      if (visual) DrawArrow(0,"ts NoLossBuy",t,NLb,color_buy,6);

   }

   if (s!=0) 

   {  

      NLs = price_s/lot_s;

      if (visual) DrawArrow(0,"ts NoLossSell",t,NLs,color_sell,6);

   }

   //---

   STOPLEVEL=(int)MarketInfo(Symbol(),MODE_STOPLEVEL);

   int SPREAD=(int)MarketInfo(Symbol(),MODE_SPREAD);

   if (STOPLEVEL<SPREAD*2) STOPLEVEL=SPREAD*2;//4;O ;L?0@8

   /*if (STOPLEVEL>0 && visual)

   {

      DrawArrow(0,"STOPLEVEL-",Time[0],Bid-STOPLEVEL*Point,color_buy,4,1,3);

      DrawArrow(0,"STOPLEVEL+",Time[0],Ask+STOPLEVEL*Point,color_sell,4,1,3);

   }

   //---

   if (level_Loss<STOPLEVEL && TrallLoss==5) 

   {

      level_Loss=STOPLEVEL;Alert(Symbol()," 0@0<5B@ B@0; C1KB>G=KE A45;>: 87<5=5= 4> <8=8<0;L=> 2>7<>6=>3> C@>2=O ",STOPLEVEL);

   }

   if (level_Profit<STOPLEVEL && TralProfit==5) 

   {

      level_Profit=STOPLEVEL;Alert(Symbol()," 0@0<5B@ B@0; ?@81K;L=KE A45;>: 87<5=5= 4> <8=8<0;L=> 2>7<>6=>3> C@>2=O ",STOPLEVEL);

   }

   if (level_NoLoss<STOPLEVEL && NoLoss==5) 

   {

      level_NoLoss=STOPLEVEL;Alert(Symbol()," 0@0<5B@ 157C1KB>: 87<5=5= 4> <8=8<0;L=> 2>7<>6=>3> C@>2=O ",STOPLEVEL);

   }*/

   //---

   int tip,Ticket,i;

   bool error;

   double OSL;

   if (NoLoss>0 && b+s>0)

   {

      if (b!=0) SLb = SlLastBar(1,Bid,NoLoss,TFProfit,Min_Profit,level_NoLoss,"No Loss Buy"); 

      if (s!=0) SLs = SlLastBar(-1,Ask,NoLoss,TFProfit,Min_Profit,level_NoLoss,"No Loss Sell");  

      if (TralPortfel==1)

      {

         RefreshRates();

         for (i=OrdersTotal(); i>=0; i--) 

         {  

            if (OrderSelect(i, SELECT_BY_POS))

            {  

               tip = OrderType();

               if (tip<2 && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==Magic || Magic==-1))

               {

                  OSL    = NormalizeDouble(OrderStopLoss(),Digits);

                  OOP    = NormalizeDouble(OrderOpenPrice(),Digits);

                  Ticket = OrderTicket();

                  if (tip==OP_BUY && (tral==2 || tral==0))             

                  {  

                     if (OSL>=OOP+Min_Profit*Point) continue;

                     if (SLb == 0) continue;

                     if (SLb < NLb+Min_Profit*Point) continue;



                     if (SLb > OSL+Step_Trall*Point)

                     {  

                        error=OrderModify(Ticket,OOP,SLb,OrderTakeProfit(),0,White);

                        if (!error) Comment("157C1KB>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLb);

                        else Comment("157C1KB>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                     }

                  }                                         

                  if (tip==OP_SELL && tral>0)        

                  {  

                     if (OSL<=OOP-Min_Profit*Point && OSL!=0) continue;

                     if (SLs == 0) continue;

                     if (SLs > NLs-Min_Profit*Point) continue;

               

                     if (SLs < OSL-Step_Trall*Point || OSL==0 )

                     {  

                        error=OrderModify(Ticket,OOP,SLs,OrderTakeProfit(),0,White);

                  

                        if (!error) Comment("157C1KB>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLs);

                        else Comment("157C1KB>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                     }

                  } 

               }

            }

         }

      }

      else

      {

         RefreshRates();

         for (i=OrdersTotal(); i>=0; i--) 

         {  

            if (OrderSelect(i, SELECT_BY_POS))

            {  

               tip = OrderType();

               if (tip<2 && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==Magic || Magic==-1))

               {

                  OSL    = NormalizeDouble(OrderStopLoss(),Digits);

                  OOP    = NormalizeDouble(OrderOpenPrice(),Digits);

                  Ticket = OrderTicket();

                  if (tip==OP_BUY && (tral==2 || tral==0))             

                  {  

                     if (OSL >=OOP+Min_Profit*Point) continue;

                     if (SLb > OSL && SLb >=OOP+Min_Profit*Point)

                     {  

                        error=OrderModify(Ticket,OOP,SLb,OrderTakeProfit(),0,White);

                        if (!error) Comment("157C1KB>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLb);

                        else Comment("157C1KB>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                     }

                  }                                         

                  if (tip==OP_SELL && tral>0)        

                  {  

                     if (OSL <=OOP+Min_Profit*Point && OSL!=0) continue;

                     if ((SLs < OSL || OSL==0 ) && SLs <=OOP-Min_Profit*Point)

                     {  

                        error=OrderModify(Ticket,OOP,SLs,OrderTakeProfit(),0,White);

                        if (!error) Comment("157C1KB>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLs);

                        else Comment("157C1KB>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                     }

                  } 

               }

            }

         }

      }

   }

   else

   {

      ObjectsDeleteAll(0,"No Loss Buy");

      ObjectsDeleteAll(0,"No Loss Sell");

   }

   //---

   if (TralProfit>0 && b+s>0)

   {

      RefreshRates();

      if (b!=0) SLb = SlLastBar( 1,Bid,TralProfit,TFProfit,delta_profit,level_Profit,"Trall Profit Buy"); 

      if (s!=0) SLs = SlLastBar(-1,Ask,TralProfit,TFProfit,delta_profit,level_Profit,"Trall Profit Sell");  

      for (i=OrdersTotal(); i>=0; i--) 

      {  

         if (OrderSelect(i, SELECT_BY_POS))

         {  

            tip = OrderType();

            if (tip<2 && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==Magic || Magic==-1))

            {

               OSL    = NormalizeDouble(OrderStopLoss(),Digits);

               OOP    = NormalizeDouble(OrderOpenPrice(),Digits);

               Ticket = OrderTicket();

               if (tip==OP_BUY && (tral==2 || tral==0))             

               {  

                  if (SLb == 0) continue;

                  if ((NormalizeDouble(SLb-Start_Trall*Point,Digits) < NLb && TralPortfel==1) || 

                      (NormalizeDouble(SLb-Start_Trall*Point,Digits) < OOP && TralPortfel==0)) continue;

               

                  if (SLb > OSL+Step_Trall*Point)

                  {  

                     error=OrderModify(Ticket,OOP,SLb,OrderTakeProfit(),0,White);

                     if (!error) Comment("B@0; ?@81K;L=KE A45;>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLb);

                     else Comment("B@0; ?@81K;L=KE A45;>: ",Ticket," ",TimeToStr(TimeCurrent(),TIME_MINUTES),"   ",NLb);

                  }

               }                                         

               if (tip==OP_SELL && tral>0)        

               {  

                  if (SLs == 0) continue;

                  if ((NormalizeDouble(SLs+Start_Trall*Point,Digits) > NLs && TralPortfel==1) || 

                      (NormalizeDouble(SLs+Start_Trall*Point,Digits) > OOP && TralPortfel==0)) continue;

               

                  if (SLs < OSL-Step_Trall*Point || OSL==0 )

                  {  

                     error=OrderModify(Ticket,OOP,SLs,OrderTakeProfit(),0,White);

                  

                     if (!error) Comment("B@0; ?@81K;L=KE A45;>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLs);

                     else Comment("B@0; ?@81K;L=KE A45;>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                  }

               } 

            }

         }

      }

   }

   else

   {

      ObjectsDeleteAll(0,"Trall Profit Buy");

      ObjectsDeleteAll(0,"Trall Profit Sell");

   }

   //---

   if (TrallLoss>0 && b+s>0)

   {

      RefreshRates();

      if (b!=0) SLb = SlLastBar( 1,Bid,TrallLoss,TFLoss,delta_Loss,level_Loss,"Trall Loss Buy");

      if (s!=0) SLs = SlLastBar(-1,Ask,TrallLoss,TFLoss,delta_Loss,level_Loss,"Trall Loss Sell");

      for (i=OrdersTotal(); i>=0; i--) 

      {  

         if (OrderSelect(i, SELECT_BY_POS))

         {  

            tip = OrderType();

            if (tip<2 && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==Magic || Magic==-1))

            {

               OSL    = NormalizeDouble(OrderStopLoss(),Digits);

               OOP    = NormalizeDouble(OrderOpenPrice(),Digits);

               Ticket = OrderTicket();

               if (tip==OP_BUY && (tral==2 || tral==0))             

               {  

                  if (SLb == 0) continue;

                  if (SLb < OSL) continue;

               

                  if (SLb > OSL+Step_Trall*Point)

                  {  

                     error=OrderModify(Ticket,OOP,SLb,OrderTakeProfit(),0,White);

                     if (!error) Comment("B@0; C1KB>G=KE A45;>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLb);

                     else Comment("B@0; C1KB>G=KE A45;>: ",Ticket," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                  }

               }                                         

               if (tip==OP_SELL && tral>0)        

               {  

                  if (SLs == 0) continue;

                  if (SLs > OSL && OSL != 0) continue;

               

                  if (SLs < OSL-Step_Trall*Point || OSL==0 )

                  {  

                     error=OrderModify(Ticket,OOP,SLs,OrderTakeProfit(),0,White);

                  

                     if (!error) Comment("B@0; C1KB>G=KE A45;>: Error ",GetLastError(),"  order ",Ticket,"   SL ",SLs);

                     else Comment("B@0; C1KB>G=KE A45;>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                  }

               } 

            }

         }

      }

   }

   else

   {

      ObjectsDeleteAll(0,"Trall Loss Buy");

      ObjectsDeleteAll(0,"Trall Loss Sell");

   }

   

   //---

   

   if (b==0)

   {

      ObjectsDeleteAll(0,"No Loss Buy");

      ObjectsDeleteAll(0,"Trall Profit Buy");

      ObjectsDeleteAll(0,"Trall Loss Buy");

   }

   if (s==0)

   {

      ObjectsDeleteAll(0,"No Loss Sell");

      ObjectsDeleteAll(0,"Trall Profit Sell");

      ObjectsDeleteAll(0,"Trall Loss Sell");

   }

   

   //---

   

   if (Level_TP>STOPLEVEL)

   {

      RefreshRates();

      for (i=OrdersTotal(); i>=0; i--) 

      {  

         if (OrderSelect(i, SELECT_BY_POS))

         {  

            tip = OrderType();

            if (tip<2 && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==Magic || Magic==-1))

            {

               OSL    = NormalizeDouble(OrderStopLoss(),Digits);

               OOP    = NormalizeDouble(OrderOpenPrice(),Digits);

               double OTP = NormalizeDouble(OrderTakeProfit(),Digits);

               double TP;

               Ticket = OrderTicket();

               if (tip==OP_BUY && (tral==2 || tral==0))             

               {  

                  TP = NormalizeDouble(NLb + Level_TP * Point,Digits);

                  if (MathAbs(TP - OTP)/Point > Step_Trall)

                  {  

                     error=OrderModify(Ticket,OOP,OSL,TP,0,White);

                     if (!error) Comment("B@0; C1KB>G=KE A45;>: Error ",GetLastError(),"  order ",Ticket,"   TP ",TP);

                     else Comment("B@0; C1KB>G=KE A45;>: ",Ticket," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                  }

               }                                         

               if (tip==OP_SELL && tral>0)        

               {  

                  TP = NormalizeDouble(NLs - Level_TP * Point,Digits);

                  if (MathAbs(TP - OTP)/Point > Step_Trall)

                  {  

                     error=OrderModify(Ticket,OOP,OSL,TP,0,White);

                  

                     if (!error) Comment("B@0; C1KB>G=KE A45;>: Error ",GetLastError(),"  order ",Ticket,"   TP ",TP);

                     else Comment("B@0; C1KB>G=KE A45;>: ",IntegerToString(Ticket)," ",TimeToStr(TimeCurrent(),TIME_MINUTES));

                  }

               } 

            }

         }

      }

   }

   //---

   if (visual) 

   {

      ObjectSetString(0,"ts Buy",OBJPROP_TEXT,b==0?(LANGUAGE?"5B >@45@>2":"no orders "):StringConcatenate("A53> ",b, " buy"));

      //ObjectSetInteger(0,"ts Buy",OBJPROP_COLOR,b==0?clrGray:clrGreen);

      ObjectSetString(0,"ts Sell",OBJPROP_TEXT,s==0?(LANGUAGE?"5B >@45@>2":"no orders "):StringConcatenate("A53> ",s, " sell"));

      //ObjectSetInteger(0,"ts Sell",OBJPROP_COLOR,s==0?clrGray:clrGreen);

   }

}

//--------------------------------------------------------------------

double SlLastBar(int tip,double price,double Trailing,int TF_Tralling,int delta,int level,string comment)

{

   datetime t1;

   double fr=0;

   int i;

   if (Trailing==5)

   {

      if (tip==1)

      {

         fr = NormalizeDouble(price - level*Point,Digits);  

         if (visual)

         {

            t1=iTime(Symbol(),0,0);

            TrendCreate(0,StringConcatenate(comment," Level FR Buy"),0,t1,fr,t,fr,color_buy);

            TextCreate(0,comment,0,t,fr,comment,"Arial",8,clrGray,0,ANCHOR_RIGHT_LOWER);

         }

      }

      else

      {

         fr = NormalizeDouble(price + level*Point,Digits);  

         if (visual)

         {

            t1=iTime(Symbol(),0,0);

            TrendCreate(0,StringConcatenate(comment," Level FR Sell"),0,t1,fr,t,fr,color_sell);

            TextCreate(0,comment,0,t,fr,comment,"Arial",8,clrGray,0,ANCHOR_RIGHT_LOWER);

         }

      }

   }

   else

   {

      //------------------------------------------------------- by Fractals

      if (Trailing==2)

      {

         

         if (tip== 1)

         {

            for (i=1; i<500; i++) 

            {

               fr = iFractals(Symbol(),TF_Tralling,MODE_LOWER,i);

               if (fr!=0) {fr=NormalizeDouble(fr-delta*Point,Digits); if (price-STOPLEVEL*Point > fr) break;}

               else fr=0;

            }

            if (visual)

            {

               t1=iTime(Symbol(),TF_Tralling,i);

               DrawArrow(0,StringConcatenate(comment," FR Buy"),t1,fr,color_buy,218,ANCHOR_TOP);

               TrendCreate(0,StringConcatenate(comment," Level FR Buy"),0,t1,fr,t,fr,color_buy);

               TextCreate(0,comment,0,t,fr,comment,"Arial",8,clrGray,0,ANCHOR_RIGHT_LOWER);

            }

         }

         if (tip==-1)

         {

            for (i=2; i<500; i++) 

            {

               fr = iFractals(Symbol(),TF_Tralling,MODE_UPPER,i);

               if (fr!=0) {fr=NormalizeDouble(fr+delta*Point,Digits); if (price+STOPLEVEL*Point < fr) break;}

               else fr=0;

            }

            if (visual)

            {

               t1=iTime(Symbol(),TF_Tralling,i);

               DrawArrow(0,StringConcatenate(comment," FR Sell"),t1,fr,color_sell,217);

               TrendCreate(0,StringConcatenate(comment," Level FR Sell"),0,t1,fr,t,fr,color_sell);

               TextCreate(0,comment,0,t,fr,comment,"Arial",8,clrGray,0,ANCHOR_RIGHT_LOWER);

            }

         }

      }

      //------------------------------------------------------- by candles

      if (Trailing==1)

      {

         if (tip== 1)

         {

            for (i=1; i<500; i++) 

            {

               fr = NormalizeDouble(iLow(Symbol(),TF_Tralling,i)-delta*Point,Digits);

               if (fr!=0) if (price-STOPLEVEL*Point > fr) break;

               else fr=0;

            }

            if (visual)

            {

               t1=iTime(Symbol(),TF_Tralling,i);

               DrawArrow(0,StringConcatenate(comment," FR Buy"),t1,fr,color_buy,159,ANCHOR_TOP,3);

               TrendCreate(0,StringConcatenate(comment," Level FR Buy"),0,t1,fr,t,fr,color_buy);

               TextCreate(0,comment,0,t,fr,comment,"Arial",8,clrGray,0,ANCHOR_RIGHT_LOWER);

            }

         }

         if (tip==-1)

         {

            for (i=1; i<500; i++) 

            {

               fr = NormalizeDouble(iHigh(Symbol(),TF_Tralling,i)+delta*Point,Digits);

               if (fr!=0) if (price+STOPLEVEL*Point < fr) break;

               else fr=0;

            }

            if (visual)

            {

               t1=iTime(Symbol(),TF_Tralling,i);

               DrawArrow(0,StringConcatenate(comment," FR Sell"),t1,fr,color_sell,159,ANCHOR_BOTTOM,3);

               TrendCreate(0,StringConcatenate(comment," Level FR Sell"),0,t1,fr,t,fr,color_sell);

               TextCreate(0,comment,0,t,fr,comment,"Arial",8,clrGray,0,ANCHOR_RIGHT_LOWER);

            }

         }

      }   

      //------------------------------------------------------- by ATR

      if (Trailing==3)

      {

         if (tip== 1)

         {

            fr = NormalizeDouble(Bid - iATR(Symbol(),TF_Tralling,period_ATR,0) - delta*Point,Digits);

         }

         if (tip==-1)

         {

            fr = NormalizeDouble(Ask + iATR(Symbol(),TF_Tralling,period_ATR,0) + delta*Point,Digits);

         }

      }

      //------------------------------------------------------- by PSAR

      if (Trailing==4)

      {

         double PSAR = iSAR(Symbol(),TF_Tralling,Step,Maximum,0);

         if (tip== 1)

         {

            if(price-STOPLEVEL*Point > PSAR) fr = NormalizeDouble(PSAR - delta*Point,Digits);

            else fr=0;

         }

         if (tip==-1)

         {

            if(price+STOPLEVEL*Point < PSAR) fr = NormalizeDouble(PSAR + delta*Point,Digits);

            else fr=0;

         }

      }

   }

   //-------------------------------------------------------

   /*if (visual)

   {

      if (tip== 1)

      {  

         //if (fr!=0) DrawArrow(0,"SL Buy",t,fr,color_buy,6);

         if (STOPLEVEL>0) DrawArrow(0,"STOPLEVEL-",t,price-STOPLEVEL*Point,color_buy,4,1,3);

      }

      if (tip==-1)

      {

         //if (fr!=0)DrawArrow(0,"SL Sell",t,fr,color_sell,6);

         if (STOPLEVEL>0) DrawArrow(0,"STOPLEVEL+",t,price+STOPLEVEL*Point,color_sell,4,1,3);

      }

   }*/

   return(fr);

}

//--------------------------------------------------------------------

string StrPer(int per)

{

   if (per == 0)     per=Period();

   if (per == 1)     return("M1");

   if (per == 5)     return("M5");

   if (per == 15)    return("M15");

   if (per == 30)    return("M30");

   if (per == 60)    return("H1");

   if (per == 240)   return("H4");

   if (per == 1440)  return("D1");

   if (per == 10080) return("W1");

   if (per == 43200) return("MN1");

return(">H81:0 ?5@8>40");

}

//+------------------------------------------------------------------+

bool ButtonCreate(const long              chart_ID=0,               // ID 3@0D8:0

                  const string            name="Button",            // 8<O :=>?:8

                  const int               sub_window=0,             // =><5@ ?>4>:=0

                  const long               x=0,                     // :>>@48=0B0 ?> >A8 X

                  const long               y=0,                     // :>>@48=0B0 ?> >A8 y

                  const int               width=50,                 // H8@8=0 :=>?:8

                  const int               height=18,                // 2KA>B0 :=>?:8

                  const string            text="Button",            // B5:AB

                  const string            font="Arial",             // H@8DB

                  const int               font_size=10,             // @07<5@ H@8DB0

                  const color             clr=clrNONE,

                  const color             back_clr=clrNONE,

                  const bool              state=false)              // =060B0/>B60B0

  {

   if (ObjectFind(chart_ID,name)==-1)

   {

      ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

      ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,1);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,clrNONE);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   return(true);

}

//--------------------------------------------------------------------

bool RectLabelCreate(const long             chart_ID=0,               // ID 3@0D8:0

                     const string           name="RectLabel",         // 8<O <5B:8

                     const int              sub_window=0,             // =><5@ ?>4>:=0

                     const long              x=0,                     // :>>@48=0B0 ?> >A8 X

                     const long              y=0,                     // :>>@48=0B0 ?> >A8 y

                     const int              width=50,                 // H8@8=0

                     const int              height=18,                // 2KA>B0

                     const color            back_clr=clrNONE,         // F25B D>=0

                     const color            clr=clrNONE,              //F25B ?;>A:>9 3@0=8FK (Flat)

                     const ENUM_LINE_STYLE  style=STYLE_SOLID,        // AB8;L ?;>A:>9 3@0=8FK

                     const int              line_width=1,             // B>;I8=0 ?;>A:>9 3@0=8FK

                     const bool             back=false,               // =0 704=5< ?;0=5

                     const bool             selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89

                     const bool             hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2

                     const long             z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN

  {

   ResetLastError();

   if (ObjectFind(chart_ID,name)==-1)

   {

      ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0);

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);

      ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

      ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   return(true);

}

//--------------------------------------------------------------------

bool LabelCreate(const long              chart_ID=0,               // ID 3@0D8:0

                 const string            name="Label",             // 8<O <5B:8

                 const int               sub_window=0,             // =><5@ ?>4>:=0

                 const long              x=0,                      // :>>@48=0B0 ?> >A8 X

                 const long              y=0,                      // :>>@48=0B0 ?> >A8 y

                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // C3>; 3@0D8:0 4;O ?@82O7:8

                 const string            text="Label",             // B5:AB

                 const string            font="Arial",             // H@8DB

                 const int               font_size=10,             // @07<5@ H@8DB0

                 const color             clr=clrNONE,      

                 const double            angle=0.0,                // =0:;>= B5:AB0

                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // A?>A>1 ?@82O7:8

                 const bool              back=false,               // =0 704=5< ?;0=5

                 const bool              selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89

                 const bool              hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2

                 const long              z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN

{

   ResetLastError();

   if (ObjectFind(chart_ID,name)==-1)

   {

      if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))

      {

         Print(__FUNCTION__,": =5 C40;>AL A>740BL B5:AB>2CN <5B:C! >4 >H81:8 = ",GetLastError());

         return(false);

      }

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

      ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

      ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

   return(true);

  }

//--------------------------------------------------------------------

bool EditCreate(const long             chart_ID=0,               // ID 3@0D8:0 

                const string           name="Edit",              // 8<O >1J5:B0 

                const int              sub_window=0,             // =><5@ ?>4>:=0 

                const long              x=0,                      // :>>@48=0B0 ?> >A8 X 

                const long              y=0,                      // :>>@48=0B0 ?> >A8 Y 

                const int              width=50,                 // H8@8=0 

                const int              height=18,                // 2KA>B0 

                const string           text="Text",              // B5:AB 

                const string           font="Arial",             // H@8DB 

                const int              font_size=8,             // @07<5@ H@8DB0 

                const ENUM_ALIGN_MODE  align=ALIGN_CENTER,       // A?>A>1 2K@02=820=8O 

                const bool             read_only=true,// 2>7<>6=>ABL @540:B8@>20BL 

                const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER,// C3>; 3@0D8:0 4;O ?@82O7:8 

                const color            clr=clrBlack,             // F25B B5:AB0 

                const color            back_clr=clrWhite,        // F25B D>=0 

                const color            border_clr=clrNONE,       // F25B 3@0=8FK 

                const bool             back=false,               // =0 704=5< ?;0=5 

                const bool             selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89 

                const bool             hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2 

                const long             z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN 

  {

   ResetLastError();

   if(ObjectFind(chart_ID,name)!=-1) ObjectDelete(chart_ID,name);

   //{

      if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0))

      {

         return(false);

      }

      ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

      ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

      ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

      ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

      ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

      ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align);

      ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only);

      ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

      ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

      ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

      ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);

      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   //}

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

   return(true);

  }

//+------------------------------------------------------------------+ 

void DrawArrow(int win, string name, datetime time,double price, color colr,int cod,int anchor=ANCHOR_BOTTOM, int w=1)

{

   ObjectDelete(name);

   ObjectCreate(name,OBJ_ARROW,win,time,price,0,0,0,0);                     

   ObjectSet   (name,OBJPROP_COLOR, colr);

   ObjectSet   (name,OBJPROP_ARROWCODE,cod);

   ObjectSet   (name,OBJPROP_WIDTH,w);

   ObjectSetInteger(win,name,OBJPROP_ANCHOR,anchor); 

}

//+------------------------------------------------------------------+

void OnChartEvent(const int id, 

                  const long &lparam, 

                  const double &dparam, 

                  const string &sparam) 

{ 

   int ret=IDYES;

   if(id==CHARTEVENT_OBJECT_CLICK) 

   { 

      if (sparam=="cm_WIN")

      {

         OnTick();

      }

      if (sparam=="ts 1")

      {

         ret=MessageBox(StringConcatenate(LANGUAGE?";O 4>102;5=8O DC=:F89, >1@0B8B5AL : @07@01>BG8:C:":

         "!ontact the developer:","\ncmillion@narod.ru\nSkype: mqlcmillion\nTelegram: @mqlcmillion"),

         StringConcatenate(LANGUAGE?"5<> 25@A8O":"Demo version"),MB_YESNO|MB_TOPMOST);

      }

   }     

} 

//-------------------------------------------------------------------//      

bool TrendCreate(const long            chart_ID=0,        // ID 3@0D8:0 

                 const string          name="TrendLine",  // 8<O ;8=88 

                 const int             sub_window=0,      // =><5@ ?>4>:=0 

                 datetime              time1=0,           // 2@5<O ?5@2>9 B>G:8 

                 double                price1=0,          // F5=0 ?5@2>9 B>G:8 

                 datetime              time2=0,           // 2@5<O 2B>@>9 B>G:8 

                 double                price2=0,          // F5=0 2B>@>9 B>G:8 

                 const color           clr=clrRed,        // F25B ;8=88 

                 const ENUM_LINE_STYLE style=STYLE_SOLID, // AB8;L ;8=88 

                 const int             width=1,           // B>;I8=0 ;8=88 

                 const bool            back=false,        // =0 704=5< ?;0=5 

                 const bool            selection=false,    // 2K45;8BL 4;O ?5@5<5I5=89 

                 const bool            ray_right=false,   // ?@>4>;65=85 ;8=88 2?@02> 

                 const bool            hidden=true,       // A:@KB 2 A?8A:5 >1J5:B>2 

                 const long            z_order=0)         // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

   if(ObjectFind(chart_ID,name)!=-1)

      ObjectDelete(name);

   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2)) 

     { 

      return(false); 

     } 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right); 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

   return(true); 

  } 

//+------------------------------------------------------------------+ 

bool TextCreate(const long              chart_ID=0,               // ID 3@0D8:0 

                const string            name="Text",              // 8<O >1J5:B0 

                const int               sub_window=0,             // =><5@ ?>4>:=0 

                datetime                time=0,                   // 2@5<O B>G:8 ?@82O7:8 

                double                  price=0,                  // F5=0 B>G:8 ?@82O7:8 

                const string            text="Text",              // A0< B5:AB 

                const string            font="Arial",             // H@8DB 

                const int               font_size=10,             // @07<5@ H@8DB0 

                const color             clr=clrGray,               // F25B 

                const double            angle=0.0,                // =0:;>= B5:AB0 

                const ENUM_ANCHOR_POINT anchor=ANCHOR_LOWER, // A?>A>1 ?@82O7:8 

                const bool              back=false,               // =0 704=5< ?;0=5 

                const bool              selection=false,          // 2K45;8BL 4;O ?5@5<5I5=89 

                const bool              hidden=true,              // A:@KB 2 A?8A:5 >1J5:B>2 

                const long              z_order=0)                // ?@8>@8B5B =0 =060B85 <KHLN 

  { 

   if(ObjectFind(chart_ID,name)!=-1) ObjectDelete(chart_ID,name);

   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price)) 

     { 

      return(false); 

     } 

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 

   return(true); 

  } 

//+------------------------------------------------------------------+ 

Comments