Edit Your Comment
Need a help for making an mt4 script
Jul 10, 2023 at 19:36
(edited Jul 10, 2023 at 19:36)
Member Since Nov 12, 2019
6 posts
Hi everyone...
I need an mt4 script that can put one buy stop order and one sell stop order by DISTANCE from the OPEN PRICE of a specified candle. No SL and TP needed.
For example:
In the script settings, I set the trading time start at 12:15, distance 10 pips, and lot size 1. When the time comes up (12:15) and it detects the open price of candle 12:15 is 1.12345, so the script immediately put a buy stop at 1.12445 and a sell stop at 1.12245. Can someone help to create or share it if you have one please?
Thank you 🙏
Best regards, Shakka.
I need an mt4 script that can put one buy stop order and one sell stop order by DISTANCE from the OPEN PRICE of a specified candle. No SL and TP needed.
For example:
In the script settings, I set the trading time start at 12:15, distance 10 pips, and lot size 1. When the time comes up (12:15) and it detects the open price of candle 12:15 is 1.12345, so the script immediately put a buy stop at 1.12445 and a sell stop at 1.12245. Can someone help to create or share it if you have one please?
Thank you 🙏
Best regards, Shakka.
Member Since Jul 04, 2023
1 posts
Jul 20, 2023 at 10:17
Member Since Jul 04, 2023
1 posts
Hy There i can see your post and i have some suggestion for you
//+------------------------------------------------------------------+
//| Buy_Sell_Stop.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int StartTimeHour = 12; // Trading start hour (0-23)
extern int StartTimeMinute = 15; // Trading start minute (0-59)
extern int DistancePips = 10; // Distance in pips from the open price
extern double LotSize = 1.0; // Lot size for the orders
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart()
{
datetime currentTime = TimeCurrent();
datetime tradingTime = TimeCurrent();
TimeHour(tradingTime) = StartTimeHour;
TimeMinute(tradingTime) = StartTimeMinute;
// Wait for the specified trading time
while (TimeCurrent() < tradingTime)
{
Sleep(1000);
}
// Get the open price of the specified candle (12:15)
double openPrice = iOpen(Symbol(), Period(), 0);
// Calculate the buy and sell stop prices
double buyStopPrice = openPrice + DistancePips * Point;
double sellStopPrice = openPrice - DistancePips * Point;
// Place the buy stop order
int ticketBuy = OrderSend(Symbol(), OP_BUYSTOP, LotSize, buyStopPrice, 0, 0, 0, "Buy Stop", 0, 0, Green);
if (ticketBuy < 0)
{
Print("Error placing buy stop order. Error code: ", GetLastError());
}
// Place the sell stop order
int ticketSell = OrderSend(Symbol(), OP_SELLSTOP, LotSize, sellStopPrice, 0, 0, 0, "Sell Stop", 0, 0, Red);
if (ticketSell < 0)
{
Print("Error placing sell https://www.tellhappystar.org/ stop order. Error code: ", GetLastError());
}
}
Thanks and regards
RichardRut
//+------------------------------------------------------------------+
//| Buy_Sell_Stop.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int StartTimeHour = 12; // Trading start hour (0-23)
extern int StartTimeMinute = 15; // Trading start minute (0-59)
extern int DistancePips = 10; // Distance in pips from the open price
extern double LotSize = 1.0; // Lot size for the orders
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart()
{
datetime currentTime = TimeCurrent();
datetime tradingTime = TimeCurrent();
TimeHour(tradingTime) = StartTimeHour;
TimeMinute(tradingTime) = StartTimeMinute;
// Wait for the specified trading time
while (TimeCurrent() < tradingTime)
{
Sleep(1000);
}
// Get the open price of the specified candle (12:15)
double openPrice = iOpen(Symbol(), Period(), 0);
// Calculate the buy and sell stop prices
double buyStopPrice = openPrice + DistancePips * Point;
double sellStopPrice = openPrice - DistancePips * Point;
// Place the buy stop order
int ticketBuy = OrderSend(Symbol(), OP_BUYSTOP, LotSize, buyStopPrice, 0, 0, 0, "Buy Stop", 0, 0, Green);
if (ticketBuy < 0)
{
Print("Error placing buy stop order. Error code: ", GetLastError());
}
// Place the sell stop order
int ticketSell = OrderSend(Symbol(), OP_SELLSTOP, LotSize, sellStopPrice, 0, 0, 0, "Sell Stop", 0, 0, Red);
if (ticketSell < 0)
{
Print("Error placing sell https://www.tellhappystar.org/ stop order. Error code: ", GetLastError());
}
}
Thanks and regards
RichardRut
Jul 20, 2023 at 11:01
Member Since Nov 12, 2019
6 posts
RichardRut posted:
Hy There i can see your post and i have some suggestion for you
//+------------------------------------------------------------------+
//| Buy_Sell_Stop.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int StartTimeHour = 12; // Trading start hour (0-23)
extern int StartTimeMinute = 15; // Trading start minute (0-59)
extern int DistancePips = 10; // Distance in pips from the open price
extern double LotSize = 1.0; // Lot size for the orders
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart()
{
datetime currentTime = TimeCurrent();
datetime tradingTime = TimeCurrent();
TimeHour(tradingTime) = StartTimeHour;
TimeMinute(tradingTime) = StartTimeMinute;
// Wait for the specified trading time
while (TimeCurrent() < tradingTime)
{
Sleep(1000);
}
// Get the open price of the specified candle (12:15)
double openPrice = iOpen(Symbol(), Period(), 0);
// Calculate the buy and sell stop prices
double buyStopPrice = openPrice + DistancePips * Point;
double sellStopPrice = openPrice - DistancePips * Point;
// Place the buy stop order
int ticketBuy = OrderSend(Symbol(), OP_BUYSTOP, LotSize, buyStopPrice, 0, 0, 0, "Buy Stop", 0, 0, Green);
if (ticketBuy < 0)
{
Print("Error placing buy stop order. Error code: ", GetLastError());
}
// Place the sell stop order
int ticketSell = OrderSend(Symbol(), OP_SELLSTOP, LotSize, sellStopPrice, 0, 0, 0, "Sell Stop", 0, 0, Red);
if (ticketSell < 0)
{
Print("Error placing sell https://www.tellhappystar.org/ stop order. Error code: ", GetLastError());
}
}
Thanks and regards
RichardRut
Hi RichardRut, thank you for your reply..
But I really know nothing about coding. What should I do with those codes? Kindly help me please. Thanks🙏
Member Since Aug 15, 2023
1 posts
Aug 15, 2023 at 09:18
Member Since Aug 15, 2023
1 posts
Certainly! Here's an example of an MQL4 script that places a buy stop order and a sell stop order based on a specified distance from the open price of a specified candle. This script does not include stop loss (SL) or take profit (TP) levels. Remember to test the script thoroughly before using it on a live trading account.
```c++
//+------------------------------------------------------------------+
//| PlaceStopOrders.mq4 |
//| Copyright 2023, Your Company Name |
//| https://www.yourwebsite.com |
//+------------------------------------------------------------------+
// Input parameters
input int CandleIndex = 1; // Index of the candle to use (0 represents the current candle)
input double BuyDistance = 10.0; // Distance in pips for the buy stop order
input double SellDistance = 10.0; // Distance in pips for the sell stop order
input int OrderExpiration = 60; // Order expiration time in minutes
// Function to calculate stop order prices
void CalculateStopOrderPrices(double openPrice, double& buyStopPrice, double& sellStopPrice)
{ https://candy-crush.io
double point = MarketInfo(Symbol(), MODE_POINT);
buyStopPrice = openPrice + BuyDistance * point;
sellStopPrice = openPrice - SellDistance * point;
}
// Entry point of the script
void OnStart()
{
// Check if the specified candle index is valid
if (CandleIndex < 0 || CandleIndex >= iBars(NULL, 0))
{
Print("Invalid candle index!");
return;
}
// Get the open price of the specified candle
double openPrice = iOpen(NULL, 0, CandleIndex);
// Calculate stop order prices
double buyStopPrice, sellStopPrice;
CalculateStopOrder
```c++
//+------------------------------------------------------------------+
//| PlaceStopOrders.mq4 |
//| Copyright 2023, Your Company Name |
//| https://www.yourwebsite.com |
//+------------------------------------------------------------------+
// Input parameters
input int CandleIndex = 1; // Index of the candle to use (0 represents the current candle)
input double BuyDistance = 10.0; // Distance in pips for the buy stop order
input double SellDistance = 10.0; // Distance in pips for the sell stop order
input int OrderExpiration = 60; // Order expiration time in minutes
// Function to calculate stop order prices
void CalculateStopOrderPrices(double openPrice, double& buyStopPrice, double& sellStopPrice)
{ https://candy-crush.io
double point = MarketInfo(Symbol(), MODE_POINT);
buyStopPrice = openPrice + BuyDistance * point;
sellStopPrice = openPrice - SellDistance * point;
}
// Entry point of the script
void OnStart()
{
// Check if the specified candle index is valid
if (CandleIndex < 0 || CandleIndex >= iBars(NULL, 0))
{
Print("Invalid candle index!");
return;
}
// Get the open price of the specified candle
double openPrice = iOpen(NULL, 0, CandleIndex);
// Calculate stop order prices
double buyStopPrice, sellStopPrice;
CalculateStopOrder

*Commercial use and spam will not be tolerated, and may result in account termination.
Tip: Posting an image/youtube url will automatically embed it in your post!
Tip: Type the @ sign to auto complete a username participating in this discussion.