cm ea StopOrdersTrendLine

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
1 Views
0 Downloads
0 Favorites
cm ea StopOrdersTrendLine
ÿþ//+------------------------------------------------------------------+

//|                               Copyright © 2012, %;KAB>2 ;048<8@ |

//|                                                cmillion@narod.ru |

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

#property copyright "Copyright © 2019, http://cmillion.ru"

#property link      "cmillion@narod.ru"

#property version   "1.00"

#property strict

#property description "!>25B=8: 2545B AB>? >@45@0 24>;L B@5=4>2>9 ;8=88"

/*

!>25B=8: AB028B >B;>65==K9 >@45@ (A> AB>?>< 8 ?@>D8B><) =0 >?@545;5==>< @0AAB>O=88 >B B@5=4>2>9 ;8=88. (DistanceFromLine)

0B5< ?@8 A@010BK20=88 >@45@0 8 ?> ?@>H5AB288 >?@545;5==KE ?C=:B>2 (PartualCloseDistance) 70:@K205B G0ABL ?>78F88 8 ?5@52>48B 

>AB0B>: 2 157C1KB>: ?;NA (BE_plusPunkts) ?C=:B>2.

@8 70?CA:5 A>25B=8:0 ?>O2;ONBAO 425 :=>?:8 Buy, Sell, GB>1K <>6=> 1K;> 2:;NG0BL Buy 8;8 Sell >B45;L=>, 8;8 2<5AB5. 

@8 =060B88 =0 :=>?:C Buy ?>O2;O5BAO A8=OO B@5=4>20O ;8=8O, :>B>@CN <>6=> :0: C3>4=> ?5@5<5I0BL 8 A25@EC :>B>@>9 =0 >?@545;5==>9 48AB0=F88 AB028BAO BuyStop.

=>?:0 Sell G5@B8B :@0A=CN ;8=8N 8 AB028B SellStop A=87C MB>9 ;8=88.

*/

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

input int     DistanceFromLine      = 100;    // 0AAB>O=85 2KAB02;5=8O >B;>65==>3> >@45@0 >B ;8=88

input int     Stoploss              = 350;

input int     Takeprofit            = 500;

input int     PartualCloseDistance  = 120;   //8AB0=F8N :>340 70:@K20BL G0ABL ?>78F88

input double  PartualCloseLot       = 0.02;  //>;8G5AB2> ;>B>2 ?>78F88, :>B>@K5 =C6=> 70:@KBL

input int     BE_Trigger            = 100;   //>340 ?5@52>48BL 2 157C1KB>:

input int     BE_plusPunkts         = 25;    //0A:>;L:> ?C=:B>2 AB028BL 2 157C1KB>:  

input double  Lots                  = 0.1;

sinput int    Magic                 = 100;

sinput bool   UseSound              = true;     // A?>;L7>20BL 72C:>2>9 A83=0;

sinput string SoundSuccess          = "ok.wav"; // 2C: 2:;NG5=8O A45;:8

int    Slippage = 30;

int    FontSize = 8;

double Bid,Ask;

int bOld=0,sOld=0;



MqlTick tick;

MqlTradeRequest request;

MqlTradeResult result;

MqlTradeCheckResult check;

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

int OnInit()

{

   ButtonCreate(0,"cm trend line Buy" ,0,5,46,45,20,"buy" ,"Times New Roman",10,clrBlack,clrLightGray,clrNONE,false);

   ButtonCreate(0,"cm trend line Sell",0,5,25,45,20,"sell","Times New Roman",10,clrBlack,clrLightGray,clrNONE,false);

   Comment(TimeCurrent()," Start");   

   return(INIT_SUCCEEDED);

  }

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

void OnTick()

