Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// Define symbol and lot sizes

string symbol = "XAUUSD";


double lotSize1 = 0.01;
double lotSize2 = 0.02;

// Define entry and exit prices


double entryPrice1 = 1900.00;
double takeProfit1 = 1920.00;
double entryPrice2 = 1880.00;
double takeProfit2 = 1900.00;

// Define trade management variables


bool trade1Open = false;
bool trade2Open = false;

// Define function to open trades


void openTrade(double lotSize, double entryPrice, double takeProfit) {
int ticket = OrderSend(symbol, OP_BUY, lotSize, entryPrice, 3, 0, 0, "", 0, 0,
Green);
if (ticket > 0) {
bool tpSet = OrderModify(ticket, 0, takeProfit, 0, 0, Green);
if (tpSet) {
Print("Trade opened successfully with ticket #", ticket);
} else {
Print("Failed to set take profit for trade #", ticket);
}
} else {
Print("Failed to open trade.");
}
}

// Define OnTick() function


void OnTick() {
double currentPrice = MarketInfo(symbol, MODE_BID);

// Open trade 1
if (!trade1Open && currentPrice >= entryPrice1) {
openTrade(lotSize1, entryPrice1, takeProfit1);
trade1Open = true;
}

// Open trade 2
if (trade1Open && !trade2Open && currentPrice <= entryPrice2) {
openTrade(lotSize2, entryPrice2, takeProfit2);
trade2Open = true;
}
}

You might also like