Troubleshooting Issues for Property #Strict

Troubleshooting Issues for Property #Strict

30 August 2018, 08:23
Mpendulo Chiliza
0
23

Introduction

I have been battle for almost four months, trying to get my head around the issues that arises when you set your indicator or expert adviser to #Property strict. So in this  article I will show you how I went about solving any issues that only arise when you use #property strict


Array Out Of Range

This has to be the most talked about error and the most misunderstood error. from my try and error, Its best to avoid using a for loop, instead use a while loop.

int i,        // Bar index
Counted_bars; // Number of counted bars

//--------------------------------------------------------------------

Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-2;  // Index of the first uncounted

while( i>0 ){
 i--;
}

Try your best to avoid this popular error.


The Alert Function

Weird as it is, for some reason the indicator fails if you have an Alert function, best use Print. Or Alert will get triggered for no reason.

int value = 10;

Print("you variable is",value);

For more information on how to use the Print function . 


USE void OnInit NOT int OnStart (Initialization Error)

Again, no reason, But I found out the hard way, PLEASE only use OnInit void function to initialize your code, to avoid "Initialization Error". I would recommend you also use OnCalculate() function.

int OnInit()
  {
   //your code here
   return(0);
  }

int deinit(){
   return(0);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  { 
    //your code here
    return(0);
  }

I'm sure if you go deep int documentation, they have a reasonable explanation, but if you do not have time its best you print this one in your mind.


Dummy Down The IF statement

When I broke down my if statements into separate statements, I started seeing promising result, so I thought I should include this practice also. "Do your best to avoid chained IF statement" also it will make your code easy to read and process a little more faster.

BAD PRACTICE 

if( A>B && C<D ){
   //your code here
}

GOOD PRACTICE

if(A>B) if(C<D){
   //your code here
}

//the second IF statement is read by the first IF statement as one line, this will help to avoid getting confused 


Simplify Your Code

If you still having troubles with #property strict,  try to simplify you code by commenting complicated lines out. Basically strip your code down to its basic elements, this will help you spot breaking codes or illegal expressions. Once you know whats not working, Google for alternative commands and implement.


Conclusion

After 4 months of headaches and rejections, I've finaly have products of my on the market ( Stepping Trend and Three Peaks ).  I hope this article was very information for you, and i will continue to update it, as i keep discovering more "illegal" functions and implementations for #property strict


Share it with friends: