Problam in PositionGetString code

09198866726 mohammadi
64
09198866726 mohammadi  

This is a tradehedge . it have these 7 errors in two lines before end (yellow line).

'PositionGetString' - unexpected token    TradeHedge.mqh    439    35
',' - unexpected token    TradeHedge.mqh    439    60
'POSITION_MAGIC' - some operator expected    TradeHedge.mqh    439    61
')' - unexpected token    TradeHedge.mqh    439    76
')' - semicolon expected    TradeHedge.mqh    439    76
')' - unexpected token    TradeHedge.mqh    439    76
'else' - illegal 'else' without matching 'if'    TradeHedge.mqh    440    2
'}' - not all control paths return a value    TradeHedge.mqh    441    1

what can i do for resolve?

//+------------------------------------------------------------------+
//|                                                   TradeHedge.mqh |
//|                                                     Andrew Young |
//|                                 http://www.expertadvisorbook.com |
//+------------------------------------------------------------------+

#property copyright "Andrew Young"
#property link      "http://www.expertadvisorbook.com"

/*
 Creative Commons Attribution-NonCommercial 3.0 Unported
 http://creativecommons.org/licenses/by-nc/3.0/

 You may use this file in your own personal projects. You may 
 modify it if necessary. You may even share it, provided the 
 copyright above is present. No commercial use is permitted. 
*/


#define MAX_RETRIES 5           // Max retries on error
#define RETRY_DELAY 3000        // Retry delay in ms

#include <errordescription.mqh>
#include <Mql5Book\Trade.mqh>


//+----------------------------------------------------------------------+
//| CTradeHedge Class - Open, Close and Modify Orders for Hedging Accounts                                                           |
//+----------------------------------------------------------------------+

class CTradeHedge : public CTrade
{
        protected:      
                ulong OpenHedgePosition(string pSymbol, ENUM_ORDER_TYPE pType, double pVolume, double pStop = 0, double pProfit = 0, string pComment = NULL);
                
        public: 
                ulong BuyHedge(string pSymbol, double pVolume, double pStop = 0, double pProfit = 0, string pComment = NULL);
                ulong SellHedge(string pSymbol, double pVolume, double pStop = 0, double pProfit = 0, string pComment = NULL);
                
                bool ModifyHedge(ulong pTicket, double pStop, double pProfit = 0);
                bool CloseHedge(ulong pTicket, double pVolume = 0, string pComment = NULL);
                bool CloseByHedge(ulong pTicket, ulong pOppositeTicket, double pVolume = 0, string pComment = NULL);
};


// Open position
ulong CTradeHedge::OpenHedgePosition(string pSymbol, ENUM_ORDER_TYPE pType, double pVolume, double pStop = 0, double pProfit = 0, string pComment = NULL)
{
        request.action = TRADE_ACTION_DEAL;
        request.symbol = pSymbol;
        request.type = pType;
        request.sl = pStop;
        request.tp = pProfit;
        request.comment = pComment;
        request.volume = pVolume;
        request.position = 0;   // Reset ticket number
        
        // Order loop
        int retryCount = 0;
        int checkCode = 0;
        
        do 
        {
                if(pType == ORDER_TYPE_BUY) request.price = SymbolInfoDouble(pSymbol,SYMBOL_ASK);
                else if(pType == ORDER_TYPE_SELL) request.price = SymbolInfoDouble(pSymbol,SYMBOL_BID);
                                
      bool OpenOrder=OrderSend(request,result);         
      
                checkCode = CheckReturnCode(result.retcode);
                
                if(checkCode == CHECK_RETCODE_OK) break;
                else if(checkCode == CHECK_RETCODE_ERROR)
                {
                        string errDesc = TradeServerReturnCodeDescription(result.retcode);
                        Alert("Open market order: Error ",result.retcode," - ",errDesc);
                        break;
                }
                else
                {
                        Print("Server error detected, retrying...");
                        Sleep(RETRY_DELAY);
                        retryCount++;
                }
        }
        while(retryCount < MAX_RETRIES);
        
        if(retryCount >= MAX_RETRIES)
        {
                string errDesc = TradeServerReturnCodeDescription(result.retcode);
                Alert("Max retries exceeded: Error ",result.retcode," - ",errDesc);
        }
        
        string orderType = CheckOrderType(pType);
        
        string errDesc = TradeServerReturnCodeDescription(result.retcode);
        Print("Open ",orderType," order #",result.deal,": ",result.retcode," - ",errDesc,", Volume: ",result.volume,", Price: ",result.price,", Bid: ",result.bid,", Ask: ",result.ask);
        
        if(checkCode == CHECK_RETCODE_OK) 
        {
                Comment(orderType," position opened at ",result.price," on ",pSymbol);
                return(result.deal);
        }
        else return(0);
}

