My shell EA code

My shell EA code

Postby LittleCaro » Tue Oct 08, 2019 1:44 pm

Hey guys,

I think i got it :

At the end of the code (in the lines 4400), i replace the line :

Code: [Select all]
 Please Login or Register to see this content
<


With the line :

Code: [Select all]
 Please Login or Register to see this content
<



And since the expert didn't miss any trades.

Greatly helped with the comment in the code.

:!!: :!!: :!!: :!!: :!!:
User avatar
LittleCaro
 
Posts: 62
Joined: Tue May 19, 2015 7:09 am

My shell EA code

Postby SteveHopwood » Tue Oct 08, 2019 4:01 pm

:clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap:

:xm: :rocket:
Read the effing manual, ok?

Global Prime is the official SHF broker. Click here to sign up for a live account with Global Prime and join the several thousand SHF members who wisely choose GP as their broker of choice.

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 Tommaso (milanese) for all the incredible work he does here.
User avatar
SteveHopwood
 
Posts: 9107
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Postby K-Lander » Tue Jun 16, 2020 4:50 pm

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
K-Lander
 
Posts: 34
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

My shell EA code

Postby SteveHopwood » Tue Jun 16, 2020 7:00 pm

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

Great to see you getting your hands dirty. :clap: :clap: :clap: :clap: :clap:

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]
 Please Login or Register to see this content
<


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:
Code: [Select all]
 Please Login or Register to see this content
<

Inside the function goes:
Code: [Select all]
 Please Login or Register to see this content
<


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:
Code: [Select all]
 Please Login or Register to see this content
<



:xm: :rocket:
Read the effing manual, ok?

Global Prime is the official SHF broker. Click here to sign up for a live account with Global Prime and join the several thousand SHF members who wisely choose GP as their broker of choice.

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 Tommaso (milanese) for all the incredible work he does here.
User avatar
SteveHopwood
 
Posts: 9107
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Postby K-Lander » Tue Jun 16, 2020 7:54 pm

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
K-Lander
 
Posts: 34
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

My shell EA code

Postby K-Lander » Wed Jun 17, 2020 12:49 am

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. :clap: :clap: :clap: :clap: :clap:

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]
 Please Login or Register to see this content
<


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:
Code: [Select all]
 Please Login or Register to see this content
<

Inside the function goes:
Code: [Select all]
 Please Login or Register to see this content
<


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:
Code: [Select all]
 Please Login or Register to see this content
<



:xm: :rocket:[/quote]
K-Lander
 
Posts: 34
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

My shell EA code

Postby SteveHopwood » Wed Jun 17, 2020 11:13 am

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);
}



You are on the right track.

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]
 Please Login or Register to see this content
<

and you will see what I mean.

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 =

You need to use Thomas' BetterOrderSelect() function instead of the Mql4 OrderSelect(). Read the comment just above the function for explanation. As coded, your function will not give accurate results. Your OrderSelect() call needs to be:
Code: [Select all]
 Please Login or Register to see this content
<


Where the function goes in your code does not matter so long as it does not go inside another function.

:xm: :rocket:
Read the effing manual, ok?

Global Prime is the official SHF broker. Click here to sign up for a live account with Global Prime and join the several thousand SHF members who wisely choose GP as their broker of choice.

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 Tommaso (milanese) for all the incredible work he does here.
User avatar
SteveHopwood
 
Posts: 9107
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Postby K-Lander » Wed Jun 17, 2020 4:12 pm

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 :smile:
You do not have the required permissions to view the files attached to this post.
K-Lander
 
Posts: 34
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

My shell EA code

Postby SteveHopwood » Wed Jun 17, 2020 5:58 pm

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 :smile:

Looks good to me. :clap: :clap: :clap: :clap: :clap: :clap: :clap:

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]
 Please Login or Register to see this content
<


This will also return 'false' if you have ForceSleepUntilNextBar set to 'false' to disable this filter, so the bot will never Trade. My fault. Here is the corrected code:
Code: [Select all]
 Please Login or Register to see this content
<


:xm: :rocket:
Read the effing manual, ok?

Global Prime is the official SHF broker. Click here to sign up for a live account with Global Prime and join the several thousand SHF members who wisely choose GP as their broker of choice.

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 Tommaso (milanese) for all the incredible work he does here.
User avatar
SteveHopwood
 
Posts: 9107
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

My shell EA code

Postby K-Lander » Thu Jun 18, 2020 5:28 pm

Hi Steve,
Attached I am sending Bare Bones with a working ForceSleepUntilNextBar feature.

A friendly reminder to anyone using the shells: Remember to DELETE the failsafe on the code (you´ll find it within the LookForTradingOpportunities function). Nothing will ever trigger a trade unless you do it (I forgot about it and took me 2 hours to figure out why the bugger doesn´t fire).

Thanks for the help Steve, and for the coding lesson.

All the best, and stay safe in these strange times.

Ariel


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]
 Please Login or Register to see this content
<


This will also return 'false' if you have ForceSleepUntilNextBar set to 'false' to disable this filter, so the bot will never Trade. My fault. Here is the corrected code:
Code: [Select all]
 Please Login or Register to see this content
<


:xm: :rocket:
You do not have the required permissions to view the files attached to this post.
K-Lander
 
Posts: 34
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

Previous

Return to Coders Hangout

Who is online

Users browsing this forum: No registered users and 2 guests