stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

HGB's Candle Power multi-pair combined trader and dashboard
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5324
Page 8 of 10
Author:  dreambig2 [ Tue Dec 05, 2017 11:33 am ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

pandaboy » Fri Nov 17, 2017 1:08 pm wrote:I am testing H4 with Leon's settings.. SL 25.. TP is open.. BE at 50.. JS 10.. looks promising. made 820 pips and closed everything manually.. just 2 days though.. will run it for few weeks and see the results.
Thank You Leon and Steve.. :hi:
Hi Pandaboy,

Are you closing at the end of each 4 hour cycle or are you closing at the end of the trading day?
I have started a set and have several trades already well into profit into my first 4 hours.

I also loaded Leons Strict daily before London open last night and see no pending or trades but I think trades and pendings come at end of day/beginning of new day if I understand correctly.

thx
db
Author:  eRIKb81 [ Tue Dec 05, 2017 7:03 pm ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

The whole-basket-close still is not working. It closed only the last ticket with the right magic number, in this case 1 out of 4 orders.

Tried it again when the basket was in profit, this time no orders got closed. This makes me think something goes wrong in CountOpenTrades(string symbol, int PairIndex).

Perhaps the block at line 1728 "//Whole position monitor if TradeWholePositionAsBasket is enabled" should be moved the the position after the "//Ensure the EA 'owns' this trade" block?

I haven't done any programming in ages, but I hope I narrowed it down.

The good news is that there was profit today!
Author:  SteveHopwood [ Tue Dec 05, 2017 8:09 pm ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

eRIKb81 » Tue Dec 05, 2017 7:03 pm wrote: I haven't done any programming in ages, but I hope I narrowed it down.
You have indeed. Thanks for sticking with this. Your solution of mucking around with CountOpenTrades() was so clearly wrong that it sent me looking elsewhere. The culprit was within void CloseAllTradesBelongingToEA(), which was closing only those trades held within the FifoTicket array. Only those trades belonging to the currently selected symbol would be held in this array.

Peasants, my latest attempted fix is in post 1 - V 1k.

Classy people, compare the new function with the existing one:

Code: Select all

void CloseAllTradesBelongingToEA()
{

   WholePositionForceTradeClosure = false;
   
   if (OrdersTotal() == 0) return;
   
   bool result = false;
   for (int pass = 0; pass <= 1; pass++)
   {
      if (OrdersTotal() == 0 || OpenTrades == 0)
         break;
      for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
      {
         if (!BetterOrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
         if (OrderMagicNumber() != MagicNumber) continue;
         
         while(IsTradeContextBusy()) Sleep(100);
         if (OrderType() < 2)
         {
            result = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, CLR_NONE);
            if (result) 
            {
               cc++;
               OpenTrades--;
            }//(result) 
            
            if (!result) ForceTradeClosure= true;
         }//if (OrderType() < 2)
         
         if (pass == 1)
            if (OrderType() > 1) 
            {
               result = OrderDelete(OrderTicket(), clrNONE);
               if (result) 
               {
                  cc++;
                  OpenTrades--;
               }//(result) 
               if (!result) WholePositionForceTradeClosure = true;
            }//if (OrderType() > 1) 
            
      }//for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
   }//for (int pass = 0; pass <= 1; pass++)
   
   //If full closure succeeded, then allow new trading
   if (!WholePositionForceTradeClosure) 
   {
      OpenTrades = 0;
      BuyOpen = false;
      SellOpen = false;
   }//if (!ForceTradeClosure) 


}//End void CloseAllTradesBelongingToEA()
This code examines every open trade and only rejects those that have the wrong magic number.

Poor Relations in the US: this basket closure is still available to you, I think, despite your government's ludicrous FIFO rules. Every time a trade closure fails, it will set the WholePositionForceTradeClosure flag which in turn tells the bot to keep on trying to close trades. They will all close eventually. This might take a while. I suggest revolution and an overthrow of your government.

:xm:
Author:  dreambig2 [ Tue Dec 05, 2017 8:43 pm ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

:smile: The H4 set I'm using got up to +$200 so I closed when down to +$100. Glad I did the second 4 hour cycle went south.
I did notice that old pendings were not being closed thus price was triggering these trades which appears contributing to the negative trades. Pretty sure these should have closed. Resetting platform and reloading set will see how goes next 4 hours.

db
Author:  eRIKb81 [ Tue Dec 05, 2017 8:55 pm ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

Minibloop: you forgot to replace 'ForceTradeClosure' with 'WholePositionForceTradeClosure' in pass 0.

Waiting for a profitable basket to test again :).
Author:  SteveHopwood [ Tue Dec 05, 2017 10:04 pm ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

eRIKb81 » Tue Dec 05, 2017 8:55 pm wrote:Minibloop: you forgot to replace 'ForceTradeClosure' with 'WholePositionForceTradeClosure' in pass 0.

Waiting for a profitable basket to test again :).
Nice spot. Thanks. :clap: :clap: :clap: :clap: Fix in post 1.

Classy people, go to void CloseAllTradesBelongingToEA() and find ForceTradeClosure; replace it with WholePositionForceTradeClosure. It will be around about line 3823 depending on how many of the updates you have been superbly crafting for yourselves. The offending line is:
if (!result) ForceTradeClosure= true;

and should be:
if (!result) WholePositionForceTradeClosure = true;

:xm:
Author:  eRIKb81 [ Wed Dec 06, 2017 10:27 am ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

The cashUPL calculation still counted all the trades from all the magic numbers. I moved the block@1728 for "//Whole position monitor if TradeWholePositionAsBasket is enabled" to after the "//All conditions passed, so carry on" block, like i tried yesterday.

It worked, cashUPL display in Empty4 works now, it was higher than the profit target, only the right positions got closed. Profitable basket closed.

EDIT: Ignore the sum at the end, that's just the daily balance.
EDIT2: The Cash UPL display somehow is not working for every EA, moving the block back to it's original place and adding "if (OrderMagicNumber() != MagicNumber) continue;" worked better.
Author:  SteveHopwood [ Wed Dec 06, 2017 10:48 am ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

eRIKb81 » Wed Dec 06, 2017 10:27 am wrote:The cashUPL calculation still counted all the trades from all the magic numbers. I moved the block@1728 for "//Whole position monitor if TradeWholePositionAsBasket is enabled" to after the "//All conditions passed, so carry on" block, like i tried yesterday.

It worked, cashUPL display in Empty4 works now, it was higher than the profit target, only the right positions got closed. Profitable basket closed.

EDIT: Ignore the sum at the end, that's just the daily balance.
Thanks again Eric. :clap: :clap:

The Peasants' fix is V 1l in post 1.

Members of the Nobility, do a search for "//Whole position monitor if TradeWholePositionAsBasket is enabled" and copy this over the top of the code block:

Code: Select all

      //Whole position monitor if TradeWholePositionAsBasket is enabled
      double pips = 0;
      if (TradeWholePositionAsBasket)
         if (OrderMagicNumber() == MagicNumber)
            if (OrderType() < 2)
            {
               WholePositionCashUpl+= (OrderProfit() + OrderSwap() + OrderCommission());
               pips = CalculateTradeProfitInPips(OrderType());
               WholePositionPipsUpl+= pips;
            }//if (OrderType() < 2)
 
I have added the extra conditional if (OrderMagicNumber() == MagicNumber). This is a little bit of future-proofing in case people decide they want to treat all open trades on the platform as basket members regardless of their origin. I can change the code to be:
if (OrderMagicNumber() == MagicNumber || IgnoreMagicNumbers) if anybody wants this feature.

:xm:
Author:  Barcode [ Thu Dec 14, 2017 3:48 am ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

Steve,

What the chance of getting an option added to the EA that writes the reason for the trade closure to the TradeComment. At present I am never quite sure why the trade closed.

This should be a big help for tuning the EA.

Bob
Author:  renexxxx [ Thu Dec 14, 2017 4:31 am ]
Post subject:  HGB's Candle Power multi-pair combined trader and dashboard

Barcode » Thu Dec 14, 2017 1:48 pm wrote: What the chance of getting an option added to the EA that writes the reason for the trade closure to the TradeComment.
The chance for that is 0.0%. The TradeComment field is set at the time the trade is opened and it can not be altered through code.

R.
All times are UTC Page 8 of 10