MT4 Script to place two orders

How would I modify this script to place two orders with the same stop loss but different profit targets?
For example a 10 pip stop loss with first target of 12 pips and second target at 30 pips? I played with it but it I don’t seem to be able to get it working?

#property show_inputs

#include <stderror.mqh>
#include <stdlib.mqh>

//parameternya ini, input-nya ini
extern double LOT = 0.10;
extern double TP = 12.0;
extern double SL = 10.0;

double Poin;
//±-----------------------------------------------------------------+
//| Custom initialization function |
//±-----------------------------------------------------------------+
int init(){

if (Point == 0.00001) Poin = 0.0001;
else {
if (Point == 0.001) Poin = 0.01;
else Poin = Point;
}
return(0);
}
//±-----------------------------------------------------------------+
// +
//±-----------------------------------------------------------------+
int start()
{
RefreshRates();
while( IsTradeContextBusy() ) { Sleep(100); }
//----
int ticket=OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SLPoin,Ask+TPPoin,“contest”,1,0,CLR_NONE);
OrderSend(Symbol(),OP_BUY,LOT,Ask,3,Ask-SLPoin,Ask+TPPoin,“contest”,2,0,CLR_NONE);
if(ticket<1)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
return;
}
//----
OrderPrint();
return(0);
}

You might be better off going here MQL4: automated forex trading, strategy tester and custom indicators with MetaTrader
Top right is the forum. Join up, not sure but you’ll probably get quicker answer there. Anyway that’s where I went when I needed an answer.

If you are using it on a live chart, make sure you enable “Live Trading” in the Common tab.

Fixed a few things for you and I know it works. I opened trades with it.

Here you go:


#property show_inputs

#include <stderror.mqh>
#include <stdlib.mqh>

//parameternya ini, input-nya ini
extern double LOT = 0.01;
extern int    TP  =   12;
extern int    TP2 =   30;
extern int    SL  =   10;
//---------------------------
string        MySym    =     "";
int       MyDigits     =      5;
double    MyPoints     = 0.0001;


//+------------------------------------------------------------------+
//| Custom initialization function |
//+------------------------------------------------------------------+
int init()
  {
       MySym = Symbol();   
   MyPoints  = MarketInfo( MySym, MODE_POINT  );
   MyDigits  = MarketInfo( MySym, MODE_DIGITS );
   //---
        if( MyPoints == 0.001   ) { MyPoints = 0.01;   MyDigits = 3; }
   else if( MyPoints == 0.00001 ) { MyPoints = 0.0001; MyDigits = 5; }
   
   return(0);
  }
//+------------------------------------------------------------------+
// +
//+------------------------------------------------------------------+
int start()
{
    RefreshRates();
    while( IsTradeContextBusy() ) { Sleep(100); }
//----
     double Stop  = NormalizeDouble(Ask - (SL  * MyPoints),MyDigits);
     double Prof1 = NormalizeDouble(Ask + (TP  * MyPoints),MyDigits);
     double Prof2 = NormalizeDouble(Ask + (TP2 * MyPoints),MyDigits);
      
     int ticket = OrderSend(MySym,OP_BUY,LOT,Ask,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof1,"contest",1,0,CLR_NONE);
                  OrderSend(MySym,OP_BUY,LOT,Ask,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof2,"contest",2,0,CLR_NONE);
         if(ticket<1)
            {
             int error=GetLastError();
             Print("Error = ",ErrorDescription(error));
             return;
            }
//----
   OrderPrint();
return(0);
}



Thanks Master Tang, could you also modify it for a sell, this one only buys.

Ok, I was able to figure it out and I have it working for a sell also. Take a look at it.

#property show_inputs

#include <stderror.mqh>
#include <stdlib.mqh>

//parameternya ini, input-nya ini
extern double LOT = 0.1;
extern int TP = 12;
extern int TP2 = 30;
extern int SL = 10;
//---------------------------
string MySym = “”;
int MyDigits = 5;
double MyPoints = 0.0001;

//±-----------------------------------------------------------------+
//| Custom initialization function |
//±-----------------------------------------------------------------+
int init()
{
MySym = Symbol();
MyPoints = MarketInfo( MySym, MODE_POINT );
MyDigits = MarketInfo( MySym, MODE_DIGITS );
//—
if( MyPoints == 0.001 ) { MyPoints = 0.01; MyDigits = 3; }
else if( MyPoints == 0.00001 ) { MyPoints = 0.0001; MyDigits = 5; }

return(0);
}
//±-----------------------------------------------------------------+
// +
//±-----------------------------------------------------------------+
int start()
{
RefreshRates();
while( IsTradeContextBusy() ) { Sleep(100); }
//----
double Stop = NormalizeDouble(Bid + (SL * MyPoints),MyDigits);
double Prof1 = NormalizeDouble(Bid - (TP * MyPoints),MyDigits);
double Prof2 = NormalizeDouble(Bid - (TP2 * MyPoints),MyDigits);

 int ticket = OrderSend(MySym,OP_SELL,LOT,Bid,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof1,"contest",1,0,CLR_NONE);
              OrderSend(MySym,OP_SELL,LOT,Bid,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof2,"contest",2,0,CLR_NONE);
     if(ticket&lt;1)
        {
         int error=GetLastError();
         Print("Error = ",ErrorDescription(error));
         return;
        }