Detected Country () : English
Create Triple Moving Average Cross Robot - codingforex.com

Welcome to CodingForex.Com!

Knowledge portal where you can learn how to create forex indicators and robot.

Click button below to choose level that suite you:

Create Triple Moving Average Cross Robot

Samples [2018-05-01 12:22:13] - by hillzx
Featured Image

This time we will make EA Moving Average Cross with 3 moving average.

Here's the logic :

  • Robot will wait for MA Faster to penetrate Middle MA and Slower MA
  • If the MA Faster is higher than Middle & Slower MA, then the robot will conduct Buy transaction
  • Conversely, if the MA Faster is lower than Middle & Slower MA, then the robot will conduct a Sell transaction
  • Robot will close the transaction if there is a trend change

 

triple ma buytriple ma sell



Create Extern code:

//+------------------------------------------------------------------+
//| Extern Settings                                  |
//+------------------------------------------------------------------+
extern string info1="Faster Moving Average";
extern ENUM_TIMEFRAMES MA1_TF=PERIOD_CURRENT;
extern int MA1_Period=10;
extern int MA1_Shift=0;
extern ENUM_MA_METHOD MA1_Method=MODE_SMA;
extern ENUM_APPLIED_PRICE MA1_Apply=PRICE_CLOSE;
extern int MA1_Candle=1;

extern string info2="-";
extern string info3="Middle Moving Average";
extern ENUM_TIMEFRAMES MA2_TF=PERIOD_CURRENT;
extern int MA2_Period=100;
extern int MA2_Shift=0;
extern ENUM_MA_METHOD MA2_Method=MODE_SMA;
extern ENUM_APPLIED_PRICE MA2_Apply=PRICE_CLOSE;
extern int MA2_Candle=1;

extern string info4="-";
extern string info5="Slower Moving Average";
extern ENUM_TIMEFRAMES MA3_TF=PERIOD_CURRENT;
extern int MA3_Period=200;
extern int MA3_Shift=0;
extern ENUM_MA_METHOD MA3_Method=MODE_SMA;
extern ENUM_APPLIED_PRICE MA3_Apply=PRICE_CLOSE;
extern int MA3_Candle=1;

extern string info6="-";
extern string info7="GUI";
extern int Corner=0;
extern int XPos=0;
extern int YPos=0;
extern color TextColor1=White;
extern color TextColor2=Yellow;
extern color TextColor3=DarkOrange;

extern string info8="-";
extern string info9="Trade";
extern double LotSize=0.01;
extern int TakeProfit=0;
extern int StopLoss=0;
extern int Slippage=5;
extern int MagicNumber=123;

 

Create Intern code :

//+------------------------------------------------------------------+
//| Intern Settings                                 |
//+------------------------------------------------------------------+
int oldTime;
double fasterMaCurrent;
double middleMaCurrent;
double slowerMaCurrent;
double fasterMaBefore;
double middleMaBefore;
double slowerMaBefore;
bool isUpTrendCurrent;
bool isUpTrendBefore;



Next, create modules Init, Deinit, OnTick, and DeleteObject:

//+------------------------------------------------------------------+
//| Code Init                              |
//+------------------------------------------------------------------+
void DeleteObjects()
  {
   for(int i=ObjectsTotal()-1; i>-1; i--)
     {
      if(StringFind(ObjectName(i),"TxtHiLLzXMaTripleCross")>=0) ObjectDelete(ObjectName(i));
     }
  }
int OnInit()
  {
//---
DeleteObjects();
UpdateMAPrice();
WriteText();
oldTime=Time[0];
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
DeleteObjects();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
if(oldTime != Time[0] )
{
   oldTime = Time[0];
   UpdateMAPrice();
   WriteText();
   
   if (fasterMaCurrent!=0 && middleMaCurrent!=0 && slowerMaCurrent!=0){
      Execute();
   }
} 
  }
//+------------------------------------------------------------------+



Create GetPriceMA module to get the price of Moving Average :

