Simple Moving Average cross over strategy not working

Simple Moving Average cross over strategy not working

Manage alerts

Loading saved threads...

Andy Galloway · External communityPost link
External question — Stack Overflow Stack Exchange Author: Andy Galloway Original post: https://stackoverflow.com/questions/64047612 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am creating a simple EA to place a trade on an SMA crossover. However, I cannot get the correct signal back from the checkEntry function. It is fine in most cases, but when the two lines almost cross then diverge again, I end up with the wrong signal. Can anyone spot what the mistake is? Also, I wouldlike to introduce a small buffer of say 1 pip after the crossover before the signal is given. string checkEntry() { double myFastMa = iMA(ChartSymbol(),Period(),varSma1,0,MODE_SMA,PRICE_CLOSE,0); double mySlowMa = iMA(ChartSymbol(),Period(),varSma2,0,MODE_SMA,PRICE_CLOSE,0); double myFastMaPrev = iMA(ChartSymbol(),Period(),varSma1,1,MODE_SMA,PRICE_CLOSE,1); double mySlowMaPrev = iMA(ChartSymbol(),Period(),varSma2,1,MODE_SMA,PRICE_CLOSE,1); double myTrendMa = iMA(ChartSymbol(),Period(),varSma3,0,MODE_SMA,PRICE_CLOSE,0); if (myFastMa > mySlowMa && myFastMaPrev <= mySlowMaPrev) signal = "BUY"; if (myFastMa < mySlowMa && myFastMaPrev >= mySlowMaPrev) signal = "SELL"; // Alert ("myFastMa is ", myFastMa," and myFastMaPrev is ", myFastMaPrev); // Alert ("mySlowMa is ", mySlowMa," and mySlowMaPrev is ", mySlowMaPrev); // Alert ("This gives a ",signal," signal"); return signal; } // End CheckEntry()
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Andy Galloway Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/64047612 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am creating a simple EA to place a trade on an SMA crossover. However, I cannot get the correct signal back from the checkEntry function. It is fine in most cases, but when the two lines almost cross then diverge again, I end up with the wrong signal. Can anyone spot what the mistake is? Also, I wouldlike to introduce a small buffer of say 1 pip after the crossover before the signal is given. string checkEntry() { double myFastMa = iMA(ChartSymbol(),Period(),varSma1,0,MODE_SMA,PRICE_CLOSE,0); double mySlowMa = iMA(ChartSymbol(),Period(),varSma2,0,MODE_SMA,PRICE_CLOSE,0); double myFastMaPrev = iMA(ChartSymbol(),Period(),varSma1,1,MODE_SMA,PRICE_CLOSE,1); double mySlowMaPrev = iMA(ChartSymbol(),Period(),varSma2,1,MODE_SMA,PRICE_CLOSE,1); double myTrendMa = iMA(ChartSymbol(),Period(),varSma3,0,MODE_SMA,PRICE_CLOSE,0); if (myFastMa > mySlowMa && myFastMaPrev <= mySlowMaPrev) signal = "BUY"; if (myFastMa < mySlowMa && myFastMaPrev >= mySlowMaPrev) signal = "SELL"; // Alert ("myFastMa is ", myFastMa," and myFastMaPrev is ", myFastMaPrev); // Alert ("mySlowMa is ", mySlowMa," and mySlowMaPrev is ", mySlowMaPrev); // Alert ("This gives a ",signal," signal"); return signal; } // End CheckEntry()

Cancel quote

Checking account access…
Simple Moving Average cross over strategy not working | Forex.com.bd