A simpler way to control these runaway trades is to enter only on a state change instead of a state.
E.g. if you say "buy if I'm currently flat and bid > X," that opens the trade OK. But if some condition causes your EA to close it and bid is still > X, boom it's going to buy again. And sell again and buy again and sell again and ...
"bid > X" is a state. It's true for a long time. You probably want to enter only when that state CHANGES from <= X to >X.
So if instead you say something like "buy if I'm currently flat, and bid > X, and the LAST bid was <= X" -- then that only happens when the condition is first satisfied. When your exit code closes the trade, it doesn't open it again.
(Yeah, welcome back George!!)
Flying Slope auto-trading EA
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Re: Flying Slope auto-trading EA
Gary, I learn from you nearly every time you post. I love this idea.garyfritz wrote:A simpler way to control these runaway trades is to enter only on a state change instead of a state.
E.g. if you say "buy if I'm currently flat and bid > X," that opens the trade OK. But if some condition causes your EA to close it and bid is still > X, boom it's going to buy again. And sell again and buy again and sell again and ...
"bid > X" is a state. It's true for a long time. You probably want to enter only when that state CHANGES from <= X to >X.
So if instead you say something like "buy if I'm currently flat, and bid > X, and the LAST bid was <= X" -- then that only happens when the condition is first satisfied. When your exit code closes the trade, it doesn't open it again.
In this context, I haven't a clue what thingies state to examine, so I shall devote some bath-time to it.
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. pianodoodler@hotmail.com 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. pianodoodler@hotmail.com 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.
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: Flying Slope auto-trading EA
SteveHopwood wrote:Gary, I learn from you nearly every time you post. I love this idea.garyfritz wrote:A simpler way to control these runaway trades is to enter only on a state change instead of a state.
E.g. if you say "buy if I'm currently flat and bid > X," that opens the trade OK. But if some condition causes your EA to close it and bid is still > X, boom it's going to buy again. And sell again and buy again and sell again and ...
"bid > X" is a state. It's true for a long time. You probably want to enter only when that state CHANGES from <= X to >X.
So if instead you say something like "buy if I'm currently flat, and bid > X, and the LAST bid was <= X" -- then that only happens when the condition is first satisfied. When your exit code closes the trade, it doesn't open it again.
In this context, I haven't a clue what thingies state to examine, so I shall devote some bath-time to it.
Gary is correct, that is the better way to go. If you are examining the trading conditions in a discrete fashion (opening of every bar) you just need to keep track of the results of your evaluation. Below is some code I used when I coded my first EA using your framework. No doubt I put things in the wrong place, but it still illustrates the points. In this code I am looking for the direction of an MA cross and the GANN Hi-Lo to be in agreement. The code starts by saving the results of this evaluation from the last time I called the function into PreviousDirection. Then I do my check and save it into CurrentDirection. I only trigger the trade (setting LookingForBuy or LookingForSell to true) if CurrentDirection != PreviousDirection.
Code: Select all
void ReadIndicatorValues()
{
static int TotalBars=0;
//only read these once a minute
if (Bars == TotalBars)
return;
TotalBars=Bars;
//store the previous direction state
PreviousDirection = CurrentDirection;
GANN_Direction = GetGANN(180);
if (GetMa(0,13,0,MODE_EMA,PRICE_CLOSE,i+1) > GetMa(0,34,0,MODE_EMA,PRICE_OPEN,i+1))
MA_Direction = up;
else
MA_Direction = down;
if (GANN_Direction == MA_Direction)
CurrentDirection = GANN_Direction;
else
CurrentDirection = none;
if (CurrentDirection == up && PreviousDirection != up)
LookingForBuy=true;
if (CurrentDirection == down && PreviousDirection != down)
LookingForSell=true;
if (CurrentDirection != up) LookingForBuy = false;
if (CurrentDirection != down) LookingForSell = false;
}//void ReadIndicatorValues()
If you are evaluating the trading conditions continuously (every tick) you'll have to impose some sort of waiting period between trades. Since many indicators use the close of the bar, there is a chance that your state will change back and forth with every tick.
George
-
garyfritz
Re: Flying Slope auto-trading EA
Glad you like it, Steve. Enjoy your bath. 
And even the state-change idea I posted can have problems, e.g. if the bid oscillates above/below/above/below your entry price. It might be better to use state variables, so when you want to set up an entry, you set GoLong = true. Then your test is "if (GoLong and bid > X) { [[buy]]; GoLong = false; } Then you're sure you'll only enter once.
I think that might have been how George used his LookingForBuy var?
And even the state-change idea I posted can have problems, e.g. if the bid oscillates above/below/above/below your entry price. It might be better to use state variables, so when you want to set up an entry, you set GoLong = true. Then your test is "if (GoLong and bid > X) { [[buy]]; GoLong = false; } Then you're sure you'll only enter once.
I think that might have been how George used his LookingForBuy var?
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: Flying Slope auto-trading EA
Yep, that's exactly how I used it, though in this case the trigger was price exceeding the prior bar's high.garyfritz wrote:Glad you like it, Steve. Enjoy your bath.
And even the state-change idea I posted can have problems, e.g. if the bid oscillates above/below/above/below your entry price. It might be better to use state variables, so when you want to set up an entry, you set GoLong = true. Then your test is "if (GoLong and bid > X) { [[buy]]; GoLong = false; } Then you're sure you'll only enter once.
I think that might have been how George used his LookingForBuy var?
From LookForTradingOpportunities():
Code: Select all
//Long -- wait until current bar exceeds previous
if (High[0] > High[1] && LookingForBuy)
{
LookingForBuy = false;
...
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Re: Flying Slope auto-trading EA
Hehe. Let me know if you two geniuses come to any firm, usable conclusions.
By 'usable', I mean usable by a dimwit like me. I rarely understand a word of what you two write. You bring the term 'High level language' to a whole new level of meaning.

By 'usable', I mean usable by a dimwit like me. I rarely understand a word of what you two write. You bring the term 'High level language' to a whole new level of meaning.
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. pianodoodler@hotmail.com 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. pianodoodler@hotmail.com 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.
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: Flying Slope auto-trading EA
I'll take a look-see over the long US weekend and see if I can add something.... No promises.SteveHopwood wrote:Hehe. Let me know if you two geniuses come to any firm, usable conclusions.
By 'usable', I mean usable by a dimwit like me. I rarely understand a word of what you two write. You bring the term 'High level language' to a whole new level of meaning.![]()
George
- Mike
- Trader
- Posts: 272
- Joined: Sun Dec 11, 2011 12:30 pm
- Location: Italy
Re: Flying Slope auto-trading EA
Hi, does anybody trade this bot succesfully? if yes, please post your set-file. With ootb I have only loosing trades! Thanks
- cuzgeorge
- Trader
- Posts: 674
- Joined: Mon Mar 05, 2012 10:10 am
- Location: Johannesburg, South Africa.
Re: Flying Slope auto-trading EA
Hi Mike,Mike wrote:Hi, does anybody trade this bot succesfully? if yes, please post your set-file. With ootb I have only loosing trades! Thanks
The pic results are the only one's i've ever had on FS. Please check the dates, about a month ago.
I have since tried to play around with the settings and slope to try and get a trade out of it, but no luck. I also noticed TIG and TOIG are interested here, so stopped tinkering to see what they'll come up with.
heres' what i got attached. set file and pic.
regards,
the other George.
You do not have the required permissions to view the files attached to this post.
10.X, BMac,Xmeter,Marylin,and CaptsNakedTrading thread coupled with Slowkeys Intraday setup for manual trades.
http://www.stevehopwoodforex.com/phpBB3 ... f=36&t=848
http://www.stevehopwoodforex.com/phpBB3 ... f=36&t=848
- Mike
- Trader
- Posts: 272
- Joined: Sun Dec 11, 2011 12:30 pm
- Location: Italy
Re: Flying Slope auto-trading EA
Thanks, I got some more trades, but quite often the program is not responding and I have to restart it. I loaded history many times, and I do not know, what stops it. Looking at the concept, it should be possible to get it working, but ... so I keep glancing at it and wonder why nobody works on it ... but right now, so many fascinating bots are worked on ...cuzgeorge wrote:Hi Mike, The pic results are the only one's i've ever had on FS ... the other George.Mike wrote:Hi, does anybody trade this bot succesfully? if yes, please post your set-file. With ootb I have only loosing trades! Thanks
Thanks Mike