Here's the changes I made on my end, hope they're useful! If there's anything incorrect or that could have been done better please let me know
firstly there's changes to function calls in start()...
Code: Select all
stop = CalculateStopLoss(CurrentPair, OP_BUY, price);
take = CalculateTakeProfit(CurrentPair, OP_BUY, price);
Do the same for sells as well, with OP_SELL of course. Now for the functions themselves:-
Code: Select all
double CalculateStopLoss(string symbol, int type, double entry) {
// askPrice and bidPrice no longer needed as we're using the real entry value
// double askPrice = MarketInfo(symbol, MODE_ASK);
// double bidPrice = MarketInfo(symbol, MODE_BID);
double stop, price = entry;
RefreshRates();
if (type == OP_BUY) {
//price = askPrice;
if (!CloseEnough(stopLoss, 0)) {
stop = price - (stopLoss / factor);
}
if (UseMovingAverage)
stop = MaVal;
}
if (type == OP_SELL) {
//price = bidPrice;
if (!CloseEnough(stopLoss, 0)) {
stop = price + (stopLoss / factor);
}
if (UseMovingAverage)
stop = MaVal;
}
return(stop);
}
double CalculateTakeProfit(string symbol, int type, double entry) {
// again, no need for askPrice and bidPrice anymore
//double askPrice = MarketInfo(symbol, MODE_ASK);
//double bidPrice = MarketInfo(symbol, MODE_BID);
double take, price = entry;
RefreshRates();
if (type == OP_BUY) {
// make sure that take is incorrect to start with, that way we can be sure when
// we get a valid take value...
take = entry - 20 * Point;
if (!CloseEnough(takeProfit, 0)) {
take = price + (takeProfit / factor);
}
// note that below I set take to higher resistance levels even if the Use flag for them
// hasn't been set, but only if the desired resistance level is below our entry...
if (UseMidSR1)
take = MR1;
if (UseSR1 || take < entry)
take = R1;
if (UseMidSR2 || take < entry)
take = MR2;
if (UseSR2 || take < entry)
take = R2;
if (take < entry)
{
// still can't get a valid take value using the pivots, so I've defaulted
// to 2 * ATR as a placeholder to ensure we have something to use.
take = entry + iATR(symbol, PERIOD_H4, 20, 0)*2;
}
}
if (type == OP_SELL) {
take = entry + 20 * Point;
if (!CloseEnough(takeProfit, 0)) {
take = price - (takeProfit / factor);
}
if (UseMidSR1)
take = MS1;
if (UseSR1 || take > entry)
take = S1;
if (UseMidSR2 || take > entry)
take = MS2;
if (UseSR2 || take > entry)
take = S2;
if (take > entry)
take = entry - iATR(symbol, PERIOD_H4, 20, 0)*2;
}
return(take);
}
Btw another change I've made is to split the lotsize in half and enter twice, once with a TP and once without (I'll trail the market with the second order). I don't know if this is valid under 10.4 rules or would improve or harm its profitability, but its something I wanted to try. Its a simple change, can post it if anyone wants ... if it does prove useful perhaps its something Andy could add an option for in a future version?