Simple Coding Help - No Promise.

Hi, I am using aux1 value as "Foreign Money Flow".
(+) for inflow, (-) for outflow.

I need to create AFL to explore and summarize aux1 value(in Billions) based on WeeklyBar(WeektoDate), MonthlyBar(MonthtoDate) and YearlyBar(YeartoDate)..

TimeFrameSet( inYearly );
Y_NBSA=Aux1/1000000000;
TimeFrameRestore();

TimeFrameSet( inMonthly );
M_NBSA=Aux1/1000000000;
TimeFrameRestore();

TimeFrameSet( inWeekly );
W_NBSA=Aux1/1000000000;
TimeFrameRestore();

D_NBSA=Aux1/1000000000;

AddColumn(W_NBSA ,"WTD(B)",6.2,colorDefault,colorDefault,62);
AddColumn(M_NBSA ,"MTD(B)",6.2,colorDefault,colorDefault,62);
AddColumn(Y_NBSA ,"YTD(B)",6.2,colorDefault,colorDefault,62);
AddColumn(D_NBSA ,"NBSA_D(B)",6.2,colorDefault,colorDefault,62);

Filter=1;
But the value of aux1 is always using the last daily value, no matter in weekly, monthly or yearly.
**I already set DatabaseSetting-->IntradaySettings-->Aux1,2 agregration mode to sum.. but there are no differences.
In chart yes, it is summarize, but in exploration/afl it is always using the last daily value

Thanks a lot
 
How will you make a program to find the peaks and troughs ? - it has to loop through the data to find them no other go.
I agree to what you say.. but still there ca be a way to use loop in more sensible way so that it is not so much memory intensive.
One needs two points (x1,y1) and (x2,y2) to draw a (trend) line. As i see it, here it needs 'For loop' to know the value of y1 only.. other 3 variables don't need that.
That is to say.. moving from right ... it finds a fractal first.. and then tries to find a previous fractal .. and connect them thru a line.
mayb u r right.. Thanks anyway , sir
 

jagankris

Well-Known Member
I agree to what you say.. but still there ca be a way to use loop in more sensible way so that it is not so much memory intensive.
One needs two points (x1,y1) and (x2,y2) to draw a (trend) line. As i see it, here it needs 'For loop' to know the value of y1 only.. other 3 variables don't need that.
That is to say.. moving from right ... it finds a fractal first.. and then tries to find a previous fractal .. and connect them thru a line.
mayb u r right.. Thanks anyway , sir
ManuAdam,

Only thing that comes to my mind is to reduce the loop period.
Instead of looping from 1st bar to the barcount (Last bar) the loop could be reduced.

Some thing like firstvisiblebar/last visible bar.
You can take sample example from the below
http://www.wisestocktrader.com/indicators/2791-vwap-bands-v2
(Improved the performance of VWAP bands than earlier versions using bigger for loops).

Hope this helps.
 
Hi,

I am stuck up with multiple signals generation in my afl. I have 3 sets of condition which are to be satisfied in sequence for successful buy signal generation.
Condition 1 - For Buy condition, the EMA crossover which I am getting properly
Condition 2 - Pullback to EMA - here I am getting problem. There could be more than one bar which can satisfy this condition. I want only first bar which satisfy condition immediately after Condition1. Rest all bars should be ignored till next crossover happens in Condition1.
Condition 3 - Similar to condition2, need first "true" signal only after condition2 is true.

I tried with flip and exrem but somehow it is not working. I am confused with how arrays are updated in amibroker.

Please help me in writing the above code, stuck up since last 2 days. Appreciate your help.
 

jagankris

Well-Known Member
Hi,

I am stuck up with multiple signals generation in my afl. I have 3 sets of condition which are to be satisfied in sequence for successful buy signal generation.
Condition 1 - For Buy condition, the EMA crossover which I am getting properly
Condition 2 - Pullback to EMA - here I am getting problem. There could be more than one bar which can satisfy this condition. I want only first bar which satisfy condition immediately after Condition1. Rest all bars should be ignored till next crossover happens in Condition1.
Condition 3 - Similar to condition2, need first "true" signal only after condition2 is true.

I tried with flip and exrem but somehow it is not working. I am confused with how arrays are updated in amibroker.

Please help me in writing the above code, stuck up since last 2 days. Appreciate your help.
Post your code.
 
Here is the code. I was doing trial and error so lot of lines are commented. It is simple crossover system with pullback to EMA.

Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
e1=EMA(C,9);
e2=EMA(C,45);
Plot(e1,"",colorRed);
Plot(e2,"",colorYellow);

BuyCrossover=Cross(e1,e2);
SellCrossover=Cross(e2,e1);


BuyCrossover = Flip( BuyCrossover, SellCrossover );
SellCrossover = Flip( SellCrossover, BuyCrossover ); 

//BuyCrossover = ExRem( BuyCrossover, SellCrossover );
//SellCrossover = ExRem( SellCrossover, BuyCrossover ); 


//printf(WriteIf(BuyCrossover,"Buy Signal Generated","") + " \n");
BI = BarIndex();
CrossoverIndex = ValueWhen(BuyCrossover, BI,1);
//printf("Buy Signal Generated bar index" + LastValue(CrossoverIndex,False) + " \n");

//NoteSet("",WriteIf(Buy,"Buy Signal Generated","") + " \n");
//printf("Bar Since buy signal " + BarsSince(BuyCrossover)+ " \n"); 

//Price should pullback to 45EMA
BarBelow45 = IIf(BuyCrossover, IIf(BarsSince(BuyCrossover) <= 5 AND L <= e2,1,0),0); //this is for buy signal, pullback to 15EMA
BarBelow45 = Flip(BarBelow45,SellCrossover); 

//printf("Bar Since BarBelow15 " + BarsSince(BarBelow15)+ " \n"); 
//printf(WriteIf((BarsSince(BuyCrossover) - BarsSince(BarBelow15) >= 2),"Bar closed below 15EMA after buy signal","") + " \n");

//BarBelow15Confirmed =  IIf(BarsSince(BuyCrossover) - BarsSince(BarBelow15) >= 2,1,0);
//PlotShapes(IIf(BarBelow15Confirmed AND (ValueWhen(BarBelow15,L) == L), shapeSmallCircle, shapeNone),colorGreen, 0, L, Offset=-10);

BarCloseAbove9 = IIf(C >= e1,1,0); //this is for buy signal, close above 3EMA
//printf(WriteIf((BarsSince(BuyCrossover) - BarsSince(BarBelow15) >= 2),"Bar closed below 15EMA after buy signal","") + " \n");


BarCloseAbove9 = IIf((BarsSince(BarBelow45) - BarsSince(BarCloseAbove9)) <= 5,1,0);

BarCloseAbove9 = Flip(BarCloseAbove9, SellCrossover); 

//BarBelow15 = Flip(BarBelow15, BuyCrossover);


PlotShapes(IIf(BuyCrossover, shapeSmallSquare, shapeNone),colorGreen, 0, L, Offset=-10);
PlotShapes(IIf(BarBelow45, shapeSmallCircle, shapeNone),colorGreen, 0, L, Offset=-10);
//PlotShapes(IIf(BarCloseAbove9, shapeUpArrow, shapeNone),colorGreen, 0, L, Offset=-10);
 

Similar threads