Indicators: Optimize single Moving average trading

 

Optimize single Moving average trading:

Optimize trading with a single moving average. This indcator tests each moving average and automatically finds the moving average which fits best to the current market

Author: Thomas Quester

 
1. Time Filter 2. Daily average range
 
  1. if (Bars != cBars)
           newBar = true;
       else  
           newBar = false;
       cBars = Bars;
    This is unsafe. Once Bars reaches Maximum Bars On Chart, the indicator stops working as Bars and cBars will not change.
    bool newBar = Time0 < Time[0]; Time0 = Time[0];

  2. The code checking for a symbol/TF change is unnecessary. When that occurs you'll get a deInit() init() cycle.
  3. Hard coded array size but never checked if exceeded
    gTradeID++;
       ArrayResize(gTradeOpen,gTradeID+1);
       ArrayResize(gTradeMin,gTradeID+1);
       ArrayResize(gTradeMax,gTradeID+1);
       ArrayResize(gTradeCmd,gTradeID+1);
       ArrayResize(gTradeStart,gTradeID+1);
       ArrayResize(gTradeEnd,gTradeID+1);
    gTradeOpen[gTradeID] = price;
    ...

 

This indicator has errors when attempting to compile it.

If you manage to fix it please post it in full code post.

 

Hi Thomas,

I have taken a look at this indicator and the method you used to find the optimised moving average is amazing. I tried tinkering the indicator for the indicator to just output a single optimised MA without any bells and whistle and this is how far I have reached. Can anyone kindly help with this?

https://drive.google.com/open?id=11ow982kViK7RxQkJ5AjVV1PIAlGUfzLs