Armen wrote:
Shouldn't that be if (PrevSlope != sell).
Yup. That was the bug I mentioned earlier.
maudur wrote:I think the correct code should be:
//Detect previous slope
if (ShelleyPlusGary)
{
double Slope = GetSlope(symbol, TimeFrame, 1);
string PrevSlope = nottradable;
if (Slope < 0.8 && Slope > 0) PrevSlope = buy;
if (Slope > -0.8 && Slope < 0) PrevSlope = sell;
}//if (ShelleyPlusGary)
Not quite -- as I understand it anyway, Slope should be >= 0.8 for a buy, <= -0.8 for a sell. But you ARE right that there's a bug in there that I didn't see before. Steve got the tests backwards: if (Slope < 0.8) PrevSlope = buy;
I'm now running with both these fixes. They didn't open up a dozen trades instantly, so that's a good sign. I'll let you know if it seems to work. Remember, though, I don't think it makes a lot of sense to trade this approach as a basket, so I'm not sure how well this is going to work.
Meanwhile if anybody else wants to test it, you can just replace LookForTradingOpportunities() with this code:
Code: Select all
void LookForTradingOpportunities()
{
BasketSent = true;
for (int cc = 0; cc < NoOfPairs; cc++)
{
string symbol = TradePair[cc][0];
if (DoesTradeExist(symbol) ) continue;//Only one trade per pair
double digits = MarketInfo(symbol, MODE_DIGITS);
double bid = NormalizeDouble(MarketInfo(symbol, MODE_BID), digits);
double ask = NormalizeDouble(MarketInfo(symbol, MODE_ASK), digits);
if (CloseEnough(bid, 0)) continue;//Pair not traded by the crim.
//Detect previous slope
if (ShelleyPlusGary)
{
double Slope = GetSlope(symbol, TimeFrame, 1);
string PrevSlope = nottradable;
if (Slope >= 0.8) PrevSlope = buy;
if (Slope <= -0.8) PrevSlope = sell;
}//if (ShelleyPlusGary)
bool SendLong = false, SendShort = false;
int type;
bool SendTrade = false;
//Slope must be buy and hold
if (TradePair[cc][1] == buyhold)
{
//Woh 2x1 must be >0
if (TradePair[cc][2] == buy)
//Trading styles
if (OriginalShelley)
{
if (IsShelleyTime) SendLong = true;
}//if (OriginalShelley)
//Additional condition: Slope(1) must have been < 0.8
if (ShelleyPlusGary)
{
if (PrevSlope != buy) SendLong = true;
}//if (ShelleyPlusGary)
}//if (TradePair[cc][3] == buyhold)
//Look for sell trades if there was no buy trigger
if (!SendLong)
{
//HTF sell and hold monthly pivot cross
//Find a monthly pivot cross. Both Woh's must be in the right direction.
if (TradePair[cc][1] == sellhold)
{
//Woh 2x1 must be <0
if (TradePair[cc][2] == sell)
{
//Trading styles
if (OriginalShelley)
{
if (IsShelleyTime) SendShort = true;
}//if (OriginalShelley)
//Additional condition: Slope(1) must have been > -0.8
if (ShelleyPlusGary)
{
if (PrevSlope != sell) SendShort = true;
}//if (ShelleyPlusGary)
}//if (TradePair[cc][2] == sell)
}//if (TradePair[cc][3] == sellhold)
}//if (!SendLong)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Trading
//Long
if (SendLong)
{
//Got this far, so there is going to be a trade send of some sort. Setting up price here makes
//this code most easily adaptable to easy alteration
type = OP_BUY;
SendTrade = true;
}//if (SendLong)
//Short
if (SendShort)
{
//Got this far, so there is going to be a trade send of some sort. Setting up price here makes
//this code most easily adaptable to easy alteration
type = OP_SELL;
SendTrade = true;
}//if (SendShort)
if (SendTrade)
{
bool result = SendSingleTrade(symbol, type, TradeComment, Lot, 0, 0);
}//if (SendTrade)
//Actions when trade send fails
if (SendTrade && !result)
{
BasketSent = false;
OldSgBarTime = 0;
}//if (!result)
}//for (int cc = 0; cc < NoOfPairs; cc++)
}//End void LookForTradingOpportunities()