Hello all,
I have a little problem,
So i'm coding an expert with the amazing steve's shell ea code, and i'm using the read indicator values module, and the close order on opposite direction signal fonction.
Here is the problem, sometimes (maybe 3 times out of 10), the expert closes the order (so he reads correctly the indicators and get the good signall), BUT the opposite trade is not sent.
And i didn't see any tracks of "context is busy" in the logs.
I wonder if some doctors could help here ?
Thanks !
My shell EA code
- LittleCaro
- Trader
- Posts: 63
- Joined: Tue May 19, 2015 7:09 am
My shell EA code
Hey guys,
I think i got it :
At the end of the code (in the lines 4400), i replace the line :
With the line :
And since the expert didn't miss any trades.
Greatly helped with the comment in the code.
I think i got it :
At the end of the code (in the lines 4400), i replace the line :
Code: Select all
TimeToStartTrading = 0;//Set to TimeCurrent() + (PostTradeAttemptWaitMinutes * 60) when there is an OrderSend() attempt)
Code: Select all
TimeCurrent() + PostTradeAttemptWaitSeconds;
And since the expert didn't miss any trades.
Greatly helped with the comment in the code.
- SteveHopwood
- Owner
- Posts: 9754
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
My shell EA code
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
-
- Trader
- Posts: 35
- Joined: Thu Nov 17, 2011 9:03 pm
- Location: Buenos Aires, Argentina
My shell EA code
Hello Everyone,
I´ve been using the Barebones shell to code different strategies based on price action. One problem I have stumbled upon several times, and was unable to solve due to my limited coding skills, is related to the fact that many of my strategies consider the price action since the beginning of a given bar and how the bar develops in time.
The problem is that if the EA works on H1 and a trade closes at, let´s say, 15:33, I have no way to make the EA get back to work at 16:00, i.e. at the beginning of the next H1 bar (the same applies to any other timeframe). The "Sleep After Trade Closure" input only allows me to make the EA sleep for a fixed number of minutes, while I need it to sleep until the beginning of the next bar.
I think it would be a nice addition to the shell. I would be truly happy and grateful if anyone could propose a solution.
Thanks y´all, and stay safe.
Ariel
I´ve been using the Barebones shell to code different strategies based on price action. One problem I have stumbled upon several times, and was unable to solve due to my limited coding skills, is related to the fact that many of my strategies consider the price action since the beginning of a given bar and how the bar develops in time.
The problem is that if the EA works on H1 and a trade closes at, let´s say, 15:33, I have no way to make the EA get back to work at 16:00, i.e. at the beginning of the next H1 bar (the same applies to any other timeframe). The "Sleep After Trade Closure" input only allows me to make the EA sleep for a fixed number of minutes, while I need it to sleep until the beginning of the next bar.
I think it would be a nice addition to the shell. I would be truly happy and grateful if anyone could propose a solution.
Thanks y´all, and stay safe.
Ariel
- SteveHopwood
- Owner
- Posts: 9754
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
My shell EA code
Great to see you getting your hands dirty.K-Lander » Tue Jun 16, 2020 4:50 pm wrote:Hello Everyone,
I´ve been using the Barebones shell to code different strategies based on price action. One problem I have stumbled upon several times, and was unable to solve due to my limited coding skills, is related to the fact that many of my strategies consider the price action since the beginning of a given bar and how the bar develops in time.
The problem is that if the EA works on H1 and a trade closes at, let´s say, 15:33, I have no way to make the EA get back to work at 16:00, i.e. at the beginning of the next H1 bar (the same applies to any other timeframe). The "Sleep After Trade Closure" input only allows me to make the EA sleep for a fixed number of minutes, while I need it to sleep until the beginning of the next bar.
I think it would be a nice addition to the shell. I would be truly happy and grateful if anyone could propose a solution.
Thanks y´all, and stay safe.
Ariel
I will tell you what to do because this is usually the hardest part to work out. You can work out the actual code because it is more satifsying for you, but post again if you get hopelessly stuck.
Declare a boolean in the general inputs section, that tells your bot whether to wait for the open of the next candle or not, so you can experiment if need be:
Code: Select all
bool ForceWaitUntilNextCandle = true;
Code: Select all
bool didTradeCloseBeforeCurrentCandle(string symbol)
{
}//End didTradeCloseBeforeCurrentCandle(string symbol)
Code: Select all
bool didTradeCloseBeforeCurrentCandle(string symbol)
{
iterate through the orders in your history tab
{
check that the bot 'owns' the trade. The line that checks the symbol will be:
if (OrderSymbol() != symbol) continue;
examine the order close time and return false if it is >= the open time of the current candle
}//end of iteration
getting to here means there was no closed order found that closed during the current
candle, so return true
}//End didTradeCloseBeforeCurrentCandle(string symbol)
Code: Select all
if (ForceWaitUntilNextCandle && didTradeCloseBeforeCurrentCandle(Symbo() ) )
{
return (true);
else
return (false);
}
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
-
- Trader
- Posts: 35
- Joined: Thu Nov 17, 2011 9:03 pm
- Location: Buenos Aires, Argentina
My shell EA code
Great Steve, will give it a try this week and post again for help if need be. I was thinking in a much more complicated way to do it, actually. Your approach makes a lot more sense.
Thanks a bunch,
Ariel
Thanks a bunch,
Ariel
-
- Trader
- Posts: 35
- Joined: Thu Nov 17, 2011 9:03 pm
- Location: Buenos Aires, Argentina
My shell EA code
Hi Steve,
I understand the logic; not so sure about the syntax and where to insert it within Bare Bones. I came up with this time-checking routine though. Would you mind take a look? Thanks,
bool DidTradeCloseBeforeCurrentCandle()
{
total = OrdersHistoryTotal();
for(i = total - 1; i >= 0; i--){
OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol() == Symbol())
{
if(OrderCloseTime()>=iTime(NULL,0,0)) return (false);
}}
return (true);
}
Great to see you getting your hands dirty.
I will tell you what to do because this is usually the hardest part to work out. You can work out the actual code because it is more satifsying for you, but post again if you get hopelessly stuck.
Declare a boolean in the general inputs section, that tells your bot whether to wait for the open of the next candle or not, so you can experiment if need be:
Next create a function that examines the orders in your History tab to find out whether the most recently closed trade closed before the open of the current candle. One of the thingies I have learned since creating these shells is to add functions in such a way that they can be pasted into a multi-pair EA without needing adjustment. I would do something like this:
Inside the function goes:
Then you go to the bool IsTradingAllowed() function. This is the final step in LookForTradingOpportunities() that could cancel an order send. This is the code to add:
[/quote]
I understand the logic; not so sure about the syntax and where to insert it within Bare Bones. I came up with this time-checking routine though. Would you mind take a look? Thanks,
bool DidTradeCloseBeforeCurrentCandle()
{
total = OrdersHistoryTotal();
for(i = total - 1; i >= 0; i--){
OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol() == Symbol())
{
if(OrderCloseTime()>=iTime(NULL,0,0)) return (false);
}}
return (true);
}
Great to see you getting your hands dirty.
I will tell you what to do because this is usually the hardest part to work out. You can work out the actual code because it is more satifsying for you, but post again if you get hopelessly stuck.
Declare a boolean in the general inputs section, that tells your bot whether to wait for the open of the next candle or not, so you can experiment if need be:
Code: Select all
bool ForceWaitUntilNextCandle = true;
Code: Select all
bool didTradeCloseBeforeCurrentCandle(string symbol)
{
}//End didTradeCloseBeforeCurrentCandle(string symbol)
Code: Select all
bool didTradeCloseBeforeCurrentCandle(string symbol)
{
iterate through the orders in your history tab
{
check that the bot 'owns' the trade. The line that checks the symbol will be:
if (OrderSymbol() != symbol) continue;
examine the order close time and return false if it is >= the open time of the current candle
}//end of iteration
getting to here means there was no closed order found that closed during the current
candle, so return true
}//End didTradeCloseBeforeCurrentCandle(string symbol)
Code: Select all
if (ForceWaitUntilNextCandle && didTradeCloseBeforeCurrentCandle(Symbo() ) )
{
return (true);
else
return (false);
}
[/quote]
- SteveHopwood
- Owner
- Posts: 9754
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
My shell EA code
You are on the right track.K-Lander » Wed Jun 17, 2020 12:49 am wrote:Hi Steve,
I understand the logic; not so sure about the syntax and where to insert it within Bare Bones. I came up with this time-checking routine though. Would you mind take a look? Thanks,
bool DidTradeCloseBeforeCurrentCandle()
{
total = OrdersHistoryTotal();
for(i = total - 1; i >= 0; i--){
OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol() == Symbol())
{
if(OrderCloseTime()>=iTime(NULL,0,0)) return (false);
}}
return (true);
}
A tip. Next time you post code, encase it within the code button for readability - 5th button along. Compare this:
bool DidTradeCloseBeforeCurrentCandle()
{
total = OrdersHistoryTotal();
for(i = total - 1; i >= 0; i--){
OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol() == Symbol())
{
if(OrderCloseTime()>=iTime(NULL,0,0)) return (false);
}}
return (true);
}
with this:
Code: Select all
bool DidTradeCloseBeforeCurrentCandle()
{
int total = OrdersHistoryTotal();
for(int i = total - 1; i >= 0; i--){
bool result = OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol() == Symbol())
{
if(OrderCloseTime()>=iTime(NULL,0,0)) return (false);
}
}
return (true);
}
Errors would show up if you tried to compile your version i.e.
- total was not declared. I made it an int.
- ditto i.
- a warning that the return value of OrderSelect should be checked, so I added bool result =
Code: Select all
bool result = BetterOrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
-
- Trader
- Posts: 35
- Joined: Thu Nov 17, 2011 9:03 pm
- Location: Buenos Aires, Argentina
My shell EA code
Well, here it is. Attached I am posting Bare Bones with the new feature. I´ll be running it to make sure it indeed works as expected. In the meantime, if you could check the code, it would be great.
The extern user input is in line 229, right after TradingHours;
The routine that checks whether there is a closed trade in the current candle is in lines 2187 to 2200.
The conditional within IsTradingAllowed is in lines 1175 to 1182.
It compiled ok. Strange, no mismatching parentheses this time. Must be doing something right for a change
The extern user input is in line 229, right after TradingHours;
The routine that checks whether there is a closed trade in the current candle is in lines 2187 to 2200.
The conditional within IsTradingAllowed is in lines 1175 to 1182.
It compiled ok. Strange, no mismatching parentheses this time. Must be doing something right for a change
You do not have the required permissions to view the files attached to this post.
- SteveHopwood
- Owner
- Posts: 9754
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
My shell EA code
Looks good to me.K-Lander » Wed Jun 17, 2020 4:12 pm wrote:Well, here it is. Attached I am posting Bare Bones with the new feature. I´ll be running it to make sure it indeed works as expected. In the meantime, if you could check the code, it would be great.
The extern user input is in line 229, right after TradingHours;
The routine that checks whether there is a closed trade in the current candle is in lines 2187 to 2200.
The conditional within IsTradingAllowed is in lines 1175 to 1182.
It compiled ok. Strange, no mismatching parentheses this time. Must be doing something right for a change
By the by, what I wrote about OrderSelect() was slightly incorrect and only applies to orders selected by ticket, not pos. Even so, stick with BetterOrderSelect() because: it makes sure you never fall foul of the OrderSelect() function; when one of the genius coders here replaces a Crapql4 function with his/her own code, then it is best to use it.
The subconscious is an amazing thingy and mine was at work as I typed the above. It just told me that I had given you duff info about the call to the function as well. Think about this call:
Code: Select all
if (ForceSleepUntilNextBar && DidTradeCloseBeforeCurrentCandle()) return (true);
else
return (false);
Code: Select all
if (ForceSleepUntilNextBar)
{
if (DidTradeCloseBeforeCurrentCandle() ) return (true);
else
return (false);
}//if (ForceSleepUntilNextBar)
Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.