{

   Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);

   Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);

   double STOPLEVEL = (double)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);

   ulong TicketBuyStop=0,TicketSellStop=0;

   double OL,OSL,OTP,OOP,StLo=0,PriceBuyStop=0,PriceSellStop=0;

   ulong Ticket;

   ulong tip;

   int i,b=0,s=0;

   bool BS = ObjectGetInteger(0,"cm trend line Buy",OBJPROP_STATE);

   bool SS = ObjectGetInteger(0,"cm trend line Sell",OBJPROP_STATE);

   

   //---

   

   datetime t1,t2;

   double PriceB=0,p1,p2;

   if (ObjectFind(0,"cm trend line B")!=-1) 

   {

      if (!BS) ObjectDelete(0,"cm trend line B");

      else PriceB = NormalizeDouble(ObjectGetValueByShift("cm trend line B",0),_Digits);

   }

   else 

   {

      if (BS) TrendCreate(0,"cm trend line B",0,iTime(NULL,0,50),iHigh(NULL,0,50)+DistanceFromLine*_Point,iTime(NULL,0,1),iHigh(NULL,0,1)+DistanceFromLine*_Point,clrBlue);

   }

   if (PriceB!=0)

   {

      t1 = (datetime)ObjectGetInteger(0,"cm trend line B",OBJPROP_TIME,0);

      t2 = (datetime)ObjectGetInteger(0,"cm trend line B",OBJPROP_TIME,1);

      p1 = ObjectGetDouble(0,"cm trend line B",OBJPROP_PRICE,0);

      p2 = ObjectGetDouble(0,"cm trend line B",OBJPROP_PRICE,1);Comment(p1,"  ",p2);

      TrendCreate(0,"cm trend line BuyStop",0,t1,p1+DistanceFromLine*_Point,t2,p2+DistanceFromLine*_Point,clrBlue,2,1,false,false);

   }

   else ObjectsDeleteAll(0,"cm trend line BuyStop");

   

   //---

   

   double PriceS=0;

   if (ObjectFind(0,"cm trend line S")!=-1) 

   {

      if (!SS) ObjectDelete(0,"cm trend line S");

      else PriceS = NormalizeDouble(ObjectGetValueByShift("cm trend line S",0),_Digits);

   }

   else 

   {

      if (SS) TrendCreate(0,"cm trend line S",0,iTime(NULL,0,50),iLow(NULL,0,50)-DistanceFromLine*_Point,iTime(NULL,0,1),iLow(NULL,0,1)-DistanceFromLine*_Point,clrRed);

   }

   if (PriceS!=0)

   {

      t1 = (datetime)ObjectGetInteger(0,"cm trend line S",OBJPROP_TIME,0);

      t2 = (datetime)ObjectGetInteger(0,"cm trend line S",OBJPROP_TIME,1);

      p1 = ObjectGetDouble(0,"cm trend line S",OBJPROP_PRICE,0);

      p2 = ObjectGetDouble(0,"cm trend line S",OBJPROP_PRICE,1);

      TrendCreate(0,"cm trend line SellStop",0,t1,p1-DistanceFromLine*_Point,t2,p2-DistanceFromLine*_Point,clrRed,2,1,false,false);

   }

   else ObjectsDeleteAll(0,"cm trend line SellStop");

   

   //---

   

   for(i=0; i<PositionsTotal(); i++)

   {

      if(_Symbol==PositionGetSymbol(i))

      {

         if (Magic==PositionGetInteger(POSITION_MAGIC))

         {

            ZeroMemory(request);

            ZeroMemory(result);

            OOP = PositionGetDouble(POSITION_PRICE_OPEN); 

            OSL = PositionGetDouble(POSITION_SL); request.sl = OSL;

            OTP = PositionGetDouble(POSITION_TP); request.tp = OTP;

            tip = PositionGetInteger(POSITION_TYPE);

            Ticket = PositionGetInteger(POSITION_TICKET);

            OL = PositionGetDouble(POSITION_VOLUME);

            if (tip==POSITION_TYPE_BUY ) 

            {

               b++;

               ObjectSetInteger(0,"cm trend line Buy",OBJPROP_STATE,false);

               BS=false;

               if (OL>=Lots && OL>=PartualCloseLot && Bid>OOP + PartualCloseDistance * _Point) 

               {

                  ZeroMemory(request);

                  ZeroMemory(result);

                  request.action   =TRADE_ACTION_DEAL;

                  request.position =Ticket;

                  request.symbol   =_Symbol;

                  request.volume   =PartualCloseLot;

                  request.deviation=Slippage;

                  request.magic    =Magic;

                  request.type_filling=ORDER_FILLING_RETURN;

                  request.price=Bid;

                  request.type =ORDER_TYPE_SELL;

                  if(!OrderSend(request,result))

                     PrintFormat("Order Close error %d",GetLastError());

                  PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

                  continue;

               }

               if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

               {

                  request.sl = NormalizeDouble(OOP - Stoploss   * _Point,_Digits);

               } 

               if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

               {

                  request.tp = NormalizeDouble(OOP + Takeprofit * _Point,_Digits);

               } 

               if (OSL<OOP && BE_Trigger!=0 && BE_Trigger>=STOPLEVEL)

               {

                  StLo = NormalizeDouble(OOP+BE_plusPunkts*_Point,_Digits); 

                  if (StLo > OSL && OOP <= NormalizeDouble(Bid - BE_Trigger * _Point,_Digits)) request.sl = StLo;

               }

               if(request.sl != OSL || request.tp != OTP)

               {

                  request.action    = TRADE_ACTION_SLTP;

                  request.position  = Ticket;

                  if(!OrderSend(request,result)) Print("error ",GetLastError());

               }

            }                     

            if (tip==POSITION_TYPE_SELL) 

            {

               s++;

               ObjectSetInteger(0,"cm trend line Sell",OBJPROP_STATE,false);

               SS=false;

               if (OL>=Lots && OL>=PartualCloseLot && Ask<OOP - PartualCloseDistance * _Point) 

               {

                  ZeroMemory(request);

                  ZeroMemory(result);

                  request.action   =TRADE_ACTION_DEAL;

                  request.position =Ticket;

                  request.symbol   =_Symbol;

                  request.volume   =PartualCloseLot;

                  request.deviation=Slippage;

                  request.magic    =Magic;

                  request.type_filling=ORDER_FILLING_RETURN;

                  request.price=Ask;

                  request.type =ORDER_TYPE_BUY;

                  if(!OrderSend(request,result))

                     PrintFormat("Order Close error %d",GetLastError());

                  PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

                  continue;

               }

               if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

               {

                  request.sl = NormalizeDouble(OOP + Stoploss   * _Point,_Digits);

               }

               if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

               {

                  request.tp = NormalizeDouble(OOP - Takeprofit * _Point,_Digits);

               }

               if ((OSL>OOP || OSL==0) && BE_Trigger!=0 && BE_Trigger>=STOPLEVEL)

               {

                  StLo = NormalizeDouble(OOP-BE_plusPunkts*_Point,_Digits); 

                  if ((StLo < OSL || OSL==0) && OOP >= NormalizeDouble(Ask + BE_Trigger * _Point,_Digits)) request.sl = StLo;

               }

               if(request.sl != OSL || request.tp != OTP)

               {

                  request.action    = TRADE_ACTION_SLTP;

                  request.position  = Ticket;

                  if(!OrderSend(request,result)) Print("error ",GetLastError());

               }

            }

         }  

      }  

   }

   

   for(i=0; i<OrdersTotal(); i++)

   {

      if((Ticket=OrderGetTicket(i))>0)

      {

         if(OrderGetInteger(ORDER_MAGIC)!=Magic || OrderGetString(ORDER_SYMBOL)!=_Symbol) continue;

         tip  = OrderGetInteger(ORDER_TYPE);

         OOP = OrderGetDouble(ORDER_PRICE_OPEN);

         if (tip==ORDER_TYPE_BUY_STOP) 

         {  

            PriceBuyStop = OOP;

            TicketBuyStop = Ticket;

            if (PriceB==0 || !BS)

            {

               ZeroMemory(request);

               ZeroMemory(result);

               request.action=TRADE_ACTION_REMOVE;

               request.order = Ticket;

               if(!OrderSend(request,result))

                  PrintFormat("OrderSend error %d",GetLastError());

               else continue;

            }

         }                                         

         if (tip==ORDER_TYPE_SELL_STOP) 

         {

            PriceSellStop = OOP;

            TicketSellStop = Ticket;

            if (PriceS==0 || !SS)

            {

               ZeroMemory(request);

               ZeroMemory(result);

               request.action=TRADE_ACTION_REMOVE;

               request.order = Ticket;

               if(!OrderSend(request,result))

                  PrintFormat("OrderSend error %d",GetLastError());

               else continue;

            }

         }                                         

      }

   }

   ObjectsDeleteAll(0,"#",0,OBJ_ARROW);

   if (UseSound)

   {

      if (b>0 && bOld==0) {Comment(TimeCurrent()," Open Buy");PlaySound(SoundSuccess);}

      if (s>0 && sOld==0) {Comment(TimeCurrent()," Open Sell");PlaySound(SoundSuccess);}

   }

   bOld=b;

   sOld=s;

  //---

  double SL,TP;

   if (BS && PriceB!=0)

   {

      if (PriceBuyStop==0)

      {

         PriceBuyStop=NormalizeDouble(PriceB + DistanceFromLine * _Point,_Digits);

         if (PriceBuyStop<Ask+STOPLEVEL*_Point) PriceBuyStop=NormalizeDouble(Ask+STOPLEVEL*_Point,_Digits);

         if (Takeprofit!=0) TP = NormalizeDouble(PriceBuyStop + Takeprofit * _Point,_Digits); else TP=0;

         if (Stoploss!=0)   SL = NormalizeDouble(PriceBuyStop - Stoploss   * _Point,_Digits); else SL=0;

            SendOrder(ORDER_TYPE_BUY_STOP,PriceBuyStop,Lots,SL,TP);

      }

      else

      {

         if (PriceBuyStop!=NormalizeDouble(PriceB + DistanceFromLine * _Point,_Digits))

         {

            PriceBuyStop=NormalizeDouble(PriceB + DistanceFromLine * _Point,_Digits);

            if (PriceBuyStop>=Ask+STOPLEVEL*_Point) 

            {

               if (Takeprofit!=0) TP = NormalizeDouble(PriceBuyStop + Takeprofit * _Point,_Digits); else TP=0;

               if (Stoploss!=0)   SL = NormalizeDouble(PriceBuyStop - Stoploss   * _Point,_Digits); else SL=0;

                  OrderModify(TicketBuyStop,PriceBuyStop,SL,TP);

            }

         }

      }

   }

   

   //---

   

   if (SS && PriceS!=0)

   {

      if (PriceSellStop==0)

      {

         PriceSellStop=NormalizeDouble(PriceS - DistanceFromLine * _Point,_Digits);

         if (PriceSellStop>Bid-STOPLEVEL*_Point) PriceSellStop=NormalizeDouble(Bid-STOPLEVEL*_Point,_Digits);

         if (Takeprofit!=0) TP = NormalizeDouble(PriceSellStop - Takeprofit * _Point,_Digits); else TP=0;

         if (Stoploss!=0)   SL = NormalizeDouble(PriceSellStop + Stoploss   * _Point,_Digits); else SL=0;

         SendOrder(ORDER_TYPE_SELL_STOP,PriceSellStop,Lots,SL,TP);

      }

      else

      {

         if (PriceSellStop!=NormalizeDouble(PriceS - DistanceFromLine * _Point,_Digits))

         {

            PriceSellStop=NormalizeDouble(PriceS - DistanceFromLine * _Point,_Digits);

            if (PriceSellStop<=Bid-STOPLEVEL*_Point) 

            {

               if (Takeprofit!=0) TP = NormalizeDouble(PriceSellStop - Takeprofit * _Point,_Digits); else TP=0;

               if (Stoploss!=0)   SL = NormalizeDouble(PriceSellStop + Stoploss   * _Point,_Digits); else SL=0;

                  OrderModify(TicketSellStop,PriceSellStop,SL,TP);

            }

         }

      }

   }

}

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

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=true,    // 2K45;8BL 4;O ?5@5<5I5=89 

                 const bool            ray_right=true,    // ?@>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) 

   {

      ObjectSetInteger(chart_ID,name,OBJPROP_TIME,0,time1); 

      ObjectSetInteger(chart_ID,name,OBJPROP_TIME,1,time2); 

      ObjectSetDouble(chart_ID,name,OBJPROP_PRICE,0,price1); 

      ObjectSetDouble(chart_ID,name,OBJPROP_PRICE,1,price2); 

      return(true); 

   }

   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); 

  } 

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

