I need your help on this EA. Actually I already got system in Amibroker TA.
I am trying to code same system as Metatrader EA.
Below is amibroker code(AFL) for system that I want to code as EA.
a = Cross(H,res);
b = Cross(sup,L);
state = IIf(BarsSince(a)<BarsSince(b),1,0); //(<<this return 1 or 0 based on condition)
As you can see there is external parameter ("no") which can be selected by user is in integer value.
Calculation on lines/variables RES & SUP (Resistance & Support)
res can be calculated using EMA of period 3 & PRICE will be highest high price of last 7 bars. This 7 bars is integer value which set by external parameter by user no.
Same goes for sup which is EMA of period 3, But only difference is that price of EMA calculation is lowest low price of last 7 bars.
Now variable a will set to 1 or 0 based on the crossing of current bar high & variable res.
For variable b set to 1 or 0 based on the crossing of current bar low & variable sup.
Here is definition of this CROSS afl code.
Now the variable state which also can be set to 1 or 0 based on following condition.SYNTAX Cross( ARRAY1, ARRAY2 )
FUNCTION Gives a "1" or true on the day that ARRAY1 crosses above ARRAY2. Otherwise the result is "0".
To find out when ARRAY1 crosses below ARRAY2, use the formula cross(ARRAY2, ARRAY1)
EXAMPLE cross( close, ema(close,9) )
BarsSince(a) : Calculates the number of bars (time periods) that have passed since ARRAY was true (or 1) in this case array was variable a
BarsSince(b) : Calculates the number of bars (time periods) that have passed since ARRAY was true (or 1) in this case array was variable b.
state = IIf(BarsSince(a)<BarsSince(b),1,0);
Now I created EA based on above system. But my knowledge with MQL is not good.SYNTAX iif( EXPRESSION, TRUE_PART, FALSE_PART )
FUNCTION "Immediate-IF" - a conditional function that returns the value of the second parameter (TRUE_PART) if the conditional expression defined by the first parameter (EXPRESSION) is true; otherwise, the value of third parameter is returned (FALSE_PART). Please note that IIF is a function - so the result of evaluation is returned by that function and should be assigned to some variable. IIf always evaluates both TRUE_PART and FALSE_PART, even though it returns only one of them. Because of this, you should watch for undesirable side effects. The following example shows one common error made with IIF function: IIF( condition, result = 7, result = 9 ); // THIS IS WRONG Correct usage is: result = IIF( condition, 7, 9 ); /* 7 or 9 is *returned* and assigned to a variable depending on condition */
EXAMPLE The formula result = iif( macd()<signal(), Volume, -Volume) will assign positive volume values to the result variable on days when macd was below its signal line, and negative volume values on theother days.
I try to create some MQL code but I am not able to get same results in Metatrader which was I am getting in Amibroker.
Please download attached MQL code file & Amibroker Trading system chart .
Note: This system generates buy/sell without vanishing. When buy/sell comes at some point it stays there so no fake signals.