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

Slopey Peaky Bob
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5389
Page 12 of 84
Author:  Zennor [ Sun May 20, 2018 6:46 am ]
Post subject:  Slopey Peaky Bob

Steve that is a great idea, regarding my recent trading I had thought that the TP should be proportional to the lot size hence the reason for my increase to see if the risk/reward was a viable option.

I was also considering the fact that trading possibly so many pairs the chicken route as you call it certainly has its merits if you want a stress free life. So I'm now looking at the viability of trading fewer but uncorrelated pairs with a higher lot size so say if the USD heads south it only does it on one pair or two pairs at most and not a host of pairs. Still tinkering with this idea at the moment.
Author:  SteveHopwood [ Sun May 20, 2018 10:07 am ]
Post subject:  Slopey Peaky Bob

Preparing this post highlighted a bloop that means that SPB will use the dynamic lot size calculation whether you want him to or not, so please re-download 1i.

I forgot to explain 1i for the DIY enthusiasts, so here goes:

Do a search for "void AutoTrading()" and add this function directly above:

Code: Select all

void CalculateDynamicBasketCashTP()
{

   //Calculates a basket cash TB calculated by lot size
   
   BasketTargetCash = NormalizeDouble(CashTakeProfitPerLot * Lot, 2);

}//End void CalculateDynamicBasketCashTP()
The top block of code inside the "void AutoTrading()" function ends with this bracket and comment:
"}//if (ForceWholePositionClosure)". Insert this code block underneath:

Code: Select all

   //Dynamic basket TP applied to a fixed lot size
   if (CloseEnough(LotsPerDollopOfCash, 0))
      if (CloseEnough(RiskPercent, 0))
         CalculateDynamicBasketCashTP();
Do a search for "extern double BasketTargetCash=0;" and add this underneath:

Code: Select all

extern string  dbt="-- Dynamic basket take profit --";
//Basket cash TP based on lot size
extern bool    UseDynamicCashTP=true;
extern double  CashTakeProfitPerLot=3000;
Do a search for "int OnInit()" and scroll down to "//Lot size based on account size" and add this underneath:

Code: Select all

   //Dynamic basket TP applied to a fixed lot size
   if (CloseEnough(LotsPerDollopOfCash, 0))
      if (CloseEnough(RiskPercent, 0))
         CalculateDynamicBasketCashTP();
Do a search for "SM("Click a pair to open its chart, the table name to switch between views, the headers to show/hide details, the labels at the bottom to let them do what they offer."+NL);" and add the TP display code directly above:

Code: Select all

   if (TreatAllPairsAsBasket)
      SM("Lot size = " + DoubleToStr(Lot, 2) + ": Basket cash take profit = " + AccountCurrency() + " " + DoubleToStr(BasketTargetCash, 2) + NL);
Do a search for "double CalculateLotSize(string symbol, double price1,double price2)" to take you to the RiskPercent based lot calculation, scroll down to "return(LotSize);" and insert this code directly above:

Code: Select all

   //Dynamic basket take profit
   if (TreatAllPairsAsBasket)
      if (UseDynamicCashTP)
         CalculateDynamicBasketCashTP();
  
Do a search for "void CalculateLotAsAmountPerCashDollops()" to take you to the LotsPerDollop based lot calculation and add this to the end of the function, underneath "Lot = minlot;":

Code: Select all

   //Dynamic basket take profit
   if (TreatAllPairsAsBasket)
      if (UseDynamicCashTP)
         CalculateDynamicBasketCashTP();
  
:xm: :rocket:
Author:  woodlands [ Sun May 20, 2018 1:02 pm ]
Post subject:  Slopey Peaky Bob

I have been away for some weeks and left SPB unattended on the (Eaymon) VPS and now catching up
My £2 profit/ M5 setup hasn't worked out..... :oops:

Both these have been running without intervention for 8 weeks
SPB_M5_wk_8.png

But the 'normal' £30 / H4 is looking after itself fine..... :smile:
SPB_H4_wk_8.png
This includes the TCRSS tests which are still above water
Author:  1of3 [ Mon May 21, 2018 3:13 pm ]
Post subject:  Slopey Peaky Bob

Hi Steve,

I found a bug in the AutoTrading function.