double GetPriceMA(ENUM_TIMEFRAMES currentTf,int currentPeriod,int currentShift,ENUM_MA_METHOD currentMethod,ENUM_APPLIED_PRICE currentApply,int currentCandle){
   return iMA(NULL,currentTf,currentPeriod,currentShift,currentMethod,currentApply,currentCandle);
}

 

Create UpdateMAPrice module to update current price of MA :

void UpdateMAPrice(){
   fasterMaCurrent=GetPriceMA(MA1_TF,MA1_Period,MA1_Shift,MA1_Method,MA1_Apply,MA1_Candle);
   middleMaCurrent=GetPriceMA(MA2_TF,MA2_Period,MA2_Shift,MA2_Method,MA2_Apply,MA2_Candle);
   slowerMaCurrent=GetPriceMA(MA3_TF,MA3_Period,MA3_Shift,MA3_Method,MA3_Apply,MA3_Candle);
   if ( (fasterMaCurrent>middleMaCurrent) && (fasterMaCurrent>slowerMaCurrent) ){
      isUpTrendCurrent=true;
   } else if ( (fasterMaCurrent<middleMaCurrent) && (fasterMaCurrent<slowerMaCurrent) ){
      isUpTrendCurrent=false;
   }
   
   fasterMaBefore=GetPriceMA(MA1_TF,MA1_Period,MA1_Shift,MA1_Method,MA1_Apply,(MA1_Candle+1));
   middleMaBefore=GetPriceMA(MA2_TF,MA2_Period,MA2_Shift,MA2_Method,MA2_Apply,(MA2_Candle+1));
   slowerMaBefore=GetPriceMA(MA3_TF,MA3_Period,MA3_Shift,MA3_Method,MA3_Apply,(MA3_Candle+1));
   if ( (fasterMaBefore>middleMaBefore) && (fasterMaBefore>slowerMaBefore) ){
      isUpTrendBefore=true;
   } else if ( (fasterMaBefore<middleMaBefore) && (fasterMaBefore<slowerMaBefore) ){
      isUpTrendBefore=false;
   }
}

 

Next create WriteText module to write text on screen :

void WriteText(){

   ObjectCreate("TxtHiLLzXMaTripleCross1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross1",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross1",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross1","Current Faster MA Price : " + DoubleToStr(fasterMaCurrent,Digits) ,14,"Arial",TextColor1);
   
   ObjectCreate("TxtHiLLzXMaTripleCross2",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross2",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross2",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross2",OBJPROP_YDISTANCE,20+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross2","Current Middle MA Price : " + DoubleToStr(middleMaCurrent,Digits) ,14,"Arial",TextColor2);
   
   ObjectCreate("TxtHiLLzXMaTripleCross3",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross3",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross3",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross3",OBJPROP_YDISTANCE,40+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross3","Current Slower MA Price : " + DoubleToStr(slowerMaCurrent,Digits) ,14,"Arial",TextColor3);
   
   ObjectCreate("TxtHiLLzXMaTripleCross4",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross4",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross4",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross4",OBJPROP_YDISTANCE,60+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross4","Before Faster MA Price : " + DoubleToStr(fasterMaBefore,Digits) ,14,"Arial",TextColor1);
   
   ObjectCreate("TxtHiLLzXMaTripleCross5",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross5",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross5",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross5",OBJPROP_YDISTANCE,80+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross5","Before Middle MA Price : " + DoubleToStr(middleMaBefore,Digits) ,14,"Arial",TextColor2);
   
   ObjectCreate("TxtHiLLzXMaTripleCross6",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross6",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross6",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross6",OBJPROP_YDISTANCE,100+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross6","Before Slower MA Price : " + DoubleToStr(slowerMaBefore,Digits) ,14,"Arial",TextColor3);

}

 

Create Execute module to check transaction logic :