// Modify position
bool CTradeHedge::ModifyHedge(ulong pTicket, double pStop, double pProfit=0.000000)
{
        request.action = TRADE_ACTION_SLTP;
        request.sl = pStop;
        request.tp = pProfit;
        request.position = pTicket;
        
        // Order loop
        int retryCount = 0;
        int checkCode = 0;
        
        do 
        {
      bool OpenOrder=OrderSend(request,result);         
      
                checkCode = CheckReturnCode(result.retcode);
                
                if(checkCode == CHECK_RETCODE_OK) break;
                else if(checkCode == CHECK_RETCODE_ERROR)
                {
                        string errDesc = TradeServerReturnCodeDescription(result.retcode);
                        Alert("Modify position: Error ",result.retcode," - ",errDesc);
                        break;
                }
                else
                {
                        Print("Server error detected, retrying...");
                        Sleep(RETRY_DELAY);
                        retryCount++;
                }
        }
        while(retryCount < MAX_RETRIES);
        
        if(retryCount >= MAX_RETRIES)
        {
                string errDesc = TradeServerReturnCodeDescription(result.retcode);
                Alert("Max retries exceeded: Error ",result.retcode," - ",errDesc);
                return(false);
        }

        string errDesc = TradeServerReturnCodeDescription(result.retcode);
        PositionSelectByTicket(pTicket);
        string symbol = PositionGetString(POSITION_SYMBOL);
        Print("Modify position #",pTicket,": ",result.retcode," - ",errDesc,", SL: ",request.sl,", TP: ",request.tp,", Bid: ",SymbolInfoDouble(symbol,SYMBOL_BID),", Ask: ",SymbolInfoDouble(symbol,SYMBOL_ASK),", Stop Level: ",SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL));
        
        if(checkCode == CHECK_RETCODE_OK) 
        {
                Comment("Position #",pTicket," modified on ",symbol,", SL: ",request.sl,", TP: ",request.tp);
                return(true);
        }
        else return(false);
}


