Author: Copyright © 2013, MetaQuotes Software Corp.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open time of each bar
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersChecks for the total of closed ordersIt Closes Orders by itself
Indicators Used
Force indexMoving average indicatorRelative strength index
0 Views
0 Downloads
0 Favorites
martin2
ÿþ//+------------------------------------------------------------------+

//|                                                      martin2.mq4 |

//|                      Copyright © 2013, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

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

#property copyright "Copyright © 2013, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.net"



extern double stoploss=10000;   //stoploss level  

extern double takeprofit=10000;   //takeprofit level

extern double risk=0;            //risk if you're not using startlot

extern double lotexp=1.5;        //lot increment for second etc. orders

extern double locklotexp=1.3;    //lot increment for lock order

extern double periodf=13;        //Force Index period

extern double periodma=26;       //Moving Average period

extern double periodrsi=20;      //RSI period



extern double magicnumber=789;   //Magicnumber

extern string comment="martin";  //comment



extern string GvBuyTime="GV_BuyTime";  //Globalvariables

extern string GvSellTime="GV_SellTime";

extern string GvRsiLevels="GV_RsiLevels";

extern string GvRsiLevelb="GV_RsiLevelb";



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

//| expert initialization function                                   |

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

int init()

  {

//----

  GlobalVariableSet(GvBuyTime, 0);

  GlobalVariableSet(GvSellTime, 0);

  GlobalVariableSet(GvRsiLevels, 0);

  GlobalVariableSet(GvRsiLevelb, 0); 

//----

   return(0);

  }

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

//| expert deinitialization function                                 |

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

int deinit()

  {

//----

   ObjectDelete("Balance");

   ObjectDelete("."); 

//----

   

   return(0);

  }

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

//| expert start function                                            |

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

int start()

  {

//Signs

   ObjectCreate("Balance", OBJ_LABEL, 0, 0, 0, 0, 0);

   ObjectSet("Balance", OBJPROP_CORNER, 2);

   ObjectSet("Balance", OBJPROP_YDISTANCE, 15);

   ObjectSet("Balance", OBJPROP_XDISTANCE, 10);

   ObjectSetText("Balance", "Balance " + DoubleToStr(AccountBalance(), 2), 10, "Tahoma", Khaki);

   

   if (AccountEquity() != AccountBalance()) 

    {

   ObjectCreate(".", OBJ_LABEL, 0, 0, 0, 0, 0);

   ObjectSet(".", OBJPROP_CORNER, 2);

   ObjectSet(".", OBJPROP_YDISTANCE, 30);

   ObjectSet(".", OBJPROP_XDISTANCE, 10);

   if (AccountEquity() - AccountBalance() > 0) ObjectSetText(".", " +" + DoubleToStr(AccountEquity() - AccountBalance(), 2), 12, "Tahoma", Orange);

   else if (AccountEquity() - AccountBalance() < 0) ObjectSetText(".", " " + DoubleToStr(AccountEquity() - AccountBalance(), 2), 12, "Tahoma", OrangeRed);

    }  

     TradeSignal();

     CloseSignal();

   return(0);

 }





//-----------------criterias for orders' opening----------------------------------