You need to change the following code (that's just under the ForceWholePositionClosure function)

Code: Select all

   //Dynamic basket TP applied to a fixed lot size
   if (CloseEnough(LotsPerDollopOfCash, 0))
      if (CloseEnough(RiskPercent, 0))
         CalculateDynamicBasketCashTP();
to this.

Code: Select all

   //Dynamic basket TP applied to a fixed lot size
   if (UseDynamicCashTP)
   if (CloseEnough(LotsPerDollopOfCash, 0))
      if (CloseEnough(RiskPercent, 0))
         CalculateDynamicBasketCashTP();
Otherwise it will always auto calculate the CashTake Profit.

Thank you for this wonderful EA.

John
Author:  SteveHopwood [ Mon May 21, 2018 3:38 pm ]
Post subject:  Slopey Peaky Bob

1of3 » Mon May 21, 2018 3:13 pm wrote:Hi Steve,

I found a bug in the AutoTrading function.

You need to change the following code (that's just under the ForceWholePositionClosure function)

Code: Select all

   //Dynamic basket TP applied to a fixed lot size
   if (CloseEnough(LotsPerDollopOfCash, 0))
      if (CloseEnough(RiskPercent, 0))
         CalculateDynamicBasketCashTP();
to this.

Code: Select all

   //Dynamic basket TP applied to a fixed lot size
   if (UseDynamicCashTP)
   if (CloseEnough(LotsPerDollopOfCash, 0))
      if (CloseEnough(RiskPercent, 0))
         CalculateDynamicBasketCashTP();
Otherwise it will always auto calculate the CashTake Profit.

Thank you for this wonderful EA.

John
Thanks John. I added the extra line in On Init() but forgot here.

I will post the fix later folks. Lucky64 sent me the code to add this feature to the individual pair baskets, so I will release the fix at the same time - just got a few lines to add to the user guide first. DIYers, this is an easy fix: start at the top of the code and do a search for "//Dynamic basket TP applied to a fixed lot size". There are two of them and the second one needs the line of code adding that John mentions.

:xm: :rocket:
Author:  SteveHopwood [ Mon May 21, 2018 4:03 pm ]
Post subject:  Slopey Peaky Bob

V 1j is in post 1; this includes John's fix in my previous post.

Luciano (Lucky64) sent me the code that allows SPB to calculate a dynamic TP for single pair baskets. Nice one Luciano. :clap: :clap: :clap: :clap: :clap: :clap: :clap:

I have updated the user guide but you only need it if you are new to all this. The inputs in the "Individual pairs" basket inputs are obvious and work in the same way as for whole position basket trading.

Three steps for DIY:
Do a search for "extern double IndividualBasketTargetCash" (clear the "Match whole word only" tickbox). Insert this code directly underneath:

Code: Select all

extern string  dbi="-- Dynamic individual pair basket take profit --";
//Individual Pair Basket cash TP based on lot size. Lucky64 added this function. Many thanks Luciano.
extern bool    UseDynamicCashTPIndividualPair=true;
extern double  CashTakeProfitIndividualePairPerLot=1000;
Do a search for "SM("Lot size = " + DoubleToStr(Lot, 2)". This will take you to the chart display. The existing code is:

Code: Select all

if (TreatAllPairsAsBasket)
     SM("Lot size = " + DoubleToStr(Lot, 2) + ": Basket cash take profit = " + AccountCurrency() + " " + DoubleToStr(BasketTargetCash, 2) + NL);
   
Delete it and replace it with this block:

Code: Select all

   string sizingInfo = "Lot size = " + DoubleToStr(Lot, 2);
   if (TreatIndividualPairsAsBasket) 
   {
      if (UseDynamicCashTPIndividualPair) 
      {
         IndividualBasketTargetCash = NormalizeDouble(CashTakeProfitIndividualePairPerLot * Lot, 2);
      } // if (UseDynamicCashTPIndividualPair) 
      sizingInfo += " , Individual pair basket cash take profit = " + AccountCurrency() + " " + DoubleToStr(IndividualBasketTargetCash, 2);
   }//if (TreatIndividualPairsAsBasket) 
   
   if (TreatAllPairsAsBasket)
      sizingInfo +=  " , Basket cash take profit = " + AccountCurrency() + " " + DoubleToStr(BasketTargetCash, 2) ;
   
   SM(sizingInfo + NL);
   
Do a search for "bool CanIndividualPairBasketBeClosed(string symbol, int PairIndex)" and scroll down to, "//Cash target" - the second code block. Delete the whole block and replace it with:

Code: Select all

   //Cash target
   if (!CloseEnough(IndividualBasketTargetCash,0) )
   {
      if (UseDynamicCashTPIndividualPair) 
      {
         IndividualBasketTargetCash = NormalizeDouble(CashTakeProfitIndividualePairPerLot * Lot, 2);
      } // if (UseDynamicCashTPIndividualPair) 
      if (CashUpl[PairIndex] >= IndividualBasketTargetCash)
      {
         CloseAllTrades(symbol, AllTrades);
         if (ForceTradeClosure)
         {
            CloseAllTrades(symbol, AllTrades);
            if (ForceTradeClosure)
            {
               CloseAllTrades(symbol, AllTrades);
               if (ForceTradeClosure)
               {
                  return(false);
               }//if (ForceTradeClosure)                     
            }//if (ForceTradeClosure)         
         }//if (ForceTradeClosure)    
         
         if (!ForceTradeClosure)
            return(true);//Closure target reached and closure successful
      }//if (CashUpl[PairIndex] >= IndividualBasketTargetCash)
   }//if (!CloseEnough(IndividualBasketTargetCash,0) )
   
:xm: :rocket:
Author:  4xtn [ Mon May 21, 2018 10:31 pm ]
Post subject:  Slopey Peaky Bob

Hi there

Anyone else is having pending orders cancelled and sent over & over again with 'DeletePendingsOnOppositeColour=true? AUDCHF pair @ H1 Peaky|D1 SS?
Author:  SteveHopwood [ Mon May 21, 2018 11:08 pm ]
Post subject:  Slopey Peaky Bob

4xtn » Mon May 21, 2018 10:31 pm wrote:Hi there

Anyone else is having pending orders cancelled and sent over & over again with 'DeletePendingsOnOppositeColour=true? AUDCHF pair @ H1 Peaky|D1 SS?
I cannot find this variable.

:xm: :rocket:
Author:  Peepaws [ Tue May 22, 2018 5:25 pm ]
Post subject:  Slopey Peaky Bob

The c. $130 DD disappeared within a hour or so when the markets finally moved back in the right direction. I have noticed that a basket closes rapidly when this happens - it can go from DD to TP within minutes. I am wondering if I am leaving too much on the table with my TP - is anyone here demoing a much higher one?

Looking good.

:xm: :rocket:

Steve, I have been trading a live account with a 500 pip basket TP for a month or so with very good results so far.

I have split my account into 3 smaller accounts to test 100 pip, 200 pip and 500 pip baskets. I am just waiting for Myfxbook to verify the new accounts before I can make them public.

I will post myfxbook links as soon as possible.
Author:  SteveHopwood [ Wed May 23, 2018 10:07 am ]
Post subject:  Slopey Peaky Bob

V 1k is in post 1. Radar emailed to say that the dynamic whole-position basket TP was not updating. I saw loads wrong with the code when I looked, so 1k is attempting to fix this. You do not need the update if you are not basket trading.

The DIY is relatively simple. Do a search for "void CalculateDynamicBasketCashTP()" and replace it with:
void CalculateDynamicBasketCashTP(double lots)

Doing a recompile will highlight a lot of errors; ignore them for now.

Go to the top of the file and do a 'Match whole word only' for "UseDynamicCashTP". The first one will take you to the variable declaration; leave that alone.

Repeat the search. It will take you to a code block in int OnInit(). Replace the block with this:

Code: Select all

   //Calculate a dynamic whole basket TP for initial display
   if (UseDynamicCashTP)
   {
      //Applied to a fixed lot size
      if (CloseEnough(LotsPerDollopOfCash, 0))
         if (CloseEnough(RiskPercent, 0))
            CalculateDynamicBasketCashTP(Lot);
   
      //LotsPerDollop
      if (!CloseEnough(LotsPerDollopOfCash, 0))
      {
         CalculateLotAsAmountPerCashDollops();
         CalculateDynamicBasketCashTP(Lot);
      }//if (!CloseEnough(LotsPerDollopOfCash, 0))
         
      //RiskPercent   
      if (!CloseEnough(RiskPercent, 0))
      {
         //Simulate a trade to calculate the lot size for a RiskPercent-based trade.
         double stop = 0, price = 0;
         string symbol = TradePair[0];
         price = MarketInfo(symbol, MODE_ASK);
         stop = CalculateStopLoss(OP_BUY, price);
         double SendLots = CalculateLotSize(symbol, price, stop);
      
         CalculateDynamicBasketCashTP(SendLots);
      
      }//if (!CloseEnough(RiskPercent, 0))
      
      
   }//if (UseDynamicCashTP)
    
Repeat the search twice more, ignoring the code each time.

Repeat the search a third time and you will find yourself in void Autotrading(). Replace the code block with the one you just copied into int OnInit().

Press the F7 key to recompile. There will be two wrong parameters count errors. Double click the first one to be taken to the first error. The code is " CalculateDynamicBasketCashTP();". Replace it with:
CalculateDynamicBasketCashTP(LotSize);

Re-compile and there will be one error left. Navigate to it and replace "CalculateDynamicBasketCashTP();" with:
CalculateDynamicBasketCashTP(Lot);

:xm: :rocket:
All times are UTC Page 12 of 84