// Close position
bool CTradeHedge::CloseHedge(ulong pTicket, double pVolume=0.000000, string pComment=NULL)
{
        request.action = TRADE_ACTION_DEAL;
        request.position = pTicket;
                        
        double closeLots = 0;
        long openType = WRONG_VALUE;
        string symbol;
        
        if(PositionSelectByTicket(pTicket) == true)
        {
                closeLots = PositionGetDouble(POSITION_VOLUME);
                openType = PositionGetInteger(POSITION_TYPE);
                symbol = PositionGetString(POSITION_SYMBOL);
                request.sl = 0;   // Reset SL and TP when closing a position
                request.tp = 0; 
        }
        else return(false);
        
        if(pVolume > closeLots || pVolume <= 0) request.volume = closeLots; 
        else request.volume = pVolume;
        
        // Order loop
        int retryCount = 0;
        int checkCode = 0;
        
        do 
        {
                if(openType == POSITION_TYPE_BUY)
                {
                        request.type = ORDER_TYPE_SELL;
                        request.price = SymbolInfoDouble(symbol,SYMBOL_BID);
                }
                else if(openType == POSITION_TYPE_SELL)
                {
                        request.type = ORDER_TYPE_BUY;
                        request.price = SymbolInfoDouble(symbol,SYMBOL_ASK);
                }

      bool OpenOrder=OrderSend(request,result);         
      
                checkCode = CheckReturnCode(result.retcode);
                
                if(checkCode == CHECK_RETCODE_OK) break;
                else if(checkCode == CHECK_RETCODE_ERROR)
                {
                        string errDesc = TradeServerReturnCodeDescription(result.retcode);
                        Alert("Close position: Error ",result.retcode," - ",errDesc);
                        break;
                }
                else
                {
                        Print("Server error detected, retrying...");
                        Sleep(RETRY_DELAY);
                        retryCount++;
                }
        }
        while(retryCount < MAX_RETRIES);
        
        if(retryCount >= MAX_RETRIES)
        {
                string errDesc = TradeServerReturnCodeDescription(result.retcode);
                Alert("Max retries exceeded: Error ",result.retcode," - ",errDesc);
        }
        
        string posType;
        if(openType == POSITION_TYPE_BUY) posType = "Buy";
        else if(openType == POSITION_TYPE_SELL) posType = "Sell";
        
        string errDesc = TradeServerReturnCodeDescription(result.retcode);
        Print("Close ",posType," position #",result.deal,": ",result.retcode," - ",errDesc,", Volume: ",result.volume,", Price: ",result.price,", Bid: ",result.bid,", Ask: ",result.ask);
        
        if(checkCode == CHECK_RETCODE_OK) 
        {
                Comment(posType," position closed on ",symbol," at ",result.price);
                return(true);
        }
        else return(false);
}


// Close position by an opposite position
bool CTradeHedge::CloseByHedge(ulong pTicket, ulong pOppositeTicket, double pVolume=0.000000, string pComment=NULL)
{
        request.action = TRADE_ACTION_DEAL;
        request.position = pTicket;
        request.position_by = pOppositeTicket;
                        
        double closeLots = 0;
        long openType = WRONG_VALUE;
        string symbol;
        
        if(PositionSelectByTicket(pTicket) == true)
        {
                closeLots = PositionGetDouble(POSITION_VOLUME);
                openType = PositionGetInteger(POSITION_TYPE);
                symbol = PositionGetString(POSITION_SYMBOL);
                request.sl = 0;   // Reset SL and TP when closing a position
                request.tp = 0; 
        }
        else return(false);
        
        if(pVolume > closeLots || pVolume <= 0) request.volume = closeLots; 
        else request.volume = pVolume;
        
        // Order loop
        int retryCount = 0;
        int checkCode = 0;
        
        do 
        {
                if(openType == POSITION_TYPE_BUY)
                {
                        request.type = ORDER_TYPE_SELL;
                        request.price = SymbolInfoDouble(symbol,SYMBOL_BID);
                }
                else if(openType == POSITION_TYPE_SELL)
                {
                        request.type = ORDER_TYPE_BUY;
                        request.price = SymbolInfoDouble(symbol,SYMBOL_ASK);
                }

      bool OpenOrder=OrderSend(request,result);         
      
                checkCode = CheckReturnCode(result.retcode);
                
                if(checkCode == CHECK_RETCODE_OK) break;
                else if(checkCode == CHECK_RETCODE_ERROR)
                {
                        string errDesc = TradeServerReturnCodeDescription(result.retcode);
                        Alert("Close position: Error ",result.retcode," - ",errDesc);
                        break;
                }
                else
                {
                        Print("Server error detected, retrying...");
                        Sleep(RETRY_DELAY);
                        retryCount++;
                }
        }
        while(retryCount < MAX_RETRIES);
        
        if(retryCount >= MAX_RETRIES)
        {
                string errDesc = TradeServerReturnCodeDescription(result.retcode);
                Alert("Max retries exceeded: Error ",result.retcode," - ",errDesc);
        }
        
        string posType;
        if(openType == POSITION_TYPE_BUY) posType = "Buy";
        else if(openType == POSITION_TYPE_SELL) posType = "Sell";
        
        string errDesc = TradeServerReturnCodeDescription(result.retcode);
        Print("Close ",posType," position #",result.deal,": ",result.retcode," - ",errDesc,", Volume: ",result.volume,", Price: ",result.price,", Bid: ",result.bid,", Ask: ",result.ask);
        
        if(checkCode == CHECK_RETCODE_OK) 
        {
                Comment(posType," position closed on ",symbol," at ",result.price);
                return(true);
        }
        else return(false);
}