void TradeSignal()

 { 

   double Force1=iForce(Symbol(),1,periodf,MODE_SMA,PRICE_CLOSE,1);

   double Force2=iForce(Symbol(),1,periodf,MODE_SMA,PRICE_CLOSE,2);

   double Force3=iForce(Symbol(),1,periodf,MODE_SMA,PRICE_CLOSE,3);

         

   static datetime ForceSell, ForceBuy;

   

   if (Force1<Force2 && Force2>Force3 && Force2>0.004) ForceSell=Time[1];

   if (TotalBuy()>0 || TotalSell()>0) ForceSell=0;

   if (Force1>Force2 && Force2<Force3 && Force2<-0.004) ForceBuy=Time[1];

   if (TotalBuy()>0 || TotalSell()>0) ForceBuy=0;

   

   double High1=iHigh(Symbol(),1,1);

   double Low1=iLow(Symbol(),1,1);

   double High2=iHigh(Symbol(),1,2);

   double Low2=iLow(Symbol(),1,2);

   double High3=iHigh(Symbol(),1,3);

   double Low3=iLow(Symbol(),1,3);

   

   double Med1=High1-(High1-Low1)/2;

   double Med2=High2-(High2-Low2)/2;

   double Med3=High3-(High3-Low3)/2;

  

  //-----------calculation of linear regression------------ 

   double sma1=iMA(Symbol(),1,periodma,0,MODE_SMA,PRICE_CLOSE,1);

   double sma2=iMA(Symbol(),1,periodma,0,MODE_SMA,PRICE_CLOSE,2);

   double sma3=iMA(Symbol(),1,periodma,0,MODE_SMA,PRICE_CLOSE,3);

   

   double lwma1=iMA(Symbol(),1,periodma,0,MODE_LWMA,PRICE_CLOSE,1);

   double lwma2=iMA(Symbol(),1,periodma,0,MODE_LWMA,PRICE_CLOSE,2);   

   double lwma3=iMA(Symbol(),1,periodma,0,MODE_LWMA,PRICE_CLOSE,3);

      

   double lr1=3.0*lwma1-2.0*sma1;

   double lr2=3.0*lwma2-2.0*sma2; 

   double lr3=3.0*lwma3-2.0*sma3; 

      

   double rsip0=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,0);

   double rsip1=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,1);

   double rsip2=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,2);

   double rsip3=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,3);

   

   //--------------opening criteria for sell orders----------------- 

   if(rsip1>70) GlobalVariableSet(GvRsiLevels, 1);

   if(rsip0<50) GlobalVariableSet(GvRsiLevels, 0);

   

   if(TotalSell()==0 && TotalBuy()==0)

    {

     if(TimeCurrent()>LastOrderClosedTime()+3600 && TimeCurrent()<ForceSell+1200)

      {

       if(rsip1>60)

        {

         if((Med1<Med2) || (lr3<lr2 && lr2>lr1)) OpenSell(lot());

        }

      }

    }    

   if(TotalSell()>=1 && TotalSell()<=2 && TotalBuy()==0)

    {

     if(TimeCurrent()>LastOpenTime()+120)

      {

       if(LastOrderType()==OP_SELL)

        {

         if(Ask>LastOpenPrice()+150*Point)

          {

           if(lr3<lr2 && lr2>lr1) OpenSell(NormalizeDouble(LastOpenLotS()*lotexp, 2));

          }

        }

      }

    } 

   

   if(TotalSell()>=3)

    {

     if(TimeCurrent()>LastOpenTime()+6800)

      {

       if(Bid>LastOpenPrice()+100*Point)

        {

         if(GlobalVariableGet(GvRsiLevels)==1 && rsip0<52)

          {

           OpenSell(NormalizeDouble(LastOpenLotS()*lotexp, 2));

           OpenBuy(NormalizeDouble(LastOpenLotS()/2*locklotexp, 2));

          }

        }

      }

    } 

   

 

 //--------------opening criteria for buy orders-----------------     

  if(rsip1<30) GlobalVariableSet(GvRsiLevelb, 1);

  if(rsip0>50) GlobalVariableSet(GvRsiLevelb, 0);

   

  if(TotalSell()==0 && TotalBuy()==0)

   {

    if(TimeCurrent()>LastOrderClosedTime()+3600 && TimeCurrent()<ForceBuy+1200)

     {

      if(rsip1<40)

       {

        if((Med1>Med2) || (lr3>lr2 && lr2<lr1)) OpenBuy(lot());

       }

     }

   }     

  if(TotalBuy()>=1 && TotalBuy()<=2 && TotalSell()==0)

   {

    if(TimeCurrent()>LastOpenTime()+120)

     {

      if(LastOrderType()==OP_BUY)

       {

        if(Bid<LastOpenPrice()-150*Point)

         {

          if(lr3>lr2 && lr2<lr1) OpenBuy(NormalizeDouble(LastOpenLotB()*lotexp, 2));

         }

       }

     }

   }      

  if(TotalBuy()>=3)

   {

    if(TimeCurrent()>LastOpenTime()+6800)

     {

      if(Ask<LastOpenPrice()-100*Point)

       {

        if(GlobalVariableGet(GvRsiLevelb)==1 && rsip0>48)

         {

          OpenBuy(NormalizeDouble(LastOpenLotB()*lotexp, 2));

          OpenSell(NormalizeDouble(LastOpenLotB()/2*locklotexp, 2));

         }

       }

     }     

   }

 } 



