Reputation: 67
All my IF statements work without issue except for the last one, even though it is still syntactically correct.
A simplified version of my code is below that contains the pertinent information. I have tested for 1st 6 IF statements by using comments. These are printed in testing. Comments made on the last 2 do not print. I have found that if both lastSignal
& thisSignal
are filled with either "BUY" or "SELL" then the statements will execute, but I want them to be stored based on the conditions of the 1st 4 IF statements. The only error code I receive is [Invalid stops]
which is not helping me at all (I cannot find anything that helps resolve the issue).
Thanks
Steve
void OnTick()
{
// MQL Rates
MqlRates priceArray[];
ArraySetAsSeries(priceArray, true);
int data = CopyRates(cPair, _Period, 0, 3, priceArray);
// SAR data
double mySARArray[];
int SARDefinition = iSAR(_Symbol, _Period, 0.02, 0.2);
ArraySetAsSeries(mySARArray, true);
CopyBuffer(SARDefinition, 0, 0, 3, mySARArray);
// Set SAR structure
double lastSARValue = NormalizeDouble(mySARArray[1], 5);
double thisSARValue = NormalizeDouble(mySARArray[0], 5);
string lastSignal = "";
string thisSignal = "";
// Set previous signals
if(lastSARValue < priceArray[1].high)
{
// This works
lastSignal = "BUY";
}
if(lastSARValue > priceArray[1].low)
{
// This works
lastSignal = "SELL";
}
// Set current signals
if(thisSARValue < priceArray[0].high)
{
// This works
thisSignal = "BUY";
}
if(thisSARValue > priceArray[0].low)
{
// This works
thisSignal = "SELL";
}
// Set trade
if(thisSignal == "BUY")
{
// This works
BuyTrade();
}
if(thisSignal == "SELL")
{
// This works
SellTrade();
}
// Set SAR swap
if(lastSignal == "SELL" && thisSignal == "BUY")
{
// This does not work
Comment("Sell to buy");
}
if(lastSignal == "BUY" && thisSignal == "SELL")
{
// This does not work
Comment("Buy to sell");
}
Upvotes: -1
Views: 30