Why are these stop loss not stopping the loss and why take profits are not taking profit. They even calculate the stop loss and take profit properly but do not take any action.

 
// Input variables
input double TradeVolume=0.1;
input int StopLoss=1000;
input int TakeProfit=1000;
input int MAPeriod=10;


// Global variables 
bool glBuyPlaced, glSellPlaced;


// OnTick() event handler
void OnTick()
{
// Trade structures
MqlTradeRequest request;
MqlTradeResult result;
ZeroMemory(request);

// Moving average
double ma[];
ArraySetAsSeries(ma,true);
int maHandle=iMA(_Symbol,0,MAPeriod,MODE_SMA,0,PRICE_CLOSE);
   CopyBuffer(maHandle,0,0,1,ma);
   
   
   // Close price
   double close[];
   ArraySetAsSeries(close,true);
   CopyClose(_Symbol,0,0,1,close);
   
   
   // Current position information
   bool openPosition = PositionSelect(_Symbol);
   long positionType = PositionGetInteger(POSITION_TYPE);
   
   double currentVolume = 0;
   if(openPosition == true) currentVolume = PositionGetDouble(POSITION_VOLUME);
   
   
   // Open buy market order
   if(close[0] > ma[0] && glBuyPlaced == false && (positionType != POSITION_TYPE_BUY || openPosition == false))
   {
    request.action = TRADE_ACTION_DEAL;
request.type = ORDER_TYPE_BUY;
request.symbol = _Symbol;
request.volume = TradeVolume + currentVolume;
request.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
request.sl = 0;
request.tp = 0;
request.deviation = 50;
bool sent = OrderSend(request,result);
// Modify SL/TP
if(result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE)
{
request.action = TRADE_ACTION_SLTP;
PositionSelect(_Symbol);
double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
if(StopLoss > 0) request.sl = positionOpenPrice - (StopLoss * _Point);
if(TakeProfit > 0) request.tp = positionOpenPrice + (TakeProfit * _Point);
if(request.sl > 0 && request.tp > 0) sent = OrderSend(request,result);
glBuyPlaced = true;
glSellPlaced = false;
} 
   }
   
   
   // Open sell market order
   else if(close[0] < ma[0] && glSellPlaced == false && positionType != POSITION_TYPE_SELL)
   {
    request.action = TRADE_ACTION_DEAL;
request.type = ORDER_TYPE_SELL;
request.symbol = _Symbol;
request.volume = TradeVolume + currentVolume;
request.price = SymbolInfoDouble(_Symbol,SYMBOL_BID);
request.sl = 0;
request.tp = 0;
request.deviation = 50;
bool sent = OrderSend(request,result);
// Modify SL/TP
if((result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE) && (StopLoss > 0 || TakeProfit > 0))
{
request.action = TRADE_ACTION_SLTP;
PositionSelect(_Symbol);
double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
if(StopLoss > 0) request.sl = positionOpenPrice + (StopLoss * _Point);
if(TakeProfit > 0) request.tp = positionOpenPrice - (TakeProfit * _Point);
if(request.sl > 0 && request.tp > 0) sent = OrderSend(request,result);
glBuyPlaced = false;
glSellPlaced = true;
} 
   } 
}

 
int maHandle=iMA(_Symbol,0,MAPeriod,MODE_SMA,0,PRICE_CLOSE);
   CopyBuffer(maHandle,0,0,1,ma);

Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010

 
William Roeder:

Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010


your answer is not very clear. What exactly is the solution for the problem it would be much better if you could show a properly working code.

 

MY answer was extremely clear. What part of "you get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, " is not unclear?

Had you bothered to look at the examples in the documentation, as instructed, you would have found "properly working code".

If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

or pay (Freelance) someone to code it. Top of every page is the link Code Base.

          Hiring to write script - General - MQL5 programming forum 2019.08.21

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help 2017.04.21