mql5, method Ctrade::PositionModify() not work :(

To add comments, please log in or register
abricot911
6
abricot911  

hello, I don't understand why my stop loss is not modify during trade

//+------------------------------------------------------------------+
//|                        TRENDTRACKERxm19                          |
//|                                                                  |                         |
//+------------------------------------------------------------------+
#include<Trade\Trade.mqh>
CTrade trade;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
      double ma20Array[];
      double ma200Array[];
      
      int ma20 = iMA(_Symbol,_Period,20,0,MODE_SMA,PRICE_CLOSE);
      int ma200= iMA(_Symbol,_Period,200,0,MODE_SMA,PRICE_CLOSE);
      
      ArraySetAsSeries(ma20Array,true);
      ArraySetAsSeries(ma200Array,true);
     
      
      CopyBuffer(ma20,0,0,3,ma20Array);
      CopyBuffer(ma200,0,0,3,ma200Array);
    
      
      double ma20Value=ma20Array[0];
      double ma200Value=ma200Array[0];
      
      if(ma20Value>ma200Value){
          if(PositionsTotal()==0&&OrdersTotal()==0){Buy();}
       }
       
       checkTrailingStop();   
    }
//+------------------------------------------------------------------+
  void Buy(){
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   trade.Buy(1,_Symbol,Ask,Ask-100*_Point,Ask+1000*_Point);
  }
  
  
  void Sell(){
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   trade.Sell(0.1,_Symbol,Bid,Bid+100*_Point,Bid-10000*_Point);
  }
  
  void checkTrailingStop(){
      double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      int total = PositionsTotal();
      
      for(int i =total-1;i>=0;i--){
         string symbol = PositionGetSymbol(i);
         double ticket = PositionGetInteger(POSITION_TICKET);
         double entry = PositionGetDouble(POSITION_PRICE_OPEN);
         double currentStop = PositionGetDouble(POSITION_SL);
         double delta = (Ask-currentStop)*10000;
        // printf(ticket);
         trade.PositionModify(ticket,(currentStop+100*_Point),0);
         
      }
      
  }
  
Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
To add comments, please log in or register