Download MetaTrader 5
To add comments, please log in or register
The Market has more than 400 indicators. Try any of them!
filipefr
58
filipefr 2015.10.12 15:37 

I'm trying to build a TrailingStop EA, but I'm getting error 130 on OrderModify. What is wrong?

 void TrailingPositions() {

  double pBid, pAsk, pp;


  Print( "OrderStopLoss", OrderStopLoss() );

  RefreshRates();


  pp = MarketInfo(OrderSymbol(), MODE_POINT);

  StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);

  if (OrderType()==OP_BUY) {

    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);

    pBid = MarketInfo(OrderSymbol(), MODE_BID);

    //Print("new SL BUY ask",pAsk-(TrailingStop+TrailingStep-1)*pp);

    Print("new SL BUY bid",pBid-(TrailingStop+TrailingStep-1)*pp);

    Print( "new SL stoplevel", pBid - (StopLevel)*pp );


    if (TrailingStop < StopLevel) {

      TrailingStop = StopLevel;

    }



    if ((pBid-OrderOpenPrice())>TrailingStop*pp) {

      if (OrderStopLoss()<pBid-(TrailingStop)*pp || OrderStopLoss()==0) {

        ModifyStopLoss(pBid-TrailingStop*pp);

        return;

      }

    }

  }

  if (OrderType()==OP_SELL) {

    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);

    pBid = MarketInfo(OrderSymbol(), MODE_BID);

    Print("new SL SELL Ask",pAsk+TrailingStop*pp);

    Print( "new SL stoplevel", pBid + (StopLevel)*pp );

    if (TrailingStop < StopLevel) {

      TrailingStop = StopLevel;

    }

    if (OrderOpenPrice()-pAsk>TrailingStop*pp) {

      if (OrderStopLoss()>pAsk+(TrailingStop)*pp || OrderStopLoss()==0) {

        ModifyStopLoss(pAsk+TrailingStop*pp);

        return;

      }

    }

  }

}



void ModifyStopLoss(double ldStopLoss) {

  bool fm;

  double pp;

  pp = MarketInfo(OrderSymbol(), MODE_POINT);


  fm=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ldStopLoss,Digits),OrderTakeProfit(),0,CLR_NONE);

  if (fm) 

  {Print( "modified success" );}

  else{Print( "error modified",GetLastError());}

}

/
To add comments, please log in or register