Joe. Swing-trade your way to a baby equity millipede

Post Reply
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Joe. Swing-trade your way to an equity millipede

Post by gaheitman »

Steve,

Nice job! I'm looking forward to getting this one fully operational...

To that end, I have one comment and then some code ( :D )

In LookForTradingOpportunities() you only move the prior trade to BE if you are trying to get in a new trade. Shouldn’t you try to move to BE regardless and then just verify the last trade is at BE before taking a new one? As it is, our additional filters can not only keep us from getting a new trade started they can prevent one from moving to BE. Also, the rules seem to say that you move to break even if in profit so you could just test OrderProfit() > 0, but I think we need to have a pips in profit threshold of some sort.

Now for the fun part. Consider the following as really detailed pseudo-code. It compiles, but is untested.

From the rules, I read three different scaling out strategies: close some, close half, close all but two strongest. I combined these to "close the weakest half".

I didn't really know where to stick this code. LookForTradeClosure() is about managing TP/SL on individual trades, so I created StrategyLookForTradeClosure(). It is:

Code: Select all

void StrategyLookForTradeClosure() {

   if (OpenTrades == 0) return;
   bool CloseHalf=false;
   
   //check for buys
   if (BuyOpen)
      if (Close[i+1] < Low[PreviousUpBar(i+1)]) CloseHalf=true;
   if (SellOpen)
      if (Close[i+1] > High[PreviousDnBar(i+1)]) CloseHalf=true;
      
   if (CloseHalf) {
      //count the trades
      int cnt = 0;
      int total = OrdersTotal();
      for (i=0;i<total;i++)
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if (OrderType() != OP_BUY  && OrderType() != OP_SELL) continue;
            if (OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() != Symbol()) continue;
            cnt++;
         }//if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))  
     
      //and close half of them
      for (int i=1;i<cnt/2;i++)
         CloseWorstTrade();
   }   
}
Nothing too surprising here. I call these two procedures to get the last Up/Dn bar respectively.

Code: Select all

int PreviousUpBar(int i) {
   i++;
   while(Close[i]<=Open[i]) i++;
   return(i);
}

int PreviousDnBar(int i) {
   i++;
   while(Close[i]>=Open[i]) i++;
   return(i);
}
Finally, the code to close the "worst" open trade. This is likely equivalent to closing the last trade, but just in case....

Code: Select all

void CloseWorstTrade() {

//find worst performing trade
      int total = OrdersTotal();
      int worst = 0;
      double worst_profit = 10000000;
      for (i=0;i<total;i++)
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if (OrderType() != OP_BUY  && OrderType() != OP_SELL) continue;
            if (OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() != Symbol()) continue;
            if (OrderProfit()< worst_profit) {
               worst = OrderTicket();
               worst_profit = OrderProfit();
            }//if (OrderProfit()< worst_profit) 
         }//if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 

//close worst trade
      bool result = CloseTrade(worst);
      //Actions when trade close succeeds
      if (result)
      {
         DeletePendingPriceLines();
         TicketNo = -1;//TicketNo is the most recently trade opened, so this might need editing in a multi-trade EA
         OpenTrades--;//Rather than OpenTrades = 0 to cater for multi-trade EA's
      }//if (result)
}
The close part of the code was lifted from LookForTradeClosure(). I agree with your TicketNo comment, but not sure what to do about it here.

As I like to say, you can learn from good examples as well as bad, so hopefully this will give you a headstart on the rest of the bot, one way or the other. ;)

George
chonghm
Posts: 6
Joined: Thu Nov 24, 2011 12:08 am

Re: Joe. Swing-trade your way to an equity millipede

Post by chonghm »

Hello Steve,
Thanks for the prompt action in coding this EA. Please do not confuse this with the equity Millipede system. This is short time trading system. It may last a few hours or at most to a couple of days. Once the signal is exhausted Joe will close all positions for a tidy profit and wait for the next 4hr flying buddha.

The Equity Melipede is long term trading system. Graeme may hold positions up to a couple of years. If I am not mistaken he is still holding on to his sell positions for GbpJpy which he took 2 years ago. He is an excellent trader and he also trades counter positions to freeze his profits when there is a retracement. His exact words is he will never know where the market is heading except anticipate. The retracement may turn up to the new trend for the next couple of years.

Mr.Pathumracled, Please note that in the Equity Milipede system there will not be any drawdown which will blow the acccount. Graeme on going trades are all in profits. He always open postions in th 5 minutes timetrame with a small stoploss. If the trade is stopped out he will look for the next oppotunity. His motto "small stop loss and huge gains". He is not talking about RR1:1. He is talking RR1:100. Its difficult to trade his system because most of us cannot stomach the idea that your 500 pips profit goes may to breakeven.

Cheers,
chonghm
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Joe. Swing-trade your way to an equity millipede

Post by SteveHopwood »

ananthhh wrote:hi steve,
I have just gone through the code...
I like to share my thoughts regarding the code...
If am wrong or misunderstood anywhere, please forgive my innocence and correct me

1.I found that trade is taken when the flying buddha is formed on both higher and lower time frame. But according to the rules in the document, its enough to have flying buddha at higher time frame.
This is just one of many ways of determining in which direction to trade. You turn off the higher tf FB by setting FbHigherTimeFrame to the same value as FbTradingTimeFrame.
2.For stacking, it is mentioned in the document to use 50% fib levels, but i couldn't find any details for stacking in the code (sorry if it is there and please let me know where it is written).
That is strange because I typed the code. I must have deleted it accidentally. Hey-ho; I will reinstate it later. Thanks.
3.Regarding closure and to detect weakening of trend, we can first test with the method as mentioned in the document (i.e.,) when any candle closes above previous high for sell trades and closes below previous high for buy trades.
Good point. I would have remembered eventually. Possibly. :lol:
4.No. of positions to be closed can be given as user input or we can test with some random numbers like 1/4 positions from bottom and 1/4 positions from top.
Good idea.

Thanks for this.

Cheers

:D
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.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Joe. Swing-trade your way to an equity millipede

Post by SteveHopwood »

Pathumracled wrote:Good day Sir Hopwood (All),
All I can Say are these (1) Finally… with a Smile (2) thanks for the Notifications on important developments, Via PM works marvelously for me! & (3) Thanks for this particular initiative. :mrgreen:

Met upon that (Equity Millipede) thread some time now and from June 2011, it gave me the first practical implementation of the adage “Cutting your Losses and allowing your profits to Run” (Graeme/PipEasy, the originator of the thread had seemingly limitless resources so he could afford to see 500+ pips legs die off at break even +pips. That I could not stomach, so for me locking in reasonable profits up to 1.5 x the margined amount on the winning trade was preferred. And, that is one of the beauties of the concept, it can be applied to any Successful Entry method, initially the Flying Buddha(FB) was used on D1, but to my mind it (Equty millipede via Stacking of Winners) can as easily be applied to an MA Crosses, Candle Break-Out or whatever your successful entry method is, just as long as the Entry Quality is High (excellent track record of market agreeing with trade entry, buy or sell 50-60%) and the lot sizes are geared low. So we could in effect use any one of our successful methods here to build an equity Millipede, hence the thought, some time, for the Caterpillar concept to be incorporated in the MPTM (If and when that aspect is added, my thoughts here will be proven…. Patience is essential to Long term Fx Profitability, don’t have any? Buy Some ;) )

etc

Spent Some 2 + weeks reading through the thread before getting some of the key concepts. I share the forgoing so that it may jumpstart someone. It is hoped that we will be able to implement the Concept of “Making Profits Run whilst cutting Losses”, in this automation process thereby having the immense benefits of Building Equity millipedes via trend trading.

Bless! >;<
Fantastic. Thanks. I have linked this in post 1.

Cheers

:D
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.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Joe. Swing-trade your way to an equity millipede

Post by SteveHopwood »

gaheitman wrote:As I like to say, you can learn from good examples as well as bad, so hopefully this will give you a headstart on the rest of the bot, one way or the other. ;)

George
George, you are the most total star on the entire planet. This saves me a heap of bathtime. :lol:

Cheers
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.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Joe. Swing-trade your way to an equity millipede

Post by SteveHopwood »

chonghm wrote:Hello Steve,
Thanks for the prompt action in coding this EA. Please do not confuse this with the equity Millipede system. This is short time trading system. It may last a few hours or at most to a couple of days. Once the signal is exhausted Joe will close all positions for a tidy profit and wait for the next 4hr flying buddha.

The Equity Melipede is long term trading system. Graeme may hold positions up to a couple of years. If I am not mistaken he is still holding on to his sell positions for GbpJpy which he took 2 years ago. He is an excellent trader and he also trades counter positions to freeze his profits when there is a retracement. His exact words is he will never know where the market is heading except anticipate. The retracement may turn up to the new trend for the next couple of years.

Mr.Pathumracled, Please note that in the Equity Milipede system there will not be any drawdown which will blow the acccount. Graeme on going trades are all in profits. He always open postions in th 5 minutes timetrame with a small stoploss. If the trade is stopped out he will look for the next oppotunity. His motto "small stop loss and huge gains". He is not talking about RR1:1. He is talking RR1:100. Its difficult to trade his system because most of us cannot stomach the idea that your 500 pips profit goes may to breakeven.

Cheers,
chonghm
Thanks. I have changed the thread title slightly.

:D
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.
andydoc
Trader
Posts: 53
Joined: Sun Dec 11, 2011 8:26 am
Location: West Brom, UK

Re: Joe. Swing-trade your way to an equity millipede

Post by andydoc »

gaheitman wrote:Steve,

I didn't really know where to stick this code. LookForTradeClosure() is about managing TP/SL on individual trades, so I created StrategyLookForTradeClosure(). It is:

Code: Select all

void StrategyLookForTradeClosure() {

   if (OpenTrades == 0) return;
   bool CloseHalf=false;
   
   //check for buys
   if (BuyOpen)
      if (Close[i+1] < Low[PreviousUpBar(i+1)]) CloseHalf=true;
   if (SellOpen)
      if (Close[i+1] > High[PreviousDnBar(i+1)]) CloseHalf=true;
      
   if (CloseHalf) {
      //count the trades
      int cnt = 0;
      int total = OrdersTotal();
      for (i=0;i<total;i++)
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if (OrderType() != OP_BUY  && OrderType() != OP_SELL) continue;
            if (OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() != Symbol()) continue;
            cnt++;
         }//if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))  
     
      //and close half of them
      for (int i=1;i<cnt/2;i++)
         CloseWorstTrade();
   }   
}
Nothing too surprising here. I call these two procedures to get the last Up/Dn bar respectively.

Code: Select all

int PreviousUpBar(int i) {
   i++;
   while(Close[i]<=Open[i]) i++;
   return(i);
}

int PreviousDnBar(int i) {
   i++;
   while(Close[i]>=Open[i]) i++;
   return(i);
}
Finally, the code to close the "worst" open trade. This is likely equivalent to closing the last trade, but just in case....

Code: Select all

void CloseWorstTrade() {

//find worst performing trade
      int total = OrdersTotal();
      int worst = 0;
      double worst_profit = 10000000;
      for (i=0;i<total;i++)
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if (OrderType() != OP_BUY  && OrderType() != OP_SELL) continue;
            if (OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() != Symbol()) continue;
            if (OrderProfit()< worst_profit) {
               worst = OrderTicket();
               worst_profit = OrderProfit();
            }//if (OrderProfit()< worst_profit) 
         }//if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 

//close worst trade
      bool result = CloseTrade(worst);
      //Actions when trade close succeeds
      if (result)
      {
         DeletePendingPriceLines();
         TicketNo = -1;//TicketNo is the most recently trade opened, so this might need editing in a multi-trade EA
         OpenTrades--;//Rather than OpenTrades = 0 to cater for multi-trade EA's
      }//if (result)
}
The close part of the code was lifted from LookForTradeClosure(). I agree with your TicketNo comment, but not sure what to do about it here.

As I like to say, you can learn from good examples as well as bad, so hopefully this will give you a headstart on the rest of the bot, one way or the other. ;)

George
Where you stick it matters not :D, where you call it does!

Code: Select all

datetime       LastBar;//for testing for a new Bar

bool newbar()
{
if (Time[0] > LastBar) 
{
LastBar = Time[0];
return(True);
}
return(False);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----
   //Look for trade cloures at beginning of bar only
   if(newbar())
   {
   StrategyLookForTradeClosure();
   }
Still not checked but hopefully checkable!
andydoc
Trader
Posts: 53
Joined: Sun Dec 11, 2011 8:26 am
Location: West Brom, UK

Re: Joe. Swing-trade your way to a baby equity millipede

Post by andydoc »

Started backtesting - not stacking yet! About to look into why...
andydoc
Trader
Posts: 53
Joined: Sun Dec 11, 2011 8:26 am
Location: West Brom, UK

Re: Joe. Swing-trade your way to a baby equity millipede

Post by andydoc »

Just saw your post about adding the stacking back in duh! lol.
In terms of which trades to close, on the 50% cull on momentum weakening, it is sensible to close the best trades. My reasoning for this is that there is no methodology for either moving the stoploss to better than BE, nor for closing the remaining 50% on a reversal. The rules suggest that we would therefore close successive 50%s on Up candles, until either we had one left - which would close, or all BE SLs had been exhausted. This would therefore mean if we closed the best trades we would leave less on the table to give back.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Joe. Swing-trade your way to a baby equity millipede

Post by gaheitman »

andydoc wrote:Just saw your post about adding the stacking back in duh! lol.
In terms of which trades to close, on the 50% cull on momentum weakening, it is sensible to close the best trades. My reasoning for this is that there is no methodology for either moving the stoploss to better than BE, nor for closing the remaining 50% on a reversal. The rules suggest that we would therefore close successive 50%s on Up candles, until either we had one left - which would close, or all BE SLs had been exhausted. This would therefore mean if we closed the best trades we would leave less on the table to give back.
The code I posted is easy to change into CloseBestTrade() so that we can compare the two. I was thinking the same way as you when I was writing it. From the strategy, it seemed to suggest that even after closing half the trades he was still ready to stack on more in the original direction. If we're doing that, I'd think we'd want the better positions to remain open to give you the confidence to continue to stack. We should code for both and let ST decide... :D
Post Reply

Return to “Automated trading systems”