//----------------------------criterias for orders' closing------------------------------------

void CloseSignal()

 {

   double sma1=iMA(Symbol(),1,periodma,0,MODE_SMA,PRICE_CLOSE,1);

   double sma2=iMA(Symbol(),1,periodma,0,MODE_SMA,PRICE_CLOSE,2);

   double sma3=iMA(Symbol(),1,periodma,0,MODE_SMA,PRICE_CLOSE,3);

   

   double lwma1=iMA(Symbol(),1,periodma,0,MODE_LWMA,PRICE_CLOSE,1);

   double lwma2=iMA(Symbol(),1,periodma,0,MODE_LWMA,PRICE_CLOSE,2);   

   double lwma3=iMA(Symbol(),1,periodma,0,MODE_LWMA,PRICE_CLOSE,3);

   

   double lr1=3.0*lwma1-2.0*sma1;

   double lr2=3.0*lwma2-2.0*sma2; 

   double lr3=3.0*lwma3-2.0*sma3;

   

   double rsi0=iRSI(Symbol(),1,periodrsi,PRICE_CLOSE,0);

   double rsi1=iRSI(Symbol(),1,periodrsi,PRICE_CLOSE,1);

   double rsi2=iRSI(Symbol(),1,periodrsi,PRICE_CLOSE,2);

   double rsi3=iRSI(Symbol(),1,periodrsi,PRICE_CLOSE,3);

   

   double rsip0=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,0);

   double rsip1=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,1);

   double rsip2=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,2);

   double rsip3=iRSI(Symbol(),15,periodrsi,PRICE_CLOSE,3);

   

   if(TotalSell()>=0 && TotalSell()<=3 && TotalBuy()==0)

    {

     if(FirstOpenType()==1)

      {

       if(CountSellPoint()>80)

        {

         if((rsi1<40 && rsi3>rsi2 && rsi2<rsi1) || (lr3>lr2 && lr2<lr1)) CloseSellOrders();

        }

      }

    }   

   else if(TotalSell()>=4)

    {

     if(FirstOpenType()==1)

      {

       if(CountBuyPL()+CountSellPL()>20)

        {

         if((rsi1<40 && rsi3>rsi2 && rsi2<rsi1) || (lr3>lr2 && lr2<lr1)) 

          {

           CloseSellOrders();

           CloseBuyOrders();

          }

        }

      }

    }  

   if(TotalSell()>=4 && TotalBuy()>1) CloseBuyOrder();

  

   if(TotalBuy()>=0 && TotalBuy()<=3 && TotalSell()==0)

    {

     if(FirstOpenType()==0)

      {

       if(CountBuyPoint()>80)

        {

         if((rsi1>60 && rsi3<rsi2 && rsi2>rsi1) || (lr3<lr2 && lr2>lr1)) CloseBuyOrders();

        }

      }

    } 

      

  else if(TotalBuy()>=4)

   {

    if(FirstOpenType()==0)

     {

      if(CountBuyPL()+CountSellPL()>20)

       {

        if((rsi1>60 && rsi3<rsi2 && rsi2>rsi1) || (lr3<lr2 && lr2>lr1))

         {

          CloseSellOrders();

          CloseBuyOrders();

         }

       }

     }

   }   

  if(TotalBuy()>=4 && TotalSell()>1) CloseSellOrder();

 }



//----------------------------Lot calculation-----------------------------------   



double lot()

 {

   RefreshRates();



   double minlot=MarketInfo(Symbol(),MODE_MINLOT);

   double maxlot=MarketInfo(Symbol(),MODE_MAXLOT);

   double free=AccountFreeMargin();

   double onelot=MarketInfo(Symbol(),MODE_MARGINREQUIRED);

   double lotsize=MarketInfo(Symbol(),MODE_LOTSIZE);

   double stepp=MarketInfo(Symbol(),MODE_LOTSTEP);

   double spread=MarketInfo(Symbol(),MODE_SPREAD);

   int leverage=AccountLeverage();



   double lots=0.01;

         

   if(risk==0) lots=NormalizeDouble(minlot,2);

   else if(risk>0) lots=NormalizeDouble((free*(risk)/100)/(onelot*leverage/500*stepp)*stepp, 2);

      

   if(lots>maxlot) lots=NormalizeDouble(maxlot,2);

   if(lots<minlot) lots=NormalizeDouble(minlot,2);

   

   return(lots);

 }