void Execute(){

   string currentStatus;
   
   if (isUpTrendCurrent==isUpTrendBefore){
      if (isUpTrendCurrent==true){
         currentStatus="Uptrend";
      } else {
         currentStatus="Downtrend";
      }
   } else {
      CloseThis();
      if (isUpTrendCurrent==true){
         OrderBuy();
         currentStatus="Before is downtrend, now uptrend";
      } else {
         OrderSell();
         currentStatus="Before is uptrend, now is downtrend";
      }
   }
   
   ObjectCreate("TxtHiLLzXMaTripleCross7",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross7",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross7",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross7",OBJPROP_YDISTANCE,120+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross7",currentStatus ,14,"Arial",TextColor2);
   

}

 

Lastly, here's the code to do transaction :

void OrderBuy() {

double tp;
double sl;

if (TakeProfit==0){
   tp=0;
} else {
   tp=Ask+TakeProfit*Point;
}

if (StopLoss==0){
   sl=0;
} else {
   sl=Ask-StopLoss*Point;
}


int ticket;
for(int i=0;i<3;i++)
{
   string errorMsg;
   ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,sl,tp,"HiLLzX Triple MA Buy",MagicNumber,0,CLR_NONE);
      
   if(ticket>0){break;}
   RefreshRates();
}

}

void OrderSell() {



double tp;
double sl;

if (TakeProfit==0){
   tp=0;
} else {
   tp=Bid-TakeProfit*Point;
}

if (StopLoss==0){
   sl=0;
} else {
   sl=Bid+StopLoss*Point;
}


int ticket;
for(int i=0;i<3;i++)
{
   string errorMsg;
   ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,sl,tp,"HiLLzX Triple MA Sell",MagicNumber,0,CLR_NONE);

   if(ticket>0){break;}
   RefreshRates();
}

}

void CloseThis() {
   bool closed = false;
   for (int i = OrdersTotal(); i >=0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      while(IsTradeContextBusy()) Sleep(100);
      RefreshRates();
      if ( OrderType() == OP_BUY && Symbol() == OrderSymbol() 
      && MagicNumber == OrderMagicNumber() ) {
        closed = OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, White);
      }
      if (OrderType() == OP_SELL && Symbol() == OrderSymbol()
       && MagicNumber == OrderMagicNumber() ) {
        closed = OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, White);
      }
   }
   
return;

}



Ok guys, EA can now be compiled. If you need the full source code, grab this code below :

//+------------------------------------------------------------------+
//                                  HiLLzX Triple Moving Average.mq4 |
//|                                                 hillzx@gmail.com |
//|                                                 hillzx@gmail.com |
//+------------------------------------------------------------------+
#property copyright "hillzx@gmail.com"
#property link      "hillzx@gmail.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| Extern Settings                                  |
//+------------------------------------------------------------------+
extern string info1="Faster Moving Average";
extern ENUM_TIMEFRAMES MA1_TF=PERIOD_CURRENT;
extern int MA1_Period=10;
extern int MA1_Shift=0;
extern ENUM_MA_METHOD MA1_Method=MODE_SMA;
extern ENUM_APPLIED_PRICE MA1_Apply=PRICE_CLOSE;
extern int MA1_Candle=1;

extern string info2="-";
extern string info3="Middle Moving Average";
extern ENUM_TIMEFRAMES MA2_TF=PERIOD_CURRENT;
extern int MA2_Period=100;
extern int MA2_Shift=0;
extern ENUM_MA_METHOD MA2_Method=MODE_SMA;
extern ENUM_APPLIED_PRICE MA2_Apply=PRICE_CLOSE;
extern int MA2_Candle=1;

extern string info4="-";
extern string info5="Slower Moving Average";
extern ENUM_TIMEFRAMES MA3_TF=PERIOD_CURRENT;
extern int MA3_Period=200;
extern int MA3_Shift=0;
extern ENUM_MA_METHOD MA3_Method=MODE_SMA;
extern ENUM_APPLIED_PRICE MA3_Apply=PRICE_CLOSE;
extern int MA3_Candle=1;

extern string info6="-";
extern string info7="GUI";
extern int Corner=0;
extern int XPos=0;
extern int YPos=0;
extern color TextColor1=White;
extern color TextColor2=Yellow;
extern color TextColor3=DarkOrange;

extern string info8="-";
extern string info9="Trade";
extern double LotSize=0.01;
extern int TakeProfit=0;
extern int StopLoss=0;
extern int Slippage=5;
extern int MagicNumber=123;

//+------------------------------------------------------------------+
//| Intern Settings                                 |
//+------------------------------------------------------------------+
int oldTime;
double fasterMaCurrent;
double middleMaCurrent;
double slowerMaCurrent;
double fasterMaBefore;
double middleMaBefore;
double slowerMaBefore;
bool isUpTrendCurrent;
bool isUpTrendBefore;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Code Init                              |
//+------------------------------------------------------------------+
void DeleteObjects()
  {
   for(int i=ObjectsTotal()-1; i>-1; i--)
     {
      if(StringFind(ObjectName(i),"TxtHiLLzXMaTripleCross")>=0) ObjectDelete(ObjectName(i));
     }
  }
int OnInit()
  {
//---
DeleteObjects();
UpdateMAPrice();
WriteText();
oldTime=Time[0];
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
DeleteObjects();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
if(oldTime != Time[0] )
{
   oldTime = Time[0];
   UpdateMAPrice();
   WriteText();
   
   if (fasterMaCurrent!=0 && middleMaCurrent!=0 && slowerMaCurrent!=0){
      Execute();
   }
} 
  }
//+------------------------------------------------------------------+

double GetPriceMA(ENUM_TIMEFRAMES currentTf,int currentPeriod,int currentShift,ENUM_MA_METHOD currentMethod,ENUM_APPLIED_PRICE currentApply,int currentCandle){
   return iMA(NULL,currentTf,currentPeriod,currentShift,currentMethod,currentApply,currentCandle);
}

void UpdateMAPrice(){
   fasterMaCurrent=GetPriceMA(MA1_TF,MA1_Period,MA1_Shift,MA1_Method,MA1_Apply,MA1_Candle);
   middleMaCurrent=GetPriceMA(MA2_TF,MA2_Period,MA2_Shift,MA2_Method,MA2_Apply,MA2_Candle);
   slowerMaCurrent=GetPriceMA(MA3_TF,MA3_Period,MA3_Shift,MA3_Method,MA3_Apply,MA3_Candle);
   if ( (fasterMaCurrent>middleMaCurrent) && (fasterMaCurrent>slowerMaCurrent) ){
      isUpTrendCurrent=true;
   } else if ( (fasterMaCurrent<middleMaCurrent) && (fasterMaCurrent<slowerMaCurrent) ){
      isUpTrendCurrent=false;
   }
   
   fasterMaBefore=GetPriceMA(MA1_TF,MA1_Period,MA1_Shift,MA1_Method,MA1_Apply,(MA1_Candle+1));
   middleMaBefore=GetPriceMA(MA2_TF,MA2_Period,MA2_Shift,MA2_Method,MA2_Apply,(MA2_Candle+1));
   slowerMaBefore=GetPriceMA(MA3_TF,MA3_Period,MA3_Shift,MA3_Method,MA3_Apply,(MA3_Candle+1));
   if ( (fasterMaBefore>middleMaBefore) && (fasterMaBefore>slowerMaBefore) ){
      isUpTrendBefore=true;
   } else if ( (fasterMaBefore<middleMaBefore) && (fasterMaBefore<slowerMaBefore) ){
      isUpTrendBefore=false;
   }
}

