DIYers, do a search for: if (!checkBuyOnlyPairs(symbol) )
Remove the "!" so that the code is:
if (checkBuyOnlyPairs(symbol) )
Code: Select all
void gridTradeDirectionBySwap(string symbol)
{
//There may be circumstances that I have not anticipated, where Desky is coded to send grids without
//checking the swap. I have added a call to this function to the top of SendBuyGrid() and SendSellGrid(),
//so this function allows/disallows the grid to be sent. It is the code higher up the function
buyGridAllowed = true;
sellGridAllowed = true;
GetBasics(symbol);
if (CadPairsPositiveOnly)
{
if (StringSubstrOld(symbol, 0, 3) == "CAD" || StringSubstrOld(symbol, 0, 3) == "cad" || StringSubstrOld(symbol, 3, 3) == "CAD" || StringSubstrOld(symbol, 3, 3) == "cad" )
{
if (longSwap < 0)
buyGridAllowed = false;
if (shortSwap < 0)
sellGridAllowed = false;
}//if (StringSubstrOld()
}//if (CadPairsPositiveOnly)
if (AudPairsPositiveOnly)
{
if (StringSubstrOld(symbol, 0, 3) == "AUD" || StringSubstrOld(symbol, 0, 3) == "aud" || StringSubstrOld(symbol, 3, 3) == "AUD" || StringSubstrOld(symbol, 3, 3) == "aud" )
{
if (longSwap < 0)
buyGridAllowed = false;
if (shortSwap < 0)
sellGridAllowed = false;
}//if (StringSubstrOld()
}//if (AudPairsPositiveOnly)
if (NzdPairsPositiveOnly)
{
if (StringSubstrOld(symbol, 0, 3) == "NZD" || StringSubstrOld(symbol, 0, 3) == "nzd" || StringSubstrOld(symbol, 3, 3) == "NZD" || StringSubstrOld(symbol, 3, 3) == "nzd" )
{
if (longSwap < 0)
buyGridAllowed = false;
if (shortSwap < 0)
sellGridAllowed = false;
}//if (StringSubstrOld()
}//if (AudPairsPositiveOnly)
//OnlyTradePositiveSwap filter
if (OnlyTradePositiveSwap)
{
if (longSwap < 0)
buyGridAllowed = false;
if (shortSwap < 0)
sellGridAllowed = false;
}//if (OnlyTradePositiveSwap)
//MaximumAcceptableNegativeSwap filter
if (longSwap < MaximumAcceptableNegativeSwap)
buyGridAllowed = false;
if (shortSwap < MaximumAcceptableNegativeSwap)
sellGridAllowed = false;
//Buy/sell only pairs.
//Must not be in the sell only list
if (checkSellOnlyPairs(symbol) )
buyGridAllowed = false;
//Must not be in the buy only list
if (checkBuyOnlyPairs(symbol) )
sellGridAllowed = false;
}//End void gridTradeDirectionBySwap(string symbol)
Code: Select all
//Swap check
gridTradeDirectionBySwap(symbol);
if (!buyGridAllowed)
return;
Code: Select all
//Swap check
gridTradeDirectionBySwap(symbol);
if (!sellGridAllowed)
return;
kwchau » Fri Apr 26, 2019 3:18 pm wrote:Hi Steve, I have tested the swap features of the latest version, everything seems running fine.
Thank you so much for fixing it !
cheers,
kwchau

Code: Select all
bool CloseEnough(double num1,double num2)
{
/*
This function addresses the problem of the way in which mql4 compares doubles. It often messes up the 8th
decimal point.
For example, if A = 1.5 and B = 1.5, then these numbers are clearly equal. Unseen by the coder, mql4 may
actually be giving B the value of 1.50000001, and so the variable are not equal, even though they are.
This nice little quirk explains some of the problems I have endured in the past when comparing doubles. This
is common to a lot of program languages, so watch out for it if you program elsewhere.
Gary (garyfritz) offered this solution, so our thanks to him.
*/
if(num1==0 && num2==0) return(true); //0==0
if(MathAbs(num1 - num2) / (MathAbs(num1) + MathAbs(num2)) < 0.00000001) return(true);
//Doubles are unequal
return(false);
}//End bool CloseEnough(double num1, double num2)
void tradeDirectionBySwap(string symbol)
{
//cancel a trade signal if the swap is negative and the user
//does not want to trade high swap pairs in the wrong direction.
//Also if the user does not want to trade negative swap at all.
getBasics(symbol);
if (CadPairsPositiveOnly)
{
if (stringSubstrOld(symbol, 0, 3) == "CAD" || stringSubstrOld(symbol, 0, 3) == "cad" || stringSubstrOld(symbol, 3, 3) == "CAD" || stringSubstrOld(symbol, 3, 3) == "cad" )
{
if (buySignal)
if (longSwap <= 0)
buySignal = false;
if (sellSignal)
if (shortSwap <= 0)
sellSignal = false;
}//if (stringSubstrOld()
}//if (CadPairsPositiveOnly)
if (AudPairsPositiveOnly)
{
if (stringSubstrOld(symbol, 0, 3) == "AUD" || stringSubstrOld(symbol, 0, 3) == "aud" || stringSubstrOld(symbol, 3, 3) == "AUD" || stringSubstrOld(symbol, 3, 3) == "aud" )
{
if (buySignal)
if (longSwap <= 0)
buySignal = false;
if (sellSignal)
if (shortSwap <= 0)
sellSignal = false;
}//if (stringSubstrOld()
}//if (AudPairsPositiveOnly)
if (NzdPairsPositiveOnly)
{
if (stringSubstrOld(symbol, 0, 3) == "NZD" || stringSubstrOld(symbol, 0, 3) == "nzd" || stringSubstrOld(symbol, 3, 3) == "NZD" || stringSubstrOld(symbol, 3, 3) == "nzd" )
{
if (buySignal)
if (longSwap <= 0)
buySignal = false;
if (sellSignal)
if (shortSwap <= 0)
sellSignal = false;
}//if (stringSubstrOld()
}//if (AudPairsPositiveOnly)
//OnlyTradePositiveSwap filter
if (OnlyTradePositiveSwap)
{
if (buySignal)
if (CloseEnough(longSwap, 0) )
if (longSwap <= 0)
buySignal = false;
if (sellSignal)
if (CloseEnough(shortSwap, 0) )
if (shortSwap <= 0)
sellSignal = false;
}//if (OnlyTradePositiveSwap)
//MaximumAcceptableNegativeSwap filter
if (buySignal)
if (longSwap < MaximumAcceptableNegativeSwap)
buySignal = false;
if (sellSignal)
if (shortSwap < MaximumAcceptableNegativeSwap)
sellSignal = false;
//Buy/sell only pairs.
//Must not be in the sell only list
if (buySignal)
if (checkSellOnlyPairs(symbol) )
buySignal = false;
//Must not be in the buy only list
if (sellSignal)
if (checkBuyOnlyPairs(symbol) )
sellSignal = false;
}//void tradeDirectionBySwap()