alguem pode me ajudar em como inserir dentro do robo ordens stop loss- stop gain e stop movel

 

senhores alguem pode me ajudar? tenho um robo porem queria uma ideia de colocolar nele um stop loss e stop movel e um alvo em tick em que local dentro do robo posso adicionar posso alguem pode me ajudar segue o scritp abaixo:




#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

//---

#include <Trade\PositionInfo.mqh>

#include <Trade\Trade.mqh>

#include <Trade\SymbolInfo.mqh>  

#include <Trade\AccountInfo.mqh>

#include <Trade\DealInfo.mqh>

#include <Trade\OrderInfo.mqh>

#include <Expert\Money\MoneyFixedMargin.mqh>

CPositionInfo  m_position;                   // trade position objeto

CTrade         m_trade;                      // objeto de negociação

CSymbolInfo    m_symbol;                     // objeto de informação de símbolo

CAccountInfo   m_account;                    // infolucro de informações da conta

CDealInfo      m_deal;                       // lida com o objeto

COrderInfo     m_order;                      // pedidos pendentes objeto

CMoneyFixedMargin *m_money;

// --- entrada de parâmetros de 

input double   InpLots           = 1.0;      // Lotes de

input uchar    InpStartHour      = 9;        // Iniciar a

input uchar    InpEndHour        = 18;       // Fim da hora de

input ulong    m_magic           = 481361391;// Numero mágico

//---

ulong          m_slippage=20;                // slippage

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

//| Função de inicialização de especialistas                         |

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

int OnInit()

  {

   if(!m_symbol.Name(Symbol())) // define o

      return(INIT_FAILED);

   RefreshRates();


   string err_text="";

   if(!CheckVolumeValue(InpLots,err_text))

     {

      Print(__FUNCTION__,", ERROR: ",err_text);

      return(INIT_PARAMETERS_INCORRECT);

     }

//---

   m_trade.SetExpertMagicNumber(m_magic);

   m_trade.SetMarginMode();

   m_trade.SetTypeFillingBySymbol(m_symbol.Name());

   m_trade.SetDeviationInPoints(m_slippage);

//---

   return(INIT_SUCCEEDED);

  }

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

//| Função de desinicialização de especialistas                      |

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

void OnDeinit(const int reason)

  {

//---


  }

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

//| Função de tick especialista                                      |

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

void OnTick()

  {

// --- trabalhamos apenas no momento do nascimento da nova barra datetime

   static datetime PrevBars=0;

   datetime time_0=Time(0);

   if(time_0==PrevBars)

      return;

   PrevBars=time_0;


   MqlDateTime STimeCurrent;

   TimeToStruct(PrevBars,STimeCurrent);

   if(STimeCurrent.hour<InpStartHour || STimeCurrent.hour>InpEndHour)

      return;


   if(!RefreshRates())

     {

      PrevBars=0;

      return;

     }


   long array_volume[];

   ArraySetAsSeries(array_volume,true);

   if(CopyTickVolume(m_symbol.Name(),Period(),0,3,array_volume)!=3)

     {

      PrevBars=0;

      return;

     }

//---

   if(array_volume[1]>array_volume[2])

     {

      ClosePositions(POSITION_TYPE_SELL);

      OpenBuy();

     }


   if(array_volume[1]<array_volume[2])

     {

      ClosePositions(POSITION_TYPE_BUY);

      OpenSell();

     }

//---


  }

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

//| Função TradeTransaction                                          |

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

void OnTradeTransaction(const MqlTradeTransaction &trans,

                        const MqlTradeRequest &request,

                        const MqlTradeResult &result)

  {

//---


  }

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

//| Atualiza os dados de citações de símbolos                        |

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

bool RefreshRates(void)

  {

// --- taxas de atualização

   if(!m_symbol.RefreshRates())

     {

      Print("RefreshRates error");

      return(false);

     }

// --- proteção contra o valor de retorno de "zero"

   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)

      return(false);

//---

   return(true);

  }

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

//| Verifique a exatidão do volume da posição                     |

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

bool CheckVolumeValue(double volume,string &error_description)

  {

// --- volume mínimo permitido para operações de negociação 

// double min_volume = m_symbol.LotsMin ( );

   double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);

   if(volume<min_volume)

     {

      if(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")

         error_description=StringFormat("Объем меньше минимально допустимого SYMBOL_VOLUME_MIN=%.2f",min_volume);

      else

         error_description=StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume);

      return(false);

     }

// --- volume máximo permitido de operações de negociação 

// double max_volume = m_symbol.LotsMax ();

   double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);

   if(volume>max_volume)

     {

      if(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")

         error_description=StringFormat("Объем больше максимально допустимого SYMBOL_VOLUME_MAX=%.2f",max_volume);

      else

         error_description=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume);

      return(false);

     }

// --- obter passo mínimo de alteração de volume 

