I want to develop an EA that takes buy and sell stop orders on inside bar when an Asian low/high or previous day high/low has been taken. The EA will then look for inside bar and place buy and sell stop orders on it. Users can decide to use only the Asian high/low or the previous day high/low. I have some errors and would greatly appreciate if someone here can help as I’m still new to this. Will upload pictures of how it should look like. Here are the code.
// Include required libraries
#include <Trade\Trade.mqh>
#include <Arrays\Array.mqh>
// Define global variables
double asianHigh, asianLow, prevDayHigh, prevDayLow;
int slippage = 4;
int takeProfit = 12;
int stopLoss = 4;
bool takeLows = true;
bool takeHighs = true;
bool reentry = true;
int reentryCandles = 5;
bool takeAllInsideBars = false;
bool onlyBuyStops = false;
bool onlySellStops = false;
// Function to calculate the Asian session high/low and previous day high/low
void calcHighLow()
{
// Get the current hour and minute
int hour = TimeHour(TimeCurrent());
int minute = TimeMinute(TimeCurrent());
// Check if the current time is within the Asian session
if (hour >= 23 || (hour >= 0 && hour < 9) || (hour == 9 && minute < 30))
{
// Get the high and low of the current Asian session
asianHigh = High[iHighest(NULL, 0, MODE_HIGH, 9, 30)];
asianLow = Low[iLowest(NULL, 0, MODE_LOW, 9, 30)];
}
else
{
// Get the high and low of the previous day
asianHigh = High[iHighest(NULL, 0, MODE_HIGH, 19, 30)];
asianLow = Low[iLowest(NULL, 0, MODE_LOW, 19, 30)];
}
// Get the high and low of the previous day
prevDayHigh = High[iHighest(NULL, 0, MODE_HIGH, 23, 59)];
prevDayLow = Low[iLowest(NULL, 0, MODE_LOW, 23, 59)];
}
// Function to check for an inside bar formation
bool checkInsideBar()
{
// Get the current high and low
double currHigh = High[0];
double currLow = Low[0];
// Check if the current high and low is within the Asian session high/low and previous day high/low
if (currHigh <= asianHigh && currLow >= asianLow && currHigh <= prevDayHigh && currLow >= prevDayLow)
{
return true;
}
else
{
return false;
}
}
// Function to place buy and sell stop orders
void placeOrders()
{
// Check if an inside bar formation has occurred
if (checkInsideBar())
{
if (takeLows) {
// Place a buy stop order at the current high
double buyStopPrice = High[0];
OrderSend(Symbol(), OP_BUYSTOP, 1, buyStopPrice, 3, stopLoss, takeProfit, "My EA", 0, 0, CLR_NONE);
}
if (takeHighs) {
// Place a sell stop order at the current low
double sellStopPrice = Low
I also attached the possible settings the EA should have in the settings. Thanks a lot guys
Files:
735D5AB4-859C-459F-A6F6-CBCB511D6E8E.jpeg
96 kb
C28B9A7F-2CEA-4AD1-884E-CE4F80D9FDFE.png
113 kb
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
- Why won't this open any trades?
- [WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you.
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
#include <Trade\Trade.mqh>
MQL4 doesn't use this.
Chinedu Emmanuel Obiajulu:
I want to develop an EA that takes buy and sell stop orders on inside bar when an Asian low/high or previous day high/low has been taken. The EA will then look for inside bar and place buy and sell stop orders on it. Users can decide to use only the Asian high/low or the previous day high/low. I have some errors and would greatly appreciate if someone here can help as I’m still new to this. Will upload pictures of how it should look like. Here are the code.
YOU need to post your entire code if you need help. “Some errors” cannot be more vague…
I want to develop an EA that takes buy and sell stop orders on inside bar when an Asian low/high or previous day high/low has been taken. The EA will then look for inside bar and place buy and sell stop orders on it. Users can decide to use only the Asian high/low or the previous day high/low. I have some errors and would greatly appreciate if someone here can help as I’m still new to this. Will upload pictures of how it should look like. Here are the code.
I also attached the possible settings the EA should have in the settings. Thanks a lot guys
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register