AFL edit HELP!!

#1
Hi friends,

first of all thanks a lot for providing such a beautiful platform, any amount of appreciation is less. The seniors doing a selfless job of guiding, mentoring and editing is commendable.

I have developed a very simple and effective trading methodology based on price action market psychology.

EMA cross over (fast,slow) as first step and then a retracement back to the slow ema. makes the stock come in my radar.

The AFL that I have made is as below.


/*==============================================================================
User-defined Functions
============================================================================== */
function EMA0(A, p)
{
r[0] = a[0];
ep = 2/(p+1);
for(i = 1; i < BarCount; i++)
{
r = r[i-1] + (a - r[i-1]) * ep;
}
return r;
}

function OptimizeNot(a1, a2, a3, a4, a5)
{
return a2;
}

/*==============================================================================
Entry and Exit Rules
==============================================================================*/
tr = Max(H-L, Max(abs(H-Ref(C, -1)), abs(Ref(C, -1)-L)));
tr[0] = H[0] - L[0];

fast = EMA0(C, Optimize("FastEMA", 5, 10, 140, 5));
slow = EMA0(C, Optimize("SlowEMA", 30, 30, 100, 10));

Buycond= fast> slow;
Buycond2= L <(EMA(Close,30));
Shortcond = slow> fast;
Shortcond2= H >(EMA(Close,30));

Buy= Buycond AND Buycond2;
Sell=Shortcond AND Shortcond2;

ExRem(Buy,Sell);
ExRem(Sell,Buy);

PlotShapes( Buy * shapeUpArrow, colorGreen,0,C);
PlotShapes(Sell * shapeDownArrow,colorRed,0,C);


Filter = Buy OR Sell;



now I am no AFL expert and all this is copy paste cloning. I am a low life after all.

The problem with this AFL is that it gives the signal every time price comes in the range specified whereas what I want is a signal only once after the ema cross over has happened.


what I am essentially saying is that AFL should not look for the price range condition every time but just the first time after EMA cross over has happened.


Please edit the code to imbibe that, I know it is a matter of 10 mins for you guys whereas it will take an eternity for a novice like me.

Thanks in advance

warm regards,

Manish Dhawan.
 

extremist

Well-Known Member
#2
first of all don't feel like a lesser coder coz ur doing Copy paste and cloning.
i guaranty u everyone here is been through this stage.
other wise no way.
not all r gifted with such talent to read the help and code directly.

fell good and stick to the task and u will be coding one day....

Corrections:

replace these two lines

ExRem(Buy,Sell);
ExRem(Sell,Buy);

with

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

try to see help also. it will be good for u.

suggestions:

tr = Max(H-L, Max(abs(H-Ref(C, -1)), abs(Ref(C, -1)-L)));
tr[0] = H[0] - L[0];

this thing not used in code so can remove it .
same is

function OptimizeNot(a1, a2, a3, a4, a5)
{
return a2;
}

and instead of

fast = EMA0(C, Optimize("FastEMA", 5, 10, 140, 5));
slow = EMA0(C, Optimize("SlowEMA", 30, 30, 100, 10));

use

fast = EMA0(C, Param( "Periods1", 5, 1, 200, 1 ));
slow = EMA0(C, Param( "Periods2", 30, 1, 200, 1 ));

tht optimize not at all helping any cause.

i hope u got wht u needed.

KEEP IT AS SIMPLE AS IT CAN BE AND IMPORTANTLY AS SHORT AS IT COULD BE
 
Last edited:

Similar threads