// double volume_step = m_symbol.LotsStep ();


   double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);


   int ratio=(int)MathRound(volume/volume_step);

   if(MathAbs(ratio*volume_step-volume)>0.0001)

     {

      if(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")

         error_description=StringFormat("Volume não é um múltiplo da etapa mínima SYMBOL_VOLUME_STEP =%. 2f, o volume correto mais próximo é% .2f",

                                        volume_step,ratio*volume_step);

      else

         error_description=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f",

                                        volume_step,ratio*volume_step);

      return(false);

     }

   error_description="Corrigir valor do volume";

   return(true);

  }

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

//| Obter tempo para o índice de barras especificado                 | 

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

datetime Time(const int index,string symbol=NULL,ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT)

  {

   if(symbol==NULL)

      symbol=m_symbol.Name();

   if(timeframe==0)

      timeframe=Period();

   datetime Time[1];

   datetime time=0; // datetime "0" -> D'1970.01.01 00:00:00'

   int copied=CopyTime(symbol,timeframe,index,1,Time);

   if(copied>0)

      time=Time[0];

   return(time);

  }

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

//| Posição de compra aberta                                         |

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

void OpenBuy()

  {

// --- verifique o volume antes de OrderSend para evitar o erro "not enough money" (CTrade)

   double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),InpLots,m_symbol.Ask(),ORDER_TYPE_BUY);


   if(check_volume_lot!=0.0)

     {

      if(check_volume_lot>=InpLots)

        {

         if(m_trade.Buy(InpLots,m_symbol.Name(),m_symbol.Ask()))

           {

            if(m_trade.ResultDeal()==0)

              {

               Print(__FUNCTION__,", #1 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription());

               PrintResult(m_trade,m_symbol);

              }

            else

              {

               Print(__FUNCTION__,", #2 Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription());

               PrintResult(m_trade,m_symbol);

              }

           }

         else

           {

            Print(__FUNCTION__,", #3 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),

                  ", description of result: ",m_trade.ResultRetcodeDescription());

            PrintResult(m_trade,m_symbol);

           }

        }

      else

        {

         Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(check_volume_lot,2),") ",

               "< Lots (",DoubleToString(InpLots,2),")");

         return;

        }

     }

   else

     {

      Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\"");

      return;

     }

//---

  }

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

//| Posição de venda aberta                                          |

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

void OpenSell()

  {

//--- check volume before OrderSend to avoid "not enough money" error (CTrade)

   double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),InpLots,m_symbol.Bid(),ORDER_TYPE_SELL);


   if(check_volume_lot!=0.0)

     {

      if(check_volume_lot>=InpLots)

        {

         if(m_trade.Sell(InpLots,m_symbol.Name(),m_symbol.Bid()))

           {

            if(m_trade.ResultDeal()==0)

              {

               Print(__FUNCTION__,", #1 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription());

               PrintResult(m_trade,m_symbol);

              }

            else

              {

               Print(__FUNCTION__,", #2 Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),

                     ", description of result: ",m_trade.ResultRetcodeDescription());

               PrintResult(m_trade,m_symbol);

              }

           }

         else

           {

            Print(__FUNCTION__,", #3 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),

                  ", description of result: ",m_trade.ResultRetcodeDescription());

            PrintResult(m_trade,m_symbol);

           }

        }

      else

        {

         Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(check_volume_lot,2),") ",

               "< Lots (",DoubleToString(InpLots,2),")");

         return;

        }

     }

   else

     {

      Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\"");

      return;

     }

//---

  }

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

//| Resultado do CTrade                                              |

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

void PrintResult(CTrade &trade,CSymbolInfo &symbol)

  {

   Print("Code of request result: "+IntegerToString(trade.ResultRetcode()));

   Print("code of request result: "+trade.ResultRetcodeDescription());

   Print("deal ticket: "+IntegerToString(trade.ResultDeal()));

   Print("order ticket: "+IntegerToString(trade.ResultOrder()));

   Print("volume of deal or order: "+DoubleToString(trade.ResultVolume(),2));

   Print("price, confirmed by broker: "+DoubleToString(trade.ResultPrice(),symbol.Digits()));

   Print("current bid price: "+DoubleToString(trade.ResultBid(),symbol.Digits()));

   Print("current ask price: "+DoubleToString(trade.ResultAsk(),symbol.Digits()));

   Print("broker comment: "+trade.ResultComment());

   int d=0;

  }

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

//| Fechar posições                                                  |

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

void ClosePositions(const ENUM_POSITION_TYPE pos_type)

  {

    for(int i=PositionsTotal()-1;i>=0;i--) // retorna o número de posições atuais

      if(m_position.SelectByIndex(i))     // seleciona a posição por índice para acesso adicional às suas propriedades

         if(m_position.Symbol()==Symbol() && m_position.Magic()==m_magic)

            if(m_position.PositionType()==pos_type) // obtém o tipo de posição

               m_trade.PositionClose(m_position.Ticket()); // fecha uma posição pelo símbolo especificado

  }

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


 
segue o arquivo do  robo baixado aqui do MQL5
Arquivos anexados:
Razão: