Griddy Wotsit Mk 2

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

Griddy Wotsit Mk 2

Post by SteveHopwood »

V 1b is in post 1. The pending trade filling in code only worked when the market has risen and there are more buys open than sells. The opposite needs catering for as well.

waltini1 send me a doc with some useful information about grids in it. The doc is an FAQ about an EA available some years ago and so is mostly irrelevant, but this looks good to take note of:
  • Small step size to profit on the smallest moves. Consider this when selecting a step
    size. A 2-pip step size grid will be twice as wide as a 1-pip step size grid. While the
    profits will come more slowly, the price will stay in the grid much longer with a smaller
    drawdown.
  • Small take profit targets to maximize the number of completed trades with minimal
    market movement. If the take profit is set to 6, and assuming $0.10 per pip and step
    size of one, there will be six closed orders for $3 profit in a 10-pip move. A take profit
    of 10 will return only $1.
  • Low interest currency pair to minimize interest losses on rollover. Choose a currency with low interest charges.
  • Strong volatility within a range.
  • High Pip value.
It is not a cheap way to trade, but it is good fun. Try the attached set file on EU. 10 trades in both directions; 2 pips apart; 2 pips tp; hedge tp 10 pips; max distance between buys and sells is 30 pips.

Save your cpu some pain. Open one chart for trading and a second for TradeReport. Then drag the SelectMarketSymbols script onto a chart, setting IncludeSymbols to a blank space. The script will close down all but the two charts you have open and the platform will no longer have to process ticks for every pair.

To add charts back in, right click in the Market Watch window and click Show All. Open the charts you want then run the script again.

:xm:
You do not have the required permissions to view the files attached to this post.
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.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Griddy Wotsit Mk 2

Post by SteveHopwood »

Try it on GJ - really good fun today.

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

Griddy Wotsit Mk 2

Post by SteveHopwood »

V 1c is in post 1. I have had a lot of fun playing with this today. The ea froze on me, just as it did in craptesting, so I went bug hunting.

All that was needed was a couple more calls to CountOpenTrades() from within ShouldTradesBeClosed() to re-populate the variables that keep track of the position. Coders will spot them immediately.

If you want to make the changes yourselves but are not confident, then the easiest way to to find ShouldTradesBeClosed() at line 1100 and copy this over the top of the existing code:

Code: Select all