//-----------------------------Sell order opening------------------------

  

  void OpenSell(double lot)

   {

    if (!IsTradeAllowed()) Sleep(5000);

    RefreshRates();

    double dg=MarketInfo(Symbol(),MODE_DIGITS);

    double sask=MarketInfo(Symbol(),MODE_ASK);

    double sbid=MarketInfo(Symbol(),MODE_BID);

    sask=NormalizeDouble(sask,dg);

    sbid=NormalizeDouble(sbid,dg);

    double sls=NormalizeDouble(sask+stoploss*Point,dg);

    double tps=NormalizeDouble(sask-takeprofit*Point,dg);

    int error;      

    if(GlobalVariableGet(GvSellTime)!=Time[0])

     {

      int Tic=OrderSend(Symbol(),OP_SELL,lot,sbid,2,sls,tps,comment,magicnumber,0,Khaki);

     }

    if (Tic>0) GlobalVariableSet(GvSellTime, Time[0]);

    else error=GetLastError();

   }



//-----------------------------Buy order opening------------------------

  

  void OpenBuy(double lot)

   {

    if(!IsTradeAllowed()) Sleep(5000);

    RefreshRates();

    double dg=MarketInfo(Symbol(),MODE_DIGITS);

    double bask=MarketInfo(Symbol(),MODE_ASK);

    double bbid=MarketInfo(Symbol(),MODE_BID);

    bask=NormalizeDouble(bask,dg);

    bbid=NormalizeDouble(bbid,dg);

    double slb=NormalizeDouble(bbid-stoploss*Point,dg);

    double tpb=NormalizeDouble(bbid+takeprofit*Point,dg);

    int error;      

    if (GlobalVariableGet(GvBuyTime)!=Time[0])

     {

      int Ticb=OrderSend(Symbol(),OP_BUY,lot,bask,2,slb,tpb,comment,magicnumber,0,Khaki);

     }

    if (Ticb>0) GlobalVariableSet(GvBuyTime,Time[0]);

    else error=GetLastError();

   }



//----------------------------calculation of opened buy orders------------------------------------

 int TotalBuy() 

  {

   int countb=0;

   for(int tradeb=OrdersTotal()-1; tradeb>=0; tradeb--) 

    {

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

      {

       if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)

        {

         if(OrderType()==OP_BUY) countb++;

        }

      }  

    }

   return(countb);

  }



//----------------------------calculation of opened sell orders------------------------------------



 int TotalSell() 

  {

   int counts=0;

   for(int trades=OrdersTotal()-1; trades>=0; trades--) 

    {

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

      {

       if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)

        {

         if(OrderType()==OP_SELL) counts++;

        }

      } 

    }

   return(counts);

  }



//-----------------------Last opened order open price-------------------------------



double LastOpenPrice()

 {

  datetime opentime=0;

  int ticket;

  for(int b=OrdersTotal()-1; b>=0; b--)

   {

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

     {

      if(OrderMagicNumber()==magicnumber && opentime<OrderOpenTime())

       {

        opentime=OrderOpenTime();

        ticket=OrderTicket();

       }           

       

      if(opentime==0) return(-1);

      if(OrderTicket()!=ticket) OrderSelect(ticket,SELECT_BY_TICKET);

     } 

   }   

  return(OrderOpenPrice());

 }      



//-----------------------Last opened order open time-------------------------------



datetime LastOpenTime()

 {

  datetime opentimeq=0;

  int ticketq;

  for(int b4=OrdersTotal()-1; b4>=0; b4--)

   {

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

     {

      if(OrderMagicNumber()==magicnumber && opentimeq<OrderOpenTime())

       {

        opentimeq=OrderOpenTime();

        ticketq=OrderTicket();

       }           

      if(opentimeq==0) return(-1);

      if(OrderTicket()!=ticketq) OrderSelect(ticketq,SELECT_BY_TICKET);

     } 

   }   

  return(opentimeq);

 }



//-----------------------Last opened order type-------------------------------