void WriteText(){

   ObjectCreate("TxtHiLLzXMaTripleCross1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross1",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross1",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross1","Current Faster MA Price : " + DoubleToStr(fasterMaCurrent,Digits) ,14,"Arial",TextColor1);
   
   ObjectCreate("TxtHiLLzXMaTripleCross2",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross2",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross2",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross2",OBJPROP_YDISTANCE,20+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross2","Current Middle MA Price : " + DoubleToStr(middleMaCurrent,Digits) ,14,"Arial",TextColor2);
   
   ObjectCreate("TxtHiLLzXMaTripleCross3",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross3",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross3",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross3",OBJPROP_YDISTANCE,40+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross3","Current Slower MA Price : " + DoubleToStr(slowerMaCurrent,Digits) ,14,"Arial",TextColor3);
   
   ObjectCreate("TxtHiLLzXMaTripleCross4",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross4",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross4",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross4",OBJPROP_YDISTANCE,60+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross4","Before Faster MA Price : " + DoubleToStr(fasterMaBefore,Digits) ,14,"Arial",TextColor1);
   
   ObjectCreate("TxtHiLLzXMaTripleCross5",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross5",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross5",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross5",OBJPROP_YDISTANCE,80+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross5","Before Middle MA Price : " + DoubleToStr(middleMaBefore,Digits) ,14,"Arial",TextColor2);
   
   ObjectCreate("TxtHiLLzXMaTripleCross6",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross6",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross6",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross6",OBJPROP_YDISTANCE,100+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross6","Before Slower MA Price : " + DoubleToStr(slowerMaBefore,Digits) ,14,"Arial",TextColor3);

}

void Execute(){

   string currentStatus;
   
   if (isUpTrendCurrent==isUpTrendBefore){
      if (isUpTrendCurrent==true){
         currentStatus="Uptrend";
      } else {
         currentStatus="Downtrend";
      }
   } else {
      CloseThis();
      if (isUpTrendCurrent==true){
         OrderBuy();
         currentStatus="Before is downtrend, now uptrend";
      } else {
         OrderSell();
         currentStatus="Before is uptrend, now is downtrend";
      }
   }
   
   ObjectCreate("TxtHiLLzXMaTripleCross7",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("TxtHiLLzXMaTripleCross7",OBJPROP_CORNER,Corner);
   ObjectSet("TxtHiLLzXMaTripleCross7",OBJPROP_XDISTANCE,XPos );
   ObjectSet("TxtHiLLzXMaTripleCross7",OBJPROP_YDISTANCE,120+YPos);
   ObjectSetText("TxtHiLLzXMaTripleCross7",currentStatus ,14,"Arial",TextColor2);
   

}

void OrderBuy() {

double tp;
double sl;

if (TakeProfit==0){
   tp=0;
} else {
   tp=Ask+TakeProfit*Point;
}

if (StopLoss==0){
   sl=0;
} else {
   sl=Ask-StopLoss*Point;
}


int ticket;
for(int i=0;i<3;i++)
{
   string errorMsg;
   ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,sl,tp,"HiLLzX Triple MA Buy",MagicNumber,0,CLR_NONE);
      
   if(ticket>0){break;}
   RefreshRates();
}

}

void OrderSell() {



double tp;
double sl;

if (TakeProfit==0){
   tp=0;
} else {
   tp=Bid-TakeProfit*Point;
}

if (StopLoss==0){
   sl=0;
} else {
   sl=Bid+StopLoss*Point;
}


int ticket;
for(int i=0;i<3;i++)
{
   string errorMsg;
   ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,sl,tp,"HiLLzX Triple MA Sell",MagicNumber,0,CLR_NONE);

   if(ticket>0){break;}
   RefreshRates();
}

}

void CloseThis() {
   bool closed = false;
   for (int i = OrdersTotal(); i >=0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      while(IsTradeContextBusy()) Sleep(100);
      RefreshRates();
      if ( OrderType() == OP_BUY && Symbol() == OrderSymbol() 
      && MagicNumber == OrderMagicNumber() ) {
        closed = OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, White);
      }
      if (OrderType() == OP_SELL && Symbol() == OrderSymbol()
       && MagicNumber == OrderMagicNumber() ) {
        closed = OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, White);
      }
   }
   
return;

}

Let us try, do not forget to share and follow our facebook and our youtube channel, happy trading!





- Provided by HiLLzSoft Studio -