New to mql4, need some help please

 

I am new to mql4. I work 12 hours a day so i haven't had time to test this and i wrote it cos i don't have time to monitor my trades. It is meant to open 4 trades on a 4 digit broker. I know it opens the trades and the tp and stoplosses work but i don't know if the modify order will work properly. It is meant to adjust the stoploss to the open price plus 1 pip. Plus Order 4 is meant to Move the stoploss 150 everytime the price is 300 above the last stoploss. Any help would be greatly appreciated.

Thanks.


//+------------------------------------------------------------------+

//| TradeManager.mq4 |
//| James Thomas |
//| |
//+------------------------------------------------------------------+
#property copyright "James Thomas"
#property link ""


extern bool BuyTrade = false;
extern bool SellTrade = false;
extern bool Trade1 = false;
extern bool Trade2 = false;
extern bool Trade3 = false;
extern bool Trade4 = false;
extern double NumberOfLots = 0.1;
extern double OStopLoss = 0.0;
extern int Target1 = 20;
extern int Target2 = 40;
extern int Target3 = 200;
extern int Target4 = 150;

int Trade2No = 0;
int Trade3No = 0;
int Trade4No = 0;
bool OpenTrade = false;
bool BreakEven = false;
bool NTrade2 = false;
bool NTrade3 = false;
bool NTrade4 = false;
int Buy1Sell2 = 0;
double NTarget1;
double NTarget2;
double NTarget3;
double OpenPrice2 = 0.0;
double OpenPrice3 = 0.0;
double OpenPrice4 = 0.0;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//---- Open orders.
if (BuyTrade == true)
{
if (Trade1 == true)
{
NTarget1 = Ask + Target1 * Point;
OrderSend (Symbol(), OP_BUY, NumberOfLots, Ask, 5, OStopLoss, NTarget1);
Trade1 = false;
}
if (Trade2 == true)
{
NTarget2 = Ask + Target2 * Point;
OpenPrice2 = Ask;
Trade2No = OrderSend (Symbol(), OP_BUY, NumberOfLots, Ask, 5, OStopLoss, NTarget2);
Trade2 = false;
NTrade2 = true;
}
if (Trade3 == true)
{
NTarget3 = Ask + Target3 * Point;
OpenPrice3 = Ask;
Trade3No = OrderSend (Symbol(), OP_BUY, NumberOfLots, Ask, 5, OStopLoss, NTarget3);
Trade3 = false;
NTrade3 = true;
}
if (Trade4 == true)
{
OpenPrice4 = Ask;
Trade4No = OrderSend (Symbol(), OP_BUY, NumberOfLots, Ask, 5, OStopLoss, Bid + 10000 * Point);
Trade4 = false;
NTrade4 = true;
}
BuyTrade = false;
OpenTrade = true;
Buy1Sell2 = 1;
}
if (SellTrade == true)
{
if (Trade1 == true)
{
NTarget1 = Bid - Target1 * Point;
OrderSend (Symbol(), OP_SELL, NumberOfLots, Bid, 5, OStopLoss, NTarget1);
Trade1 = false;
}
if (Trade2 == true)
{
NTarget2 = Bid - Target2 * Point;
OpenPrice2 = Bid;
Trade2No = OrderSend (Symbol(), OP_SELL, NumberOfLots, Bid, 5, OStopLoss, NTarget2);
Trade2 = false;
NTrade2 = true;
}
if (Trade3 == true)
{
NTarget3 = Bid - Target3 * Point;
OpenPrice3 = Bid;
Trade3No = OrderSend (Symbol(), OP_SELL, NumberOfLots, Bid, 5, OStopLoss, NTarget3);
Trade3 = false;
NTrade3 = true;
}
if (Trade4 == true)
{
OpenPrice4 = Bid;
Trade4No = OrderSend (Symbol(), OP_SELL, NumberOfLots, Bid, 5, OStopLoss, Ask - 1000 * Point);
Trade4 = false;
NTrade4 = true;
}
SellTrade = false;
OpenTrade = true;
Buy1Sell2 = 2;
}
//---- Manage Orders
if (OpenTrade == true)
{
if (Buy1Sell2 == 1)
{
if (NTrade2 == true)
{
if (Bid > OpenPrice2 + NTarget1)
{
OrderModify (Trade2No, OpenPrice2, OpenPrice2 + 1 * Point, NTarget2, 0);
}
NTrade2 = false;
}
if (NTrade3 == true)
{
if (Bid > OpenPrice3 + NTarget1)
{
OrderModify (Trade3No, OpenPrice3, OpenPrice3 + 1 * Point, NTarget3, 0);
}
NTrade3 = false;
}
if (NTrade4 == true)
{
if (Bid > OpenPrice4 + NTarget1)
{
OStopLoss = OpenPrice4 + 1 * Point;
OrderModify (Trade4No, OpenPrice4, OStopLoss, Bid + 1000 * Point, 0);
BreakEven = true;
NTrade4 = false;
}
}
}
if (Buy1Sell2 == 2)
{
if (NTrade2 == true)
{
if (Ask < OpenPrice2 - NTarget1)
{
OrderModify (Trade2No, OpenPrice2, OpenPrice2 - 1 * Point, NTarget2, 0);
}
NTrade2 = false;
}
if (NTrade3 == true)
{
if (Ask < OpenPrice3 - NTarget1)
{
OrderModify (Trade3No, OpenPrice3, OpenPrice3 - 1 * Point, NTarget3, 0);
}
NTrade3 = false;
}
if (NTrade4 == true)
{
if (Ask < OpenPrice4 - NTarget1)
{
OStopLoss = OpenPrice4 - 1 * Point;
OrderModify (Trade4No, OpenPrice4, OStopLoss, Ask - 1000 * Point, 0);
BreakEven = true;
NTrade4 = false;
}
}
}
}
if (BreakEven == true)
{
if (Buy1Sell2 == 1)
{
if (Bid > OStopLoss + Target4 * Point * 2)
{
OStopLoss = Bid - Target4 * Point;
OrderModify (Trade4No, OpenPrice4, OStopLoss, Bid + 1000 * Point, 0);
}
if (Bid < OStopLoss)
{
BreakEven = false;
OpenTrade = false;
}
}
if (Buy1Sell2 == 2)
{
if (Ask < OStopLoss - Target4 * Point * 2)
{
OStopLoss = Ask + Target4 * Point;
OrderModify (Trade4No, OpenPrice4, OStopLoss, Ask - 1000 * Point, 0);
}
if (Ask > OStopLoss)
{
BreakEven = false;
OpenTrade = false;
}
}
}
return(0);
}
//+------------------------------------------------------------------+
 