double LastOrderType()

 {

  datetime opentime2=0;

  int ticket5;

  for(int we=OrdersTotal()-1; we>=0; we--)

   {

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

     {

      if(OrderMagicNumber()==magicnumber && opentime2<OrderOpenTime())

       {

        opentime2=OrderOpenTime();

        ticket5=OrderTicket();

       }           

      if(opentime2==0) return(-1);

      if(OrderTicket()!=ticket5) OrderSelect(ticket5,SELECT_BY_TICKET);

     } //end of OrderSelect

   }   //end of for

  return(OrderType());

 }

  

 //-----------------------First opened order type-------------------------------



double FirstOpenType()

 {

  datetime FirstOpenTimeq = 99999999999999;

  int ticketq;

  int type;

  for(int syaq=OrdersTotal()-1; syaq>=0; syaq--)

   {

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

     {

      if(OrderMagicNumber()==magicnumber && FirstOpenTimeq>OrderOpenTime())

       {

        FirstOpenTimeq=OrderOpenTime();

        ticketq=OrderTicket();

        type=OrderType();

       } 

      if(OrderTicket()!=ticketq) OrderSelect(ticketq,SELECT_BY_TICKET);                  

     } 

    }  

  return(type);

 }



//-----------------------First opened Buy order open time-------------------------------



datetime FirstOpenTimeB()

 {

  datetime FirstOpenTimeB1 = 99999999999999;

  int ticketB777;

  for(int syb=OrdersTotal()-1; syb>=0; syb--)

   {

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

     {

      if(OrderMagicNumber()==magicnumber && OrderType()==OP_BUY && FirstOpenTimeB1>OrderOpenTime())

       {

        FirstOpenTimeB1=OrderOpenTime();

        ticketB777=OrderTicket();

       } 

      if(OrderTicket()!=ticketB777) OrderSelect(ticketB777,SELECT_BY_TICKET);                  

     } 

   } 

  return(FirstOpenTimeB1);

 }



//-----------------------First opened Sell order open time-------------------------------



datetime FirstOpenTimeS()

 {

  datetime FirstOpenTimeS1 = 99999999999999;

  int ticketS777;

  for(int sys=OrdersTotal()-1; sys>=0; sys--)

   {

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

     {

      if(OrderMagicNumber()==magicnumber && OrderType()==OP_SELL && FirstOpenTimeS1>OrderOpenTime())

       {

        FirstOpenTimeS1=OrderOpenTime();

        ticketS777=OrderTicket();

       } 

      if(OrderTicket()!=ticketS777) OrderSelect(ticketS777,SELECT_BY_TICKET);                  

     } 

   }  

  return(FirstOpenTimeS1);

 }

   

//-----------------------Last closed order closed time in history -------------------------------



datetime LastOrderClosedTime()

 {

  datetime lasttime2 = 0;

  for(int ql=OrdersHistoryTotal()-1; ql>=0; ql--)

   {

    if(OrderSelect(ql, SELECT_BY_POS,MODE_HISTORY)==true) 

     {

      if(OrderMagicNumber()==magicnumber)

        {       

        if(lasttime2<OrderCloseTime())

         {

          lasttime2=OrderCloseTime();

         }

       }

     }

   }

  return(lasttime2);

 }



//----------------------------Last opened Sell order lots------------------------------------



double LastOpenLotS()

 {

  datetime lasttimea = 0;

  double lots1;

  for(int qed=OrdersTotal()-1; qed>=0; qed--) 

   {

    if(OrderSelect(qed,SELECT_BY_POS, MODE_TRADES))

     {

      RefreshRates();

      if(OrderMagicNumber()==magicnumber && OrderType()==OP_SELL && lasttimea<OrderOpenTime()) 

       {

        lasttimea=OrderOpenTime();

        lots1=OrderLots();

       } 

     } 

   }  

  return(lots1);

 } 



//----------------------------Last opened Buy order lots------------------------------------



double LastOpenLotB()

 {

  datetime lasttimeb = 0;

  double lots2;

  for(int qeb=OrdersTotal()-1; qeb>=0; qeb--) 

   {

    if(OrderSelect(qeb,SELECT_BY_POS, MODE_TRADES))

     {

      RefreshRates();

      if(OrderMagicNumber()==magicnumber && OrderType()==OP_BUY && lasttimeb<OrderOpenTime()) 

       {

        lasttimeb = OrderOpenTime();

        lots2 = OrderLots();

       } 

     } 

   } 

  return(lots2);

 } 

      