// Trade opening shortcuts
ulong CTradeHedge::BuyHedge(string pSymbol,double pVolume,double pStop=0.000000,double pProfit=0.000000,string pComment=NULL)
{
        ulong ticket = OpenHedgePosition(pSymbol,ORDER_TYPE_BUY,pVolume,pStop,pProfit,pComment);
        return(ticket);
}

ulong CTradeHedge::SellHedge(string pSymbol,double pVolume,double pStop=0.000000,double pProfit=0.000000,string pComment=NULL)
{
        ulong ticket = OpenHedgePosition(pSymbol,ORDER_TYPE_SELL,pVolume,pStop,pProfit,pComment);
        return(ticket);
}


//+------------------------------------------------------------------+
//| Position Information                                             |
//+------------------------------------------------------------------+


string PositionComment(ulong pTicket = 0)
{
        bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetString(POSITION_COMMENT));
        else return(NULL);
}


long PositionType(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetInteger(POSITION_TYPE));
        else return(WRONG_VALUE);
}


long PositionIdentifier(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetInteger(POSITION_IDENTIFIER));
        else return(WRONG_VALUE);
}


double PositionOpenPrice(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetDouble(POSITION_PRICE_OPEN));
        else return(WRONG_VALUE);
}


long PositionOpenTime(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetInteger(POSITION_TIME));
        else return(WRONG_VALUE);
}


double PositionVolume(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetDouble(POSITION_VOLUME));
        else return(WRONG_VALUE);
}


double PositionStopLoss(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetDouble(POSITION_SL));
        else return(WRONG_VALUE);
}


double PositionTakeProfit(ulong pTicket = 0)
{
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetDouble(POSITION_TP));
        else return(WRONG_VALUE);
}


double PositionProfit(ulong pTicket = 0)
{
        bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(PositionGetDouble(POSITION_PROFIT));
        else return(WRONG_VALUE);
}

string PositionMagicNumber(ulong pTicket = 0)
{ 
   bool select = false;
   if(pTicket > 0) select = PositionSelectByTicket(pTicket);
        
        if(select == true) return(string PositionGetString(_Symbol,POSITION_MAGIC)); //THIS LINE SEEMS FALSE//
        else return(NULL);
}
William Roeder
24691
William Roeder  
        if(select == true) return(string PositionGetString(_Symbol,POSITION_MAGIC));


Dominik Egert
1323
Dominik Egert  
Btw, it is PositionGetInteger();
09198866726 mohammadi
64
09198866726 mohammadi  
William Roeder:


hi, it have yet error:

'PositionGetString' - no one of the overloads can be applied to the function call TradeHedge.mqh 439 28

could be one of 2 function(s) TradeHedge.mqh 439 28

   built-in: string PositionGetString(ENUM_POSITION_PROPERTY_STRING) TradeHedge.mqh 439 28

   built-in: bool PositionGetString(ENUM_POSITION_PROPERTY_STRING,string&) TradeHedge.mqh 439 28

implicit conversion from 'number' to'string' TradeHedge.mqh 439 28

09198866726 mohammadi
64
09198866726 mohammadi  
Dominik Egert:
Btw, it is PositionGetInteger();

ok,thanks I tested and enjoied!

09198866726 mohammadi
64
09198866726 mohammadi  

hello, when I compile my EA , I receive following errors(check highlighted line):

'Init' - no one of the overloads can be applied to the function call Bands RSI jadid.mq5 121 12

could be one of 2 function(s) Bands RSI jadid.mq5 121 12

   int CiAlligator::Init(string,ENUM_TIMEFRAMES,int,int,int,int,int,int,ENUM_MA_METHOD,ENUM_APPLIED_PRICE) Indicators.mqh 435 7

   int CIndicator::Init() Indicators.mqh 36 15

