Scripts: Open Trade

Open Trade:

This function performs the main logic of opening a trade. It calculates the opening price, take profit levels and stop loss based on the symbol information and parameters provided by the user. Prepare a trade request (MqlTradeRequest) with the necessary information such as symbol, volume, order type, slippage, comment, magic number, etc. Call the OrderSend function to send the trade request and get the result. SetTypeFillingBySymbol function: determines the order fulfilment type (Fill or Cancel, Immediate or Cancel or Return) according to the symbol's fulfilment policy. GetMinTradeLevel function: calculates the minimum trade level based on the freeze level and stop level of the symbol. Adjusts the minimum level to ensure that it is within certain limits and returns the result.

Author: Manuel Gonzales

How can I add it to MT5?
Luis Gonzalo Mira Pintos #:
How can I add it to MT5?

Hi Luis, it’s a script that can be used as a function in Expert Advisors.
Once installed, drag the icon from the Scripts window to the symbol window where you want to run it.
Best regards.

Luis Gonzalo Mira Pintos #:
How can I add it to MT5?
const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(bodyParser.json());

/*
Expected JSON from MT5:
{
"symbol": "EURUSD",
"candles": [
{ "high": 1.0921, "low": 1.0882, "close": 1.0910 },
...
],
"period": 20
}
*/

app.post("/breakout", (req, res) => {
const { candles, period } = req.body;

if (!candles || candles.length < period + 1) {
return res.json({ signal: "NONE" });
}

const lookback = candles.slice(1, period + 1);

const highestHigh = Math.max(...lookback.map(c => c.high));
const lowestLow = Math.min(...lookback.map(c => c.low));

const currentClose = candles[0].close;

let signal = "NONE";

if (currentClose > highestHigh) signal = "BUY";
if (currentClose < lowestLow) signal = "SELL";

res.json({
signal,
highestHigh,
lowestLow
});
});

app.listen(3000, () => {
console.log("Breakout bot API running on port 3000");
});