Simple Coding Help - No Promise.

can somebody please help me in finding an afl which shows small square showing the trend of various time frames on on chart. please can somebody help me
 
Help required to code strategy in Amibroker.

1. First The 50 MA should crossover the 200 MA.
2. Then the very first crossover of 8 MA above 34 MA.

Step 2 is a Buy signal. Kindly note that we are considering only the first Positive crossover of 8 MA above 34MA as Buy signal after the 50-200 MA crossover.

3. First The 20 MA should cross below the 200 MA.
4. Then the very first crossover of 8 MA below 34 MA.

Step 4 is a Sell signal. Kindly note that we are considering only the first negative crossover of 8 MA below 34MA as Sell signal after the 200-50 MA crossover.

Thanks.
 

josh1

Well-Known Member
Good morning

I want to get hourly price candles time stamping-0900--10000 and 10000--1100 likewise
candle start without premarket data that is 0900-0915
guidance please
Assuming you are talking about NSE equity, go to Amibroker Database settings -- intraday Settings. Set as below
1542779127829.png


Then in Tools -- Preferences -- Intraday set as below
1542779268257.png


Premarket data is not given by NSE except for spot index so it won't be shown unless you are manually feeding it.
 

josh1

Well-Known Member
Code:
_SECTION_BEGIN("TrendLines");

GraphXSpace = Param("GraphXSpace", 10, 0, 100, 1);

colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));
//Price
SetBarFillColor(colorHighliter);
Plot(C, "Close", IIf(colorHighliter == ColorRGB(128, 0, 128), ColorRGB(255, 0, 255), IIf(colorHighliter == ColorRGB(128, 128, 0), ColorRGB(255, 255, 0), IIf(C > O, ColorRGB(0, 255, 0), IIf(C < O, ColorRGB(255, 0, 0), ColorRGB(255, 255, 255))))), styleCandle, Null, Null, 0, 0);

// Pivots
SV_LP=Param("Lookback Period for pivot?",5,2,50,1);

PH = H > Ref(HHV(H,SV_LP),-1) AND Ref(HHV(H,SV_LP),SV_LP)<=H;
PHP = ValueWhen(PH,H);
PL = L < Ref(LLV(L,SV_LP),-1) AND Ref(LLV(L,SV_LP),SV_LP)>=L;
    if(ParamToggle("Suppress Successive Same Pivots?","No,Yes")){
        PH = ExRem(PH,PL);
        PL = ExRem(PL,PH);
    }

    if(ParamToggle("Plot Pivots?","No,Yes",1)){
        PlotShapes(IIf(PH,shapeSmallCircle,shapeNone),colorGreen,0,H,12);
        PlotShapes(IIf(PL,shapeSmallCircle,shapeNone),colorRed,0,L,-12);
    }
//End Pivots

//Demand Point
colorDemandPoint = ParamColor("Demand Line", ColorRGB(0, 128, 255));
DemandPoint = PL;
//Supply Point
colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
SupplyPoint = PH;

CountTrendBars = 0;
CurrentBar = BarCount - 1;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;
y2=0;
y3=0;

Miny = Status("axisminy");
Maxy = Status("axismaxy");

for (i = 0; i < BarCount; i++) {
    CurrentBar = (BarCount - 1) - i;
    if (DemandPoint[CurrentBar]) {
        if (dx1 == 0 & dy1 == 0) {
            dx1 = CurrentBar;
            dy1 = L[CurrentBar];
        } else {
            dx0 = CurrentBar;
            dy0 = L[CurrentBar];
        }
        if (dx0 != 0 & dx1 != 0 & dy0 != 0 & dy1 != 0) {
            if (dy0 < dy1) {
                a = (-dy0 + dy1) / (-dx0 + dx1);
                b = dy0 - dx0 * a;
                for (j = dx1; j < BarCount; j++) {
                    if (j != dx1) {
                        y2 = a * j + b;

//                        if(y2 == Miny) {break;};

                        if (C[j] < y2) {
                            dy1 = y2;
                            dx1 = j;
                            colorHighliter[j] = ColorRGB(128, 0, 128);
                            CountTrendBars[j] = dx1 - dx0 - 1;
                            break;
                        }
                    }
                }
                if (dy1 != y2) {
                    dy1 = y2;
                    dx1 = BarCount - 1;
                }
                Plot(LineArray(dx0, dy0, dx1, dy1, 0), "", colorDemandPoint, styleLine, Null, Null, 0, 0);
            }
            dx1 = dx0;
            dy1 = dy0;
            dx0 = dy0 = 0;
        }
    }

    if (SupplyPoint[CurrentBar]) {
        if (sx1 == 0 & sy1 == 0) {
            sx1 = CurrentBar;
            sy1 = H[CurrentBar];
        } else {
            sx0 = CurrentBar;
            sy0 = H[CurrentBar];
        }
        if (sx0 != 0 & sx1 != 0 & sy0 != 0 & sy1 != 0) {
            if (sy0 > sy1) {
                a = (-sy0 + sy1) / (-sx0 + sx1);
                b = sy0 - sx0 * a;
                for (j = sx1; j < BarCount; j++) {
                    if (j != sx1) {
                        y3 = a * j + b;

//                        if(y3 == Miny) {break;};

                        if (C[j] > y3) {
                            sy1 = y3;
                            sx1 = j;
                            colorHighliter[j] = ColorRGB(128, 128, 0);
                            CountTrendBars[j] = sx1 - sx0 - 1;
                            break;

                        }
                    }
                }
                if (sy1 != y3) {
                    sy1 = y3;
                    sx1 = BarCount - 1;
                }
                Plot(LineArray(sx0, sy0, sx1, sy1, 0), "", colorSupplyPoint, styleLine, Null, Null, 0, 0);
            }
            sx1 = sx0;
            sy1 = sy0;
            sx0 = sy0 = 0;
        }
    }
}