void OnDeinit(const int reason)

{

   switch(reason) 

   { 

   case REASON_ACCOUNT: //:B828@>20= 4@C3>9 AG5B ;81> ?@>87>H;> ?5@5?>4:;NG5=85 : B>@3>2><C A5@25@C 2A;54AB285 87<5=5=8O =0AB@>5: AG5B0

      break; 

   case REASON_CHARTCHANGE: //!8<2>; 8;8 ?5@8>4 3@0D8:0 1K; 87<5=5=

      break; 

   case REASON_CHARTCLOSE: //@0D8: 70:@KB

      ObjectDelete(0,"cm trend line");break; 

   case REASON_PARAMETERS: //E>4=K5 ?0@0<5B@K 1K;8 87<5=5=K ?>;L7>20B5;5<

      break; 

   case REASON_RECOMPILE: //@>3@0<<0 ?5@5:><?8;8@>20=0

      break; 

   case REASON_REMOVE: //@>3@0<<0 C40;5=0 A 3@0D8:0

      ObjectDelete(0,"cm trend line");break; 

   case REASON_TEMPLATE: //@8<5=5= 4@C3>9 H01;>= 3@0D8:0

      ObjectDelete(0,"cm trend line");break; 

   case REASON_PROGRAM://-:A?5@B ?@5:@0B8; A2>N @01>BC, 2K7202 DC=:F8N ExpertRemove()

      ObjectDelete(0,"cm trend line");break; 

   default:ObjectDelete(0,"cm trend line"); 

   } 

}

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

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=clrRed,               // F25B B5:AB0

                  const color             clrfon=clrBlack,          // F25B D>=0

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

                  const bool              state=false,       // F25B 3@0=8FK

                  const ENUM_BASE_CORNER  CORNER=CORNER_LEFT_LOWER)

  {

   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);

      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,1);

      ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);

   }

   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,clrfon);

   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);

}

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

