Latest update in post 1.
I have added Michael's fix to allow risk-based lot sizes to half-close. Cheers Michael.
Can you do me a favour, please, and look at this snippet from void CaterpillarTrailingStop(int TradesToCheck)
Code: Select all
//Got this far, so Cat owns the trade and the stop needs moving.
//Calculate the shift back from current candle to the candle open time of the previous cts move
//Michael, can this little lot be replaced by iBarShift(NULL, CatTimeFrame, ctime, false);?
shift = 0;
ctime = GlobalVariableGet(CsGvName);
while (iTime(NULL, CatTimeFrame, shift) > ctime && shift < iBars(NULL, CatTimeFrame))//Can probably replace this with iBarShift
{
shift++;
}//while (iTime(NULL, CatTimeFrame, shift) > ctime && shift < iBars(NULL, CatTimeFrame
//Point to the next candls
shift--;
//This is an attempt to stop the final trade in the sequence having its stop moved too early, because
//this can result in it being stopped out as soon as it is opened
if (shift < 2) continue;
I coded this before discovering iBarShift. If UseCaterpillarTS is enabled, then CountOpenTrades creates a Global Variable with the ticket number turned into a string and used as the GV's name, and the order open price as its value.
The code snippet loops back to find the shift that is 1 bar to the right of the time saved in the GV. This time is updated later on if the stop loss is moved, so Graeme always needs to know the value of this changing shift.
I am reluctant to change this because it might be clumsy programming, but it aint actually broke. Can all this be easily replaced with shift = iBarShift(NULL, CatTimeFrame, ctime, false);?
If so, does ctime's (Candle Open Time) declaration need turning into a datetime?
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. 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.