Sorry this didn't place any trades for me when I tested it.

int start()
{
//---- Open orders.
if (BuyTrade == true)
{
if (Trade1 == true)
{
NTarget1 = Ask + Target1 * Point;
OrderSend (Symbol(), OP_BUY, NumberOfLots, Ask, 5, OStopLoss, NTarget1);
Trade1 = false;
}
if (Trade2 == true)
{

I'm not an expert programmer nor do I totally understand Object Oriented Programming. However, my understanding is that the computer reads the program from the top-down and left-right. I don't see any external functions to change BuyTrade from false to True, Yet its the first line in your code. I suggest you find time for your trading or put it off till you can make time. This is just my opinion I'm not a Financial Advisor. 

 
ubzen:

Sorry this didn't place any trades for me when I tested it.

I'm not an expert programmer nor do I totally understand Object Oriented Programming. However, my understanding is that the computer reads the program from the top-down and left-right. I don't see any external functions to change BuyTrade from false to True, Yet its the first line in your code. I suggest you find time for your trading or put it off till you can make time. This is just my opinion I'm not a Financial Advisor.


You have to change the external variable manually to true as well as which trades you want on and enter the stoploss.
 
  1. For large amounts, attach the file.


  2. It wont do anything unless BuyTrade is true. It wont open a trade unless trade1..trade4 is true and those reset back to false once a trade opens.