double ObjectGetValueByShift(string name,int shift)

  {

   ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);

   MqlRates mql4[];

   CopyRates(NULL,timeframe,shift,1,mql4);

   return(ObjectGetValueByTime(0,name,mql4[0].time,0));

  }

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

uint SendOrder(ENUM_ORDER_TYPE Tip, double Price, double Lot, double SL, double TP)

{

   ZeroMemory(request);

   request.action = TRADE_ACTION_PENDING;

   request.magic  = Magic;

   request.symbol = _Symbol;

   request.volume = Lot;

   request.sl = SL;

   request.tp = TP;

   request.type=Tip;

   request.comment="www.cmillion.ru";

   request.price=Price;

   request.type_time=ORDER_TIME_GTC;

   request.expiration=0;



   if(OrderCheck(request,check))

   {

      if(!OrderSend(request,result))

         PrintFormat("Order Send error %d",GetLastError());  // 5A;8 >B?@028BL 70?@>A =5 C40;>AL, 2K25AB8 :>4 >H81:8

   

      Print(__FUNCTION__,":",result.comment); 

      if(result.retcode==10016) Print(result.bid,result.ask,result.price); 

   }

   return result.retcode;

}

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

void OrderModify(ulong Ticket, double Price, double SL, double TP)

{

   ZeroMemory(request);

   ZeroMemory(result);

   request.action=TRADE_ACTION_MODIFY;

   request.order = Ticket;

   request.price = Price; 

   request.sl = SL;

   request.tp = TP;

   request.type_time=ORDER_TIME_GTC;//ORDER_TIME_GTC

   request.expiration=0;



   if(!OrderSend(request,result))

      PrintFormat("Order Modify error %d",GetLastError());  // 5A;8 >B?@028BL 70?@>A =5 C40;>AL, 2K25AB8 :>4 >H81:8

   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);

  }

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

