Hi Everyone,
I am new to the world of MQL 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
Here is the code:
Code: Select all >>>>>>>>>>>>>>>
#property strict
#property show_inputs
#include <stderror.mqh>
#include <stdlib.mqh>
extern double LotSize = 0.01;
extern double EntryPrice = 1.00000;
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);
}
//+------------------------------------------------------------------+
|