Download MetaTrader 5

Straddle Pending Orders?

To add comments, please log in or register
Mr_H
74
Mr_H  
Hi Everyone,

I am new to the world of MQL4 coding but I managed to modify a free code to a one-sided pending order entry script as included in this message.
I appreciate if I would get this script converted into a straddle ( 2 opposing orders).

Keep It Simple,
Mr H
       
        #property strict
        #property show_inputs
        #include <stderror.mqh>
        #include <stdlib.mqh>
        extern double LotSize = 0.01;
        extern double EntryPrice = 50.00;
        extern double TakeProfit = 400;
        extern double StopLoss = 100;
        extern bool Buy = false;
        extern bool Sell = false;
        //+------------------------------------------------------------------+
        //| script program start function                                    |
        //+------------------------------------------------------------------+
        int start()
          {int ticket;
        //----
        if (Buy==false && Sell==false)
        {Alert("Invalid settings, choose to Buy or Sell by setting one of them to true");
        Alert("the script must now be relaunched");
        return (0);
        }
        if (Buy==true && Sell == true)  
        {
        Alert("Invalid settings! choose to Buy or Sell by setting one of them to false");
        Alert("the script must now be relaunched");
        return (0);
        }
        //----
        for (int i =0;i<5;i++)
        {
        if (Buy==true)
        {
        ticket= OrderSend(Symbol(),OP_BUYSTOP,LotSize,EntryPrice,7,NormalizeDouble(EntryPrice-StopLoss*10*Point,5),NormalizeDouble(EntryPrice+TakeProfit*10*Point,5));
        if (ticket>0)
        {
        Alert("Buy order successful");
        break;
        }
        else
        Alert("error opening Buy order, error code = ", ErrorDescription(GetLastError()));
        }
        else
        if (Sell==true)
        {
        ticket= OrderSend(Symbol(),OP_SELLSTOP,LotSize,EntryPrice,7,NormalizeDouble(EntryPrice+StopLoss*10*Point,5),NormalizeDouble(EntryPrice-TakeProfit*10*Point,5));
        if (ticket>0)
        {
        Alert("Sell order successful");
        break;
        }
        else
        Alert("error opening Sell order, error code = ", ErrorDescription(GetLastError()));
        }
        Sleep(3000);
        RefreshRates();
        }
           return(0);
          }
        //+------------------------------------------------------------------+
Alain Verleyen
Moderator
31192
Alain Verleyen  
To add comments, please log in or register