any one can help me, please?


//+------------------------------------------------------------------+
//|                                           Bands/RSI CounterTrend |
//|                                                     Andrew Young |
//|                                 http://www.expertadvisorbook.com |
//+------------------------------------------------------------------+

#property copyright "Andrew Young"
#property link      "http://www.expertadvisorbook.com"
#property description "A counter-trend trading system using Bollinger Bands and RSI"

/*
 Creative Commons Attribution-NonCommercial 3.0 Unported
 http://creativecommons.org/licenses/by-nc/3.0/

 You may use this file in your own personal projects. You
 may modify it if necessary. You may even share it, provided
 the copyright above is present. No commercial use permitted. 
*/


// Trade
#include <Mql5Book\Trade.mqh>
CTrade Trade;

// Price
#include <Mql5Book\Price.mqh>
CBars Bar;

// Money management
#include <Mql5Book\MoneyManagement.mqh>

// Trailing stops
#include <Mql5Book\TrailingStops.mqh>
CTrailing Trail;

// Timer
#include <Mql5Book\Timer.mqh>
CTimer Timer;
CNewBar NewBar;

// Indicators 
#include <Mql5Book\Indicators.mqh>
CiAlligator Alligator;
CiCCI CCI;


//+------------------------------------------------------------------+
//| Input variables                                                  |
//+------------------------------------------------------------------+

input ulong Slippage = 3;
input bool TradeOnNewBar = true;

sinput string MM;       // Money Management
input bool UseMoneyManagement = true;
input double RiskPercent = 2;
input double FixedVolume = 0.1;

sinput string SL;       // Stop Loss & Take Profit
input int StopLoss = 0;
input int TakeProfit = 0;

sinput string TS;               // Trailing Stop
input bool UseTrailingStop = false;
input int TrailingStop = 0;
input int MinimumProfit = 0;
input int Step = 0; 

sinput string BE;               // Break Even
input bool UseBreakEven = false;
input int BreakEvenProfit = 0;
input int LockProfit = 0;

sinput string Alli;             // Bollinger Bands
input int JawPeriod = 13;
input int JawShift = 8;
input int TeethPeriod = 8;
input int TeethShift = 5;
input int LipsPeriod = 5;
input int LipsShift = 3;
input double AlligatorMethod = MODE_SMMA;
input ENUM_APPLIED_PRICE AlligatorPrice = PRICE_MEDIAN; 

sinput string CC;       // RSI
input int CCIPeriod = 14;
input ENUM_APPLIED_PRICE CCIPrice = PRICE_CLOSE;

sinput string TI;       // Timer
input bool UseTimer = false;
input int StartHour = 0;
input int StartMinute = 0;
input int EndHour = 0;
input int EndMinute = 0;
input bool UseLocalTime = false;



//+------------------------------------------------------------------+
//| Global variables                                                 |
//+------------------------------------------------------------------+

bool glBuyPlaced, glSellPlaced;

enum Signal
{
        SIGNAL_BUY,
        SIGNAL_SELL,
        SIGNAL_NONE,
};

Signal glSignal;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
{  
          
//problem line//Alligator.Init(_Symbol,_Period,JawPeriod,JawShift,TeethPeriod,TeethShift,LipsPeriod,LipsShift,AlligatorMethod,AlligatorPrice);
        CCI.Init(_Symbol,_Period,CCIPeriod,CCIPrice);
        
        Trade.Deviation(Slippage);
   return(0);
}



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
{

        // Check for new bar
        bool newBar = true;
        int barShift = 0;
        if(TradeOnNewBar == true) 
        {
                newBar = NewBar.CheckNewBar(_Symbol,_Period);
                barShift = 1;
        }
        
        
        // Timer
        bool timerOn = true;
        if(UseTimer == true)
        {
                timerOn = Timer.DailyTimer(StartHour,StartMinute,EndHour,EndMinute,UseLocalTime);
        }
        
        
        // Update prices
        Bar.Update(_Symbol,_Period);
        
        
        // Order placement 
        if(newBar == true && timerOn == true)
        {
                
                // Money management
                double tradeSize;
                if(UseMoneyManagement == true) tradeSize = MoneyManagement(_Symbol,FixedVolume,RiskPercent,StopLoss);
                else tradeSize = VerifyVolume(_Symbol,FixedVolume);
                
                
                if(Bar.Close(barShift) < Alligator.Jaw(barShift) && CCI.Main(barShift) < 30) glSignal = SIGNAL_BUY;
                else if(Bar.Close(barShift) > Alligator.Lips(barShift) && CCI.Main(barShift) > 70) glSignal = SIGNAL_SELL;
                
                
                // Open buy order
                if(glSignal == SIGNAL_BUY && Bar.Close(barShift) > Alligator.Jaw(barShift) && Bar.Close(barShift+1) <=  Alligator.Jaw(barShift+1)) 
                {
                        glBuyPlaced = Trade.Buy(_Symbol,tradeSize);
                
                        if(glBuyPlaced == true)  
                        {
                                do(Sleep(100)); while(PositionSelect(_Symbol) == false);
                                double openPrice = PositionOpenPrice(_Symbol);
                                
                                double buyStop = BuyStopLoss(_Symbol,StopLoss,openPrice);
                                if(buyStop > 0) AdjustBelowStopLevel(_Symbol,buyStop);
                                
                                double buyProfit = BuyTakeProfit(_Symbol,TakeProfit,openPrice);
                                if(buyProfit > 0) AdjustAboveStopLevel(_Symbol,buyProfit);
                                
                                if(buyStop > 0 || buyProfit > 0) Trade.ModifyPosition(_Symbol,buyStop,buyProfit);
                                
                                glSignal = SIGNAL_NONE;
                        } 
                }
                
                
                // Open sell order
                if(glSignal == SIGNAL_SELL && Bar.Close(barShift) <  Alligator.Lips(barShift) && Bar.Close(barShift+1) >=  Alligator.Lips(barShift+1)) 
                {
                        glSellPlaced = Trade.Sell(_Symbol,tradeSize);
                        
                        if(glSellPlaced == true)
                        {
                                do(Sleep(100)); while(PositionSelect(_Symbol) == false);
                                double openPrice = PositionOpenPrice(_Symbol);
                                
                                double sellStop = SellStopLoss(_Symbol,StopLoss,openPrice);
                                if(sellStop > 0) sellStop = AdjustAboveStopLevel(_Symbol,sellStop);
                                
                                double sellProfit = SellTakeProfit(_Symbol,TakeProfit,openPrice);
                                if(sellProfit > 0) sellProfit = AdjustBelowStopLevel(_Symbol,sellProfit);
                                
                                if(sellStop > 0 || sellProfit > 0) Trade.ModifyPosition(_Symbol,sellStop,sellProfit);
                                
                                glSignal = SIGNAL_NONE;
                        } 
                }
                
        }       // Order placement end
        
        
        // Break even
        if(UseBreakEven == true && PositionType(_Symbol) != -1)
        {
                Trail.BreakEven(_Symbol,BreakEvenProfit,LockProfit);
        }
        
        
        // Trailing stop
        if(UseTrailingStop == true && PositionType(_Symbol) != -1)
        {
                Trail.TrailingStop(_Symbol,TrailingStop,MinimumProfit,Step);
        }


}






Dominik Egert
1323
Dominik Egert  
Check your inputs.

input double AlligatorMethod = MODE_SMMA


09198866726 mohammadi
64
09198866726 mohammadi  
Dominik Egert:
Check your inputs.

input double AlligatorMethod = MODE_SMMA


thanks a lot sir ,you save my life again.

09198866726 mohammadi
64
09198866726 mohammadi  

My EA opens positions  but they haven't take profit and stop loss! 

the include file (trade) that implement take profit and stop loss don't work correctly meanwhile when in doesn't show any error. I attached  trade file bottom because of its size. does any one know how can I fix this problem.

Files:
Trade.mqh  25 kb