/*
How it work:
========

Supply Line is Orange, Demand Line is Blue.
Trigger: Buy candle is Yellow, Sell Candle is Magenta

*/

_SECTION_END(); //("TrendLines");

_N(Title = StrFormat(EncodeColor( colorPaleGreen ) + "{{NAME}} - {{INTERVAL}} {{DATE}} " + " Open %g,"  + " Hi %g, "
+ " Lo %g, "  + " C %g  {{VALUES}}", O, H, L, C )
+ EncodeColor( colorRed ) + "\n"+",  LH = " + NumToStr(Ref(H,-1), 1.4)  + ",    LL = "
+ NumToStr(Ref(L,-1), 1.4) + ",    LH2 = " + NumToStr(Ref(H,-2), 1.4) + ", LL2 = " + NumToStr(Ref(L,-2), 1.4));
This is AFL for drawing Trend Lines on the chart. I want to provide break when value of y2 or y3 is less than Lowest Lowor more than the highest high in visible chart. Some times (LineArray(sx0, sy0, sx1, sy1, 0) goes below zero. That distorts the chart and makes it illegible.

I tried this --
if(y2 == Miny) {break;};

It does not work. Miny becomes negative, some times -536 to accommodate array.

Edit - I am using 3 and 5 minute chart. If Amibroker throws error on activating AFL, try changing intraday bar period to 1,3,5,6,15,60 minutes by pressing Ctrl+1, or 5 or 6 etc. Once chart appears, you can change bar period to 3/5 minutes.
Thanks
 
Last edited:

josh1

Well-Known Member
Reverting the definition of Demand and Supply point seems to solve the issue.

DemandPoint = (L < Ref(L, -2)) & L <= Ref(L, -1) & L < Ref(L, 1) & L < Ref(L, 2);
//DemandPoint = PL;

SupplyPoint = (H > Ref(H, -2) & H >= Ref(H, -1) & H > Ref(H, 1) & H > Ref(H, 2));
//SupplyPoint = PH;

It seems I have not understood Amibroker Arrays fully.
 

john302928

Well-Known Member
Hi
Could anyone help me create this kind of Pivot support resistance lines. The below chart is taken from tradingview. In intrday chart if we set the pivot time frame as "Daily" it will chart the Daily pivots on the chart and if we set it to "Auto" then it will show the pivots lines of one higher time frame than the current time frame. say for example if we are viewing the chart in 30 min time frame then it will show the pivot lines of 60 min timframe.
Could anyone please help me with this. Its very urgent. It would be of great help.
1542972810080.png
 
Assuming you are talking about NSE equity, go to Amibroker Database settings -- intraday Settings. Set as below
View attachment 30896

Then in Tools -- Preferences -- Intraday set as below
View attachment 30897

Premarket data is not given by NSE except for spot index so it won't be shown unless you are manually feeding it.
Good morning Josh ji
First of all Thank you for your kind reply.
Yes I set this same settings. As you mentioned Index spot premarket data updated automatically. Now rectified. Thanks again.
 
Reverting the definition of Demand and Supply point seems to solve the issue.

DemandPoint = (L < Ref(L, -2)) & L <= Ref(L, -1) & L < Ref(L, 1) & L < Ref(L, 2);
//DemandPoint = PL;

SupplyPoint = (H > Ref(H, -2) & H >= Ref(H, -1) & H > Ref(H, 1) & H > Ref(H, 2));
//SupplyPoint = PH;

It seems I have not understood Amibroker Arrays fully.

Dear Josh, I tried ur afl as per ur modified demand/supply point, but error with warning.
so pls post working afl

thanks & regards
 

Similar threads