help strange problem on scaning nd exlporation

Discussion in 'AmiBroker' started by amit_k2100, Dec 22, 2009.

  1. amit_k2100

    amit_k2100 Member

    Joined:
    Nov 20, 2009
    Messages:
    178
    Likes Received:
    21
    Trophy Points:
    18
    guys i have a formul which shows buy-sell signal.....but when i run scan on it it doesnot scan nd shows a error message that buy-sell signal missing ....why so ?
    when i run exlporation it again shows an error by sayng check help how to run exploration................whereas if i expore or scan with other formula it does that very easily..thnx in advance
     
  2. vinodkiyer

    vinodkiyer Well-Known Member

    Joined:
    Feb 2, 2009
    Messages:
    352
    Likes Received:
    418
    Trophy Points:
    63
    for scan u must add - Filter = Buy or Sell;
    for explore u must also add AddColumn(....) to the afl
     
  3. amit_k2100

    amit_k2100 Member

    Joined:
    Nov 20, 2009
    Messages:
    178
    Likes Received:
    21
    Trophy Points:
    18
    hi bro thnx for reply....but the problem not rectified...now when i add ur line " filter=buy or sell" it shows error in formula that buy nd sell variables used without being intianlised.plz bro if posible write the exact line to be added for scanning nd exploration....thnx
     
  4. ramsrinivasan

    ramsrinivasan Member

    Joined:
    Dec 24, 2009
    Messages:
    56
    Likes Received:
    8
    Trophy Points:
    8
    Friends...

    Stock of the year are and going to outperform the markets are...



    Vijaay bank ,IFCI bank , UCO bank , ICICI bank , Deep industries , fcs software , hanung toys , indowind energy , acc cement..

    Watch out for these...


    Ram Srinivasan...
     
  5. vinodkiyer

    vinodkiyer Well-Known Member

    Joined:
    Feb 2, 2009
    Messages:
    352
    Likes Received:
    418
    Trophy Points:
    63
    check and make sure that Buy= and Sell= conditions are written in the afl and put the filter= after these Buy/sell lines or as the last line in the afl
     
  6. amit_k2100

    amit_k2100 Member

    Joined:
    Nov 20, 2009
    Messages:
    178
    Likes Received:
    21
    Trophy Points:
    18
    guys i am wrting the formula....plz make changes nd make it suitable for scaning nd exploration........thnx




    _SECTION_BEGIN("Price");
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
    Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
    if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
    {
    ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
    }
    _SECTION_END();



    _SECTION_BEGIN("GIP-3");
    SetChartOptions(0,chartShowArrows|chartShowDates);
    _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
    Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
    if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
    {
    ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
    }

    // -- what will be our lookback range for the hh and ll?
    nBars = Param("Number of bars", 12, 5, 40);
    bTrace = Param("Include trace output", 1, 0, 1);
    nNoPivsInSetup = Param("No. Pivs in Setup", 4, 3, 4, 1);
    bShowTCZ = Param("Show TCZ", 1, 0, 1);
    nMinBarsBtwPivs = Param("Min. number of bars btw. pivots", 1, 1, 10, 1);
    nMinPctBtwPivs = Param("Min. percent diff. btw. pivots", .05, .04, .2, .01);
    bLastBarCanBePiv = Param("Last bar can be a pivot", 1, 0, 1);
    retrcTolerance = .01;
    tczTolerance = .005;
    nNumBarsToScan = 120;

    // -- added from exploration version 20040204
    nExploreBarIdx = 0;
    nExploreDate = 0;
    nCurDateNum = 0;
    DN = DateNum();
    DT = DateTime();

    // -- key exploration variables
    bTCZLong = False;
    bTCZShort = False;
    nAnchorPivIdx = 0;

    ADX8 = ADX(8);

    // 1 - INDICATOR, 2 - COMMENTARY, 3 - SCAN,
    // 4 - EXPLORATION, 5 - BACKTEST / Optimize
    if(Status("action")==1) {
    bDraw = True;
    bUseLastVis = Param("Use last visible bar", 1, 0, 1);
    } else {
    bDraw = False;
    bUseLastVis = False;
    bTrace = False;
    nExploreDate = Status("rangetodate");
    for (i=LastValue(BarIndex());i>=0;i--) {
    nCurDateNum = DN;
    if (nCurDateNum == nExploreDate) {
    nExploreBarIdx = i;
    }
    }
    // -- if(Status("action")==1...
    }

    GraphXSpace=7;

    // -- basic candle chart
    // -- if this appears inside if block, strange
    // drawing results!
    PlotOHLC(Open, High, Low, Close,
    "BIdx = " + BarIndex() +
    "\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L
    + "\n"+"C ",
    colorBlack, styleCandle);


    // -- Create 0-initialized arrays the size of barcount
    aHPivs = H - H;
    aLPivs = L - L;
    aHPivHighs = H - H;
    aLPivLows = L - L;
    aHPivIdxs = H - H;
    aLPivIdxs = L - L;
    aAddedHPivs = H - H;
    aAddedLPivs = L - L;
    aLegVol = H - H;
    aRetrcVol = H - H;

    nHPivs = 0;
    nLPivs = 0;

    lastHPIdx = 0;
    lastLPIdx = 0;
    lastHPH = 0;
    lastLPL = 0;
    curPivBarIdx = 0;

    // -- looking back from the current bar, how many bars
    // back were the hhv and llv values of the previous
    // n bars, etc.?
    aHHVBars = HHVBars(H, nBars);
    aLLVBars = LLVBars(L, nBars);
    aHHV = HHV(H, nBars);
    aLLV = LLV(L, nBars);

    // -- Initialize value of curTrend
    nLastVisBar = LastValue(
    Highest(IIf(Status("barvisible"), BarIndex(), 0)));

    curBar = IIf(nlastVisBar > 0 AND bUseLastVis, nlastVisBar,
    IIf(Status("action")==4 AND nExploreBarIdx > 0, nExploreBarIdx,
    LastValue(BarIndex())));

    curTrend = "";
    if (aLLVBars[curBar] < aHHVBars[curBar])
    curTrend = "D";
    else
    curTrend = "U";

    // -- Loop through bars. Search for
    // entirely array-based approach
    // in future version
    /* *******************
    Find main pivots
    ******************* */

    // -- Make sure there are enough bars!
    if (curBar >= nNumBarsToScan) {
    for (i=0; i<nNumBarsToScan; i++) {

    // -- value of curBar dependent on two parameters
    curBar = IIf(nlastVisBar > 0 AND bUseLastVis,
    nlastVisBar-i,
    IIf(Status("action")==4 AND nExploreBarIdx > 0,
    nExploreBarIdx-i,
    LastValue(BarIndex())-i));

    // -- Have we identified a pivot? If trend is down...
    if (aLLVBars[curBar] < aHHVBars[curBar]) {

    // ... and had been up, this is a trend change
    if (curTrend == "U") {
    curTrend = "D";
    // -- Capture pivot information
    curPivBarIdx = curBar - aLLVBars[curBar];
    aLPivs[curPivBarIdx] = 1;
    aLPivLows[nLPivs] = L[curPivBarIdx];
    aLPivIdxs[nLPivs] = curPivBarIdx;
    nLPivs++;
    }
    // -- or current trend is up
    } else {
    if (curTrend == "D") {
    curTrend = "U";
    curPivBarIdx = curBar - aHHVBars[curBar];
    aHPivs[curPivBarIdx] = 1;
    aHPivHighs[nHPivs] = H[curPivBarIdx];
    aHPivIdxs[nHPivs] = curPivBarIdx;
    nHPivs++;
    }
    // -- If curTrend is up...else...
    }

    // -- loop through bars
    }
    }
    /* *******************
    Found main pivots
    ******************* */

    /* *************************
    Finding missed pivot(s)
    ************************* */

    // -- Start at last bar. Reestablish curBar
    curBar =
    IIf(nlastVisBar > 0 AND bUseLastVis,
    nlastVisBar,
    IIf(Status("action")==4 AND nExploreBarIdx > 0,
    nExploreBarIdx,
    LastValue(BarIndex()))
    );

    // -- Make sure I found at least two of each above.
    if (nHPivs >= 2 AND nLPivs >= 2) {

    lastLPIdx = aLPivIdxs[0];
    lastLPL = aLPivLows[0];

    lastHPIdx = aHPivIdxs[0];
    lastHPH = aHPivHighs[0];

    nLastHOrLPivIdx = Max(lastLPIdx, lastHPIdx);

    nAddPivsRng = curBar - nLastHOrLPivIdx;
    aLLVAfterLastPiv = LLV(L, nAddPivsRng);
    nLLVAfterLastPiv = aLLVAfterLastPiv[curBar];
    aLLVIdxAfterLastPiv = LLVBars(L, nAddPivsRng);
    nLLVIdxAfterLastPiv = curBar - aLLVIdxAfterLastPiv[curBar];
    aHHVAfterLastPiv = HHV(H, nAddPivsRng);
    nHHVAfterLastPiv = aHHVAfterLastPiv[curBar];
    aHHVIdxAfterLastPiv = HHVBars(H, nAddPivsRng);
    nHHVIdxAfterLastPiv = curBar - aHHVIdxAfterLastPiv[curBar];

    // -- Later want to add last high pivot only if
    // not in buy mode from last and still in trade

    /*
    Note - I'm only interested in adding pivots if I'm in
    a higher-highs or lower-lows scenario
    */


    // -- OK, let's start where the last high pivot occurs after the
    // last Low pivot
    if (lastHPIdx > lastLPIdx) {

    /* There are at least two possibilities here. One is that
    the previous high was higher, indicating that this is a
    possible short retracement or one in the making.
    The other is that the previous high was lower, indicating
    that this is a possible long retracement in the working.
    However, both depend on opposing pivots. E.g., if I find
    higher highs, what if I have lower lows?

    If the highs are descending, then I can consider:
    - a lower low, and leave it at that
    - a higher high and higher low
    - a lower low and another lower high
    */
    if (aHPivHighs[0] < aHPivHighs[1]) {

    if (nLLVAfterLastPiv < aLPivLows[0] AND
    (nLLVIdxAfterLastPiv - lastHPIdx - 1) >= nMinBarsBtwPivs
    AND nLLVIdxAfterLastPiv != curBar ) {

    // -- OK, we'll add this as a pivot.
    // Mark it for plotting...
    aLPivs[nLLVIdxAfterLastPiv] = 1;
    aAddedLPivs[nLLVIdxAfterLastPiv] = 1;

    // ...and then rearrange elements in the
    // pivot information arrays
    for (j=0; j<nLPivs; j++) {
    aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
    aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
    }
    aLPivLows[0] = nLLVAfterLastPiv;
    aLPivIdxs[0] = nLLVIdxAfterLastPiv;
    nLPivs++;

    // -- Test whether to add piv given last piv is high
    // AND we have lower highs
    }

    // -- Here, the last piv is a high piv, and we have
    // higher-highs. The most likely addition is a
    // Low piv that is a retracement.
    } else {

    if (nLLVAfterLastPiv > aLPivLows[0] AND
    (nLLVIdxAfterLastPiv - lastHPIdx - 1) >= nMinBarsBtwPivs
    AND nLLVIdxAfterLastPiv != curBar ) {

    // -- OK, we'll add this as a pivot.
    // Mark it for plotting...
    aLPivs[nLLVIdxAfterLastPiv] = 1;
    aAddedLPivs[nLLVIdxAfterLastPiv] = 1;

    // ...and then rearrange elements in the
    // pivot information arrays
    for (j=0; j<nLPivs; j++) {
    aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
    aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
    }
    aLPivLows[0] = nLLVAfterLastPiv;
    aLPivIdxs[0] = nLLVIdxAfterLastPiv;
    nLPivs++;

    // -- Test whether to add piv given last piv is high
    // AND we have lower highs
    }
    // -- The last piv is a high and we have higher highs
    // OR lower highs
    }

    /* ************************************************** **************
    Still finding missed pivot(s). Here, the last piv is a low piv.
    ************************************************** ************** */
    } else {

    // -- First case, lower highs
    if (aHPivHighs[0] < aHPivHighs[1]) {

    if (nHHVAfterLastPiv < aHPivHighs[0] AND
    (nHHVIdxAfterLastPiv - lastLPIdx - 1) >= nMinBarsBtwPivs
    AND nHHVIdxAfterLastPiv != curBar ) {

    // -- OK, we'll add this as a pivot.
    // Mark that for plotting
    aHPivs[nHHVIdxAfterLastPiv] = 1;
    aAddedHPivs[nHHVIdxAfterLastPiv] = 1;

    // ...and then rearrange elements in the
    // pivot information arrays
    for (j=0; j<nHPivs; j++) {
    aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-(j+1)];
    aHPivIdxs[nHPivs-j] = aHPivIdxs[nhPivs-(j+1)];
    }
    aHPivHighs[0] = nHHVAfterLastPiv;
    aHPivIdxs[0] = nHHVIdxAfterLastPiv;
    nHPivs++;

    // -- Test whether to add piv given last piv is high
    // AND we have lower highs
    }

    // -- Second case when last piv is a low piv, higher highs
    // Most likely addition is high piv that is a retracement.
    // Considering adding a high piv as long as it is higher
    } else {

    // -- Where I have higher highs,
    if (nHHVAfterLastPiv > aHPivHighs[0] AND
    (nHHVIdxAfterLastPiv - lastLPIdx - 1) >= nMinBarsBtwPivs
    AND nHHVIdxAfterLastPiv != curBar ) {

    // -- OK, we'll add this as a pivot.
    // Mark it for plotting...
    aHPivs[nHHVIdxAfterLastPiv] = 1;
    aAddedHPivs[nHHVIdxAfterLastPiv] = 1;

    // ...and then rearrange elements in the
    // pivot information arrays
    for (j=0; j<nHPivs; j++) {
    aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-(j+1)];
    aHPivIdxs[nHPivs-j] = aHPivIdxs[nhPivs-(j+1)];
    }
    aHPivHighs[0] = nHHVAfterLastPiv;
    aHPivIdxs[0] = nHHVIdxAfterLastPiv;
    nHPivs++;

    // -- Test whether to add piv given last piv is high
    // AND we have lower highs
    }

    }

    }

    // -- If there are at least two of each
    }

    /* ****************************************
    // -- Done with finding pivots
    ***************************************** */

    if (bDraw) {

    // -- OK, let's plot the pivots using arrows
    PlotShapes(
    IIf(aHPivs==1, shapeDownArrow, shapeNone),
    colorRed, 0, High, Offset=-15);
    PlotShapes(
    IIf(aAddedHPivs==1, shapeDownArrow, shapeNone),
    colorBrown, 0, High, Offset=-15);
    PlotShapes(
    IIf(aLPivs==1, shapeUpArrow , shapeNone),
    colorGreen, 0, Low, Offset=-15);
    PlotShapes(
    IIf(aAddedLPivs==1, shapeUpArrow , shapeNone),
    colorBlue, 0, Low, Offset=-15);
    }
    Filter = shapeDownArrow OR shapeDownArrow;

    /* ****************************************
    // -- Done with discovering and plotting pivots
    ***************************************** */
    _SECTION_END();
     
  7. vinodkiyer

    vinodkiyer Well-Known Member

    Joined:
    Feb 2, 2009
    Messages:
    352
    Likes Received:
    418
    Trophy Points:
    63
    Hi amit, attached pls find the afl with scan and explorer. Pls note in Explore The Red "P" stands for low Pivot and Green P Stands for High Pivot while B stands for low Pivot and Red S stands for High Pivot
     
    Last edited: Jan 15, 2010
    amit_k2100 likes this.
  8. amit_k2100

    amit_k2100 Member

    Joined:
    Nov 20, 2009
    Messages:
    178
    Likes Received:
    21
    Trophy Points:
    18
    hey vinod ji.......thnx a lot for such a prompt reply :clapping:....now its working for both....realy appreciate for ur help:clap:...thnx again.... can u help me some more in learning also....actualy i m a new learner.....i take as scan nd exploration ...more of same...can u tell me the diffrence between them...nd how to make correct use.....
    also i am looking for an intra afl with good accuracy...do u have any or u can help me in some way.....if i give u few condtions can u make an afl for that....thnx again....
     
  9. vinodkiyer

    vinodkiyer Well-Known Member

    Joined:
    Feb 2, 2009
    Messages:
    352
    Likes Received:
    418
    Trophy Points:
    63
    scanning gives u only buy short signals while exploration can give u any sort of filters u may write in the afl. tell me the conditions
     
  10. amit_k2100

    amit_k2100 Member

    Joined:
    Nov 20, 2009
    Messages:
    178
    Likes Received:
    21
    Trophy Points:
    18
    hey vindo ji thnx again:thanx:....u have been realy nice..to help....ok.the comdtions are i have heard that 3 indictors r good for intraday trdng , rsi , macd , moving ave , so i would like that someone can write a formula on these.

    BUY signal when all theses 3 condtions satisfied=

    1) rsi below 30
    2) macd buy signal above zero
    3) 20 day moving average( or 20 intraday bars since its intraday) holds or if trdng below it then on its crossover

    SELL signal=

    1)rsi above 70
    2)macd sel signal below 0
    3)20 day moving averges breaks


    vinod ji i m not sure whether i am even right on the condtions or no...if i am wrong plz correct me or else u can advice somethng else....by the way are u on yahoo messneger also ?
     

Share This Page