//----------------------------Profit or Loss for Buy orders------------------------------------



double CountBuyPL()

 {

  double pj1l=0.0;

  for(int drl=OrdersTotal()-1; drl>=0; drl--)

   {

    if(OrderSelect(drl,SELECT_BY_POS,MODE_TRADES))

     {

      RefreshRates();

      if(OrderSymbol()==Symbol())

       {

        if(OrderMagicNumber()==magicnumber)

         {

          if(OrderType()==OP_BUY)

           {

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

           }

         }

       }

     }

   }

  return(pj1l);

 }



//----------------------------------Total sell orders profit/loss-------------------------------



double CountSellPL()

 {

  double pj2l=0;

  for(int srl=OrdersTotal()-1; srl>=0; srl--)

   {

    if(OrderSelect(srl,SELECT_BY_POS,MODE_TRADES))

     {

      RefreshRates();

      if(OrderSymbol()==Symbol())

       {

        if(OrderMagicNumber()==magicnumber)

         {

          if(OrderType()==OP_SELL)

           {

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

           }

         }

       }

     }

   }

  return(pj2l);

 }

 

//----------------------------Sum of points for opened Buy orders------------------------------------



double CountBuyPoint()

 {

  double countbp=0.0;

  for(int dr=OrdersTotal()-1; dr>=0; dr--)

   {

    if(OrderSelect(dr,SELECT_BY_POS,MODE_TRADES))

     {

      RefreshRates();

      if(OrderSymbol()==Symbol())

       {

        if(OrderMagicNumber()==magicnumber)

         {

          if(OrderType()==OP_BUY)

           {

            countbp+=(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice());

           }

         }

       }

     }

   }

  return(countbp/Point);

 }

 

//----------------------------Sum of points for opened Sell orders------------------------------------



double CountSellPoint()

 {

  double countsp=0.0;

  for(int sr=OrdersTotal()-1; sr>=0; sr--)

   {

    if(OrderSelect(sr,SELECT_BY_POS,MODE_TRADES))

     {

      RefreshRates();

      if(OrderSymbol()==Symbol())

       {

        if(OrderMagicNumber()==magicnumber)

         {

          if(OrderType()==OP_SELL)

           {

            countsp+=(OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK));

           }

         }

       }

     }

   }

  return(countsp/Point);

 } 

  

//-----------------------Closing all Sell orders-----------------------------------------



void CloseSellOrders()

 {

  for(int tu=OrdersTotal()-1; tu>=0; tu--)

   {

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

     {

      if(OrderSymbol()==Symbol())

       {

        if(OrderType()==OP_SELL)

         {

          if(OrderMagicNumber()==magicnumber)

           {

            bool cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),5000,clrBlue);

            if(cl==false) GetLastError();

           }

         }

       }

     }

   }

 }



//--------------------------Close all buy orders------------------------------------



void CloseBuyOrders()

 {

  for(int tw=OrdersTotal()-1; tw>=0; tw--)

   {

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

     {

      if(OrderSymbol()==Symbol())

       {

        if(OrderType()==OP_BUY)

         {

          if(OrderMagicNumber()==magicnumber)

           {

            bool clb=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),500,clrBlue);

            if(clb==false) GetLastError();

           }

         }

       }

     }

   }

 }



//-----------------------Closing locking order Buy-----------------------------------------



void CloseBuyOrder()

 {

  while(true)

   {

    for (int tb=OrdersTotal()-1; tb>=0; tb--)

     {

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

       {

        if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magicnumber)

         {

          if(OrderOpenTime()==FirstOpenTimeB())

           {

            RefreshRates();

            bool gd=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits), 2,Blue);

            if(gd==true) break;

            if (gd==false) GetLastError();

           }

         }

       }

     }

   break;

  } 

}

 

//-----------------------Closing locking order Sell-----------------------------------------



void CloseSellOrder()

 {

  while(true)

   {

    for(int ts=OrdersTotal()-1; ts>=0; ts--)

     {

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

       {

        if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==magicnumber)

         {

          if(OrderOpenTime()==FirstOpenTimeS())

           {

            RefreshRates();

            bool gs=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits), 2,Blue);

            if(gs==true) break;

            if(gs==false) GetLastError();

           }

         }

       }

     }

   break;

  } 

}

 



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