CONVERSION FUNCTIONS on mt4

 

hi

i'm new on mql4 and stuck with error 130 becuase of 'invalid stops.' i place my stops as multiples of the stoploss value in order to enhance my risk to reward ratio. when i use fixed pip values for my stops i don't receive such error but becuase volatility can change anytime in the market i do not want to use fixed stops like 50pips for takeprofit and 15pips for SL. kindly help me convert the follow code into price in order to stop this erro 130.

in the code my Takeprofit for a buy trade is 5x Stoploss. in the code my stoploss is predetermined below or above the cuurent fractal before the position was opened.  when im testing it, some of the orders go through but majority of them return error 130.  i know this topic is supposed to be on Mql4 forum but whenever i open the link it directs me here.

double TPSell;// Take Profit for my selltrade
double TPBuy;// Take Profit for my selltrade
   double point;
    
   TPBuy=((OrderOpenPrice()-OrderStopLoss())*5) ;
   TPSell=((OrderStopLoss()-OrderOpenPrice())*5) ;


////if we have a buy signal and no position
   if((Hour()>9&&Hour()<18)  &&OrdersTotal()<=0)
      //send a buy order
     {
      OrderSend(_Symbol,OP_BUY,0.1,Ask,5,FractalDown[0]-1*_Point,Ask+TPBuy*_Point,NULL,MagicNumber,0,clrGreen);
     }


//if sell signal
   if((Hour()>9&&Hour()<18)&&OrdersTotal()<=0)
      //open a sell order
     {
      OrderSend(_Symbol,OP_SELL,0.1,Bid,5,FractalUp[0]+1*_Point, Bid-TPSell*_Point,NULL,MagicNumber,0,clrRed);
     }
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1.    TPBuy=((OrderOpenPrice()-OrderStopLoss())*5) ;
       TPSell=((OrderStopLoss()-OrderOpenPrice())*5) ;

    MT4: You can not use any Trade Functions until you first select an order.

  2. OrderSend(_Symbol,OP_BUY,0.1,Ask,5,FractalDown[0]-1*_Point,Ask+TPBuy*_Point,NULL,MagicNumber,0,clrGreen);

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  3. TP/SL are prices. Your TPBuy is a change of price. (0.01234) Your Ask+ TPBuy * _Point is garbage. (Ask + 0.1234 × 0.00001 == Ask)
 
William Roeder #:
  1. MT4: You can not use any Trade Functions until you first select an order.

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  3. TP/SL are prices. Your TPBuy is a change of price. (0.01234) Your Ask+ TPBuy * _Point is garbage. (Ask + 0.1234 × 0.00001 == Ask)
Wow thanks. i'll do the correction and see what happens
Reason: