Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
sean gilbank
54
sean gilbank 2014.04.15 04:50 

Can someone help me?

If a user inputs $10

extern double takeProfit=10.00;

extern double lotSize=0.01;

how can you convert this so you can add set the take profit to $10.00 above the ask.

Thank you

Keith Watford
Moderator
7887
Keith Watford 2014.04.15 05:48  

Her's a script that I did some time ago that modifies open orders according to SL and TP in account currency.

It may not be exactly what you want, but can probably be modified.

//+------------------------------------------------------------------+
//|                                                        order.mq4 |
//|                                                           GumRai |
//|                                                             none |
//+------------------------------------------------------------------+
#property copyright "GumRai"
#property link      "none"
#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input double SL_in_Currency=10;
input double TP_in_Currency=10;
input bool   Chart_Trades_Only=false;

#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---

   for(int x=OrdersTotal()-1;x>=0;x--)
     {
      if(!OrderSelect(x,SELECT_BY_POS,MODE_TRADES))
        {
         Print("Error with OrderSelect-",ErrorDescription(GetLastError()));
         continue;
        }
      if(!(OrderType()==OP_BUY || OrderType()==OP_SELL))
         continue;
      if(Chart_Trades_Only && OrderSymbol()!=Symbol())
         continue;

      double tick_size=SymbolInfoDouble(OrderSymbol(),SYMBOL_TRADE_TICK_SIZE);
      double pnt=SymbolInfoDouble(OrderSymbol(),SYMBOL_POINT);
      double minfromcurrentprice=SymbolInfoInteger(OrderSymbol(),SYMBOL_TRADE_STOPS_LEVEL)*pnt;
      double loss_for_1_lot=SymbolInfoDouble(OrderSymbol(),SYMBOL_TRADE_TICK_VALUE);  //Loss/Gain for a 1 tick move with 1 lot
      double loss_for_lot_size_this_trade=loss_for_1_lot*OrderLots();    //Loss/Gain for a 1 tick move with trade lot size
      double SL_ticks=SL_in_Currency/loss_for_lot_size_this_trade;
      double SL_points=MathFloor(SL_ticks*tick_size/pnt)*pnt;
      double TP_ticks=TP_in_Currency/loss_for_lot_size_this_trade;
      double TP_points=MathFloor(TP_ticks*tick_size/pnt)*pnt;

      if(OrderType()==OP_SELL)
        {
         SL_points= (-SL_points);
         TP_points= (-TP_points);
        }

      double new_sl=OrderOpenPrice()-SL_points;
      if(MathAbs(new_sl-OrderClosePrice()) -minfromcurrentprice<pnt)
        {
         Alert(OrderSymbol()," Order ",OrderTicket()," SL too close to current price");
         new_sl=OrderStopLoss();
        }
      double new_tp=OrderOpenPrice()+TP_points;
      if(MathAbs(new_tp-OrderClosePrice()) -minfromcurrentprice<pnt)
        {
         Alert(OrderSymbol()," Order ",OrderTicket()," TP too close to current price");
         new_tp=OrderTakeProfit();
        }
      if(MathAbs(new_sl-OrderStopLoss())>=pnt || MathAbs(new_tp-OrderTakeProfit())>=pnt)
         OrderModify(OrderTicket(),OrderOpenPrice(),new_sl,new_tp,0,0);

     }
  }
//+------------------------------------------------------------------+
sean gilbank
54
sean gilbank 2014.04.15 06:01  
Right on thank you. I will have a loo k in the morning and test it out.
sean gilbank
54
sean gilbank 2014.04.15 06:07  
I just tested it out and that is exactly what I was trying to do thank you so much I will have to go through your code so that I understand it better.
/
To add comments, please log in or register