void ShouldTradesBeClosed()
{
   
   if (OpenTrades == 0)
      return;//Nothing to do

   int tries = 0;

   //We only want trades closing if the trades are based on a previous candle's signal
   if (LatestTradeTime < iTime(Symbol(), TradingTimeFrame, 0) )
   {
      
      //Opposite direction semafor
      if (CloseTradesOnRelevantSemafor)
      {
         //Close buys
                  
         if (SemStatus == highsemafor)
         {
            tries = 0;
            //Close buys
            if (BuyOpen)
            {
               ForceTradeClosure = true;
               while (ForceTradeClosure)
               {
                  CloseAllTrades(OP_BUY);
                  CloseAllTrades(OP_BUYSTOP);
                  CloseAllTrades(OP_SELLSTOP);//Forces a regrid closer to the market
                  if (ForceTradeClosure)
                     Sleep(1000);
                  tries++;
                  if (tries >= 100)
                  {
                     ForceTradeClosure = false;
                     break;
                  }//if (tries >= 100)
               }//while (ForceTradeClosure)
            
               SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
         
               return;//Nothing more for this function to do
            }//if (BuyOpen)
         }//if (SemStatus == highsemafor)
         
         if (SemStatus == lowsemafor)
         {        
            tries = 0;
            //Close sells
            if (SellOpen)
            {
               ForceTradeClosure = true;
               while (ForceTradeClosure)
               {
                  CloseAllTrades(OP_SELL);
                  CloseAllTrades(OP_SELLSTOP);
                  CloseAllTrades(OP_BUYSTOP);//Forces a regrid closer to the market
                  if (ForceTradeClosure)
                     Sleep(1000);
                  tries++;
                  if (tries >= 100)
                  {
                     ForceTradeClosure = false;
                     break;
                  }//if (tries >= 100)
               }//while (ForceTradeClosure)
              
              SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
    
              return;//Nothing more for this function to do
                  
            }//if (SellOpen)              
         }//if (SemStatus == lowsemafor)         
     }//if (CloseTradesOnRelevantSemafor)
      

   }//if (LatestTradeTime < iTime(Symbol(), TradingTimeFrame, 0) )

   //Hedged position. Has it hit tp?
   if (Hedged)
   {
      bool ClosePosition = false;
      
      //Have we hit pips upl
      if (HedgeProfitPips > 0)
         if (PipsUpl >= HedgeProfitPips)
            ClosePosition = true;
            
      //Have we hit cash upl
      if (!ClosePosition)   
         if (HedgeProfitCash > 0)
            if (CashUpl >= HedgeProfitCash)
               ClosePosition = true;
               
      if (ClosePosition)
      {
         tries = 0;
         ForceTradeClosure = true;
         while(ForceTradeClosure)
         {
            ForceTradeClosure = false;
            if (BuyOpen)
               CloseAllTrades(OP_BUY);
            if (SellOpen)
               CloseAllTrades(OP_SELL);   
            if (SellStopOpen)
               CloseAllTrades(OP_SELLSTOP);
            if (SellLimitOpen)
               CloseAllTrades(OP_SELLLIMIT);
            if (BuyStopOpen)
               CloseAllTrades(OP_BUYSTOP);
            if (BuyLimitOpen)
               CloseAllTrades(OP_BUYLIMIT);   
               
            tries++;
            if (tries >= 100)
            {
               break;
            }//if (tries >= 100)
            CountOpenTrades();//Recalculate the position
         }//while(ForceTradeClosure)
         
         return;//Nothing else to do
      }//if (ClosePosition)
            
      //Successive waves of group trade closures can leave a massive gap in between
      //groups of market trades. Deal with this situation by setting up a new grid
      //of pendings closer to the market.
      if (IsGapBetweenGroupsTooBig() )
      {
         //No need to try to force trade deletions as subsequent ticks will
         //repeat this process if necessary.
         ForceTradeClosure = false;
         CloseAllTrades(OP_BUYSTOP);
         CloseAllTrades(OP_SELLSTOP);
         if (!ForceTradeClosure)
         {
            SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
            SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
            return;
         }//if (!ForceTradeClosure)
         
         CountOpenTrades();
      }//if (IsGapBetweenGroupsTooBig() )
      
   }//if (Hedged)
      
   
   //We always want a grid of GridSize * 2 stop orders, so do a delete and resend when a trade fills
   if (BuyStops <= 1)
   {
      ForceTradeClosure = true;
      while(ForceTradeClosure)
      {
         tries = 0;
         ForceTradeClosure = false;
         CloseAllTrades(OP_BUYSTOP);
         if (ReplaceOppositeGridAtL4)
            CloseAllTrades(OP_SELLSTOP);
              
         tries++;
         if (tries >= 100)
         {
            ForceTradeClosure = false;
            break;
         }//if (tries >= 100)
     }//while(ForceTradeClosure) 
     SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
     if (ReplaceOppositeGridAtL4)
         SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
     CountOpenTrades();
     return;
   }//if (BuyStops < GridSize)
   
   if (SellStops <= 1)
   {
      ForceTradeClosure = true;
      while(ForceTradeClosure)
      {
         tries = 0;
         ForceTradeClosure = false;
         if (ReplaceOppositeGridAtL4)
            CloseAllTrades(OP_BUYSTOP);
         CloseAllTrades(OP_SELLSTOP);
              
         tries++;
         if (tries >= 100)
         {
            ForceTradeClosure = false;
            break;
         }//if (tries >= 100)
     }//while(ForceTradeClosure) 
     if (ReplaceOppositeGridAtL4)
         SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
     SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
     CountOpenTrades();
     
   }//if (BuyStops < GridSize)
   
   
}//void ShouldTradesBeClosed()
:xm:
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.
PhP71
Posts: 8
Joined: Thu Feb 02, 2012 6:37 pm
Location: Paris, France

Griddy Wotsit Mk 2

Post by PhP71 »

Hi Steve,

been busy at work these last few days but cleaned up my demo yesterday evening and started a fresh new one with your version 1c on different pairs.

I checked this morning the result over the night and I've been surprised on the behaviour of the tool.

I checked if I didn't missed something but couldn't find, nothing noticed in the journal log or elsewhere.

I am with default settings except for "MaxDistanceBetweenGroupsPips" where I set it to 25 so when a buy or sell trade close the opposite grid should logically close and re-open.

On AU going long (and EG as well going short) it doesn't seem to work
Capture03.PNG
and on NU as well but in the way they are getting too close
Capture04.PNG
Don't know if I really missed something or the tool still need debugging.

phil.
You do not have the required permissions to view the files attached to this post.
zaguy
Trader
Posts: 43
Joined: Wed Feb 03, 2016 7:42 am

Griddy Wotsit Mk 2

Post by zaguy »

Hello Steve. I was also playing around with this latest version and had great fun. Thank you!

I had an idea - and it pretty much follows from your Recovery EA of a few years ago. Maybe worthwhile to investigate? Here goes:

As you are aware, the leaky toilet thingy is still a problem. Example: Some buy trades and filled and suddenly the market trend downwards and fill all the sell trades and a new grid appears. However, the buy trades are still open and moves further and further away from the market eventually leading to a massive loss. (I am explaining for those who are new / following).