ENUM_TIMEFRAMES TFMigrate(int tf)

  {

   switch(tf)

     {

      case 0: return(PERIOD_CURRENT);

      case 1: return(PERIOD_M1);

      case 5: return(PERIOD_M5);

      case 15: return(PERIOD_M15);

      case 30: return(PERIOD_M30);

      case 60: return(PERIOD_H1);

      case 240: return(PERIOD_H4);

      case 1440: return(PERIOD_D1);

      case 10080: return(PERIOD_W1);

      case 43200: return(PERIOD_MN1);

      

      case 2: return(PERIOD_M2);

      case 3: return(PERIOD_M3);

      case 4: return(PERIOD_M4);      

      case 6: return(PERIOD_M6);

      case 10: return(PERIOD_M10);

      case 12: return(PERIOD_M12);

      case 16385: return(PERIOD_H1);

      case 16386: return(PERIOD_H2);

      case 16387: return(PERIOD_H3);

      case 16388: return(PERIOD_H4);

      case 16390: return(PERIOD_H6);

      case 16392: return(PERIOD_H8);

      case 16396: return(PERIOD_H12);

      case 16408: return(PERIOD_D1);

      case 32769: return(PERIOD_W1);

      case 49153: return(PERIOD_MN1);      

      default: return(PERIOD_CURRENT);

     }

  }

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---