How about sending grids with higher lot sizes the further away the pending position is from the price action. Example: 1st pending position closest to the price action = 0.01 lots, 2nd position = 0.01 lots, 3rd position = 0.02 lots, 3rd position = 0.03 lots, 4th position = 0.04 lots etc. Say the same scenario as above plays out and all open trades are forced to close when (still using the same example as above) all pending sell orders are filled and profits taken. Such profits might be higher than the loss incurred from the 1 or 2 open buy trades. A "forcetradeclosure" for open trades thus needs to take place when all pending orders have been filled and profits taken in a certain direction (in this case the open sell orders). The following logical step would be to replace the winning grid.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Griddy Wotsit Mk 2

Post by SteveHopwood »

zaguy » Wed Mar 02, 2016 5:49 pm wrote: How about sending grids with higher lot sizes the further away the pending position is from the price action. Example: 1st pending position closest to the price action = 0.01 lots, 2nd position = 0.01 lots, 3rd position = 0.02 lots, 3rd position = 0.03 lots, 4th position = 0.04 lots etc. Say the same scenario as above plays out and all open trades are forced to close when (still using the same example as above) all pending sell orders are filled and profits taken. Such profits might be higher than the loss incurred from the 1 or 2 open buy trades. A "forcetradeclosure" for open trades thus needs to take place when all pending orders have been filled and profits taken in a certain direction (in this case the open sell orders). The following logical step would be to replace the winning grid.
Strange, isn't it? This bot was supposed to be a toy for entertainment but there is something about it....

Leave this with me. I love the idea; the code needs some thinking about.

:xm:
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.
User avatar
Gertje
Trader
Posts: 1936
Joined: Mon Dec 12, 2011 1:17 pm
Location: Middle of the Netherlands

Griddy Wotsit Mk 2

Post by Gertje »

SteveHopwood » Wed Mar 02, 2016 7:34 pm wrote:
zaguy » Wed Mar 02, 2016 5:49 pm wrote: How about sending grids with higher lot sizes the further away the pending position is from the price action. Example: 1st pending position closest to the price action = 0.01 lots, 2nd position = 0.01 lots, 3rd position = 0.02 lots, 3rd position = 0.03 lots, 4th position = 0.04 lots etc. Say the same scenario as above plays out and all open trades are forced to close when (still using the same example as above) all pending sell orders are filled and profits taken. Such profits might be higher than the loss incurred from the 1 or 2 open buy trades. A "forcetradeclosure" for open trades thus needs to take place when all pending orders have been filled and profits taken in a certain direction (in this case the open sell orders). The following logical step would be to replace the winning grid.
Strange, isn't it? This bot was supposed to be a toy for entertainment but there is something about it....

Leave this with me. I love the idea; the code needs some thinking about.

:xm:
I believe it's an accountkiller to add variable lotsizes, it going to be Martingale in a different suit.
The EA is capable of opening a huge amount of trades before closing the basket. Adding higher lots is draining the margin for small gain.

I added the "10.7 line of zero" from Bob to the chart, to be visible able to see where the basket will close for the defined amount of pips/ $. Baskets of over 100 orders have been seen, consuming all the profit with the provision. There is no way of telling beforehand how many orders will be in the basket, and set the basketdetails [close at #pips or #$] likewise.

My idea; is it possible to make the TP/ basketclosure settings floating with the number of orders? This could be done using the 'point of zero' where all orders together are at breakeven and close x-amount of pips beyond that value.

In the example below, there are 10 orders. The 'line of zero' is at 1.08462 and I added a line at 1.08432 to make it visible where the 3pips TP will be. In this case, the basket will open some more sells before reaching the closure line, and closing at 5-6 times 3pips. In the 'line of zero', swap and commission is already accounted for.
EURUSDM5.png
You do not have the required permissions to view the files attached to this post.
User avatar
Gertje
Trader
Posts: 1936
Joined: Mon Dec 12, 2011 1:17 pm
Location: Middle of the Netherlands

Griddy Wotsit Mk 2

Post by Gertje »

Attached the current situation for EURUSD;
EURUSDM5.png
Maybe a few moments until the basket closes.
You do not have the required permissions to view the files attached to this post.
User avatar
Gertje
Trader
Posts: 1936
Joined: Mon Dec 12, 2011 1:17 pm
Location: Middle of the Netherlands

Griddy Wotsit Mk 2

Post by Gertje »

Basket closed.
EURUSDM5.png
I changed the distance between trades and the TP to 3pips, to cater for the commission of 0.7pip.
.
You do not have the required permissions to view the files attached to this post.
PhP71
Posts: 8
Joined: Thu Feb 02, 2012 6:37 pm
Location: Paris, France

Griddy Wotsit Mk 2

Post by PhP71 »

One little correction to the code, nothing to see with this trading method but to have a proper display of the daily P/L (last line of the text displayed on the screen).

at line 1622 (inside CalculateDailyResult() function), I think it would be better to compare the OrderCloseTime to PERIOD_D1 instead of TradingTimeFrame (which is the current time frame of the window).

Also I'm not fan of the idea of martigaling the grid but I find Gertje idea interresting to close the hedge trading at breakeven + profit in case the trades last in time and the simple profit could be eated by the swap.

Phil.
Post Reply

Return to “Automated trading systems”