![]() |
|
| Discuss Need Help with this AFL at the AmiBroker within the Traderji.com - Discussion forum for Stocks Commodities & Forex; Thanks Deedeed Will take a closer look after mkt hrs. Regards, Kalyan.... |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools |
| Sponsored Links |
|
#11
|
|||
|
|||
|
Thanks Deedeed Will take a closer look after mkt hrs.
Regards, Kalyan. |
| Sponsored Links |
|
#12
|
|||
|
|||
|
Hi Ashutosh,
Seems to be working perfect now. will keep watching for a couple of days and will ping you with the results. cheers deedeed. |
|
#13
|
|||
|
|||
|
HI ASHUTOSH & DEEDEED
Following is the AFL for ploting Pivot points on the chart. However, I need the value and no. of bars from last close of last 2 pivot highs and last 2 pivot lows. Can u help me please . I am attaching a chart indicating requirements ::::: _SECTION_BEGIN("Pivots"); // -- what will be our lookback range for the hh and ll? farback= Param("How Far back to go",100,50,5000,10); nBars = Param("Number of bars", 12, 5, 40); // -- Plot basic candle chart PlotOHLC(Open, High, Low, Close, "BIdx = " + BarIndex() + "\n" + "O = " + O + ", H = "+ H + ", L = " + L + ", C ", colorBlack, styleCandle); GraphXSpace=7; // -- Create 0-initialized arrays the size of barcount aHPivs = H - H; aLPivs = L - L; // -- More for future use, not necessary for basic plotting aHPivHighs = H - H; aLPivLows = L - L; aHPivIdxs = H - H; aLPivIdxs = L - L; 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); // -- Would like to set this up so pivots are calculated back from // last visible bar to make it easy to "go back" and see the pivots // this code would find. However, the first instance of // _Trace output will show a value of 0 aVisBars = Status("barvisible"); nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0))); _TRACE("Last visible bar: " + nLastVisBar); // -- Initialize value of curTrend curBar = (BarCount-1); curTrend = ""; if (aLLVBars[curBar] < aHHVBars[curBar]) { curTrend = "D"; } else { curTrend = "U"; } // -- Loop through bars. Search for // entirely array-based approach // in future version for (i=0; i<farback; i++) { curBar = (BarCount - 1) - 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 } // -- Basic attempt to add a pivot this logic may have missed // -- OK, now I want to look at last two pivots. If the most // recent low pivot is after the last high, I could // still have a high pivot that I didn't catch // -- Start at last bar curBar = (BarCount-1); candIdx = 0; candPrc = 0; lastLPIdx = aLPivIdxs[0]; lastLPL = aLPivLows[0]; lastHPIdx = aHPivIdxs[0]; lastHPH = aHPivHighs[0]; if (lastLPIdx > lastHPIdx) { // -- Bar and price info for candidate pivot candIdx = curBar - aHHVBars[curBar]; candPrc = aHHV[curBar]; if ( lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar) { // -- OK, we'll add this as a pivot... aHPivs[candIdx] = 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] = candPrc ; aHPivIdxs[0] = candIdx; nHPivs++; } } else { // -- Bar and price info for candidate pivot candIdx = curBar - aLLVBars[curBar]; candPrc = aLLV[curBar]; if ( lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar) { // -- OK, we'll add this as a pivot... aLPivs[candIdx] = 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] = candPrc; aLPivIdxs[0] = candIdx; nLPivs++; } } // -- Dump inventory of high pivots for debugging /* for (k=0; k<nHPivs; k++) { _TRACE("High pivot no. " + k + " at barindex: " + aHPivIdxs[k] + ", " + WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k], DateTime(), 1), formatDateTime) + ", " + aHPivHighs[k]); } */ // -- OK, let's plot the pivots using arrows PlotShapes( IIf(aHPivs==1, shapeDownArrow, shapeNone), colorRed, 0, High, Offset=-15); PlotShapes( IIf(aLPivs==1, shapeUpArrow , shapeNone), colorGreen, 0, Low, Offset=-15); ////////////////////////// _SECTION_END(); I think u can get these values & no of bars from latest close (Pivot highs & lows ) from text marked red & green. But how, I dont know. Can u help me please. see attached chart. regards Ajax Last edited by Ajax; 22nd October 2008 at 10:52 PM. |
|
#14
|
|||
|
|||
|
Hi Ajax,
try this. Code:
GraphXSpace = 20;
dist = 1.1*ATR(20);
for(m=0;m<=BarCount-1;m++){
if(aHPivs[m] == 1)PlotText("" + (BarCount - m - 1), m, H[m]+dist[m],colorBlack);
if(aLPivs[m] == 1)PlotText("" + (BarCount - m - 1), m, L[m]-dist[m], colorBlack);
}
Code:
GraphXSpace = 20;
dist = 1.1*ATR(20);
for(m=0;m<=BarCount-1;m++){
if(aHPivs[m] == 1)PlotText("" + (BarCount - m - 1) + "C" + C[m], m, H[m]+dist[m],colorBlack);
if(aLPivs[m] == 1)PlotText("" + (BarCount - m - 1) + "C" + C[m], m, L[m]-dist[m], colorBlack);
}
Last edited by ashutosh.krsrivastava; 11th March 2008 at 10:34 AM. Reason: replaced C by c[m] |
|
#15
|
|||
|
|||
|
Hi Aushotosh
Thanx a ton for the formula. It really shows nicely on the charts the desired values... Now a step further... Need to build a Automatic analysis query Need values of last 2 Pivot tops & last 2 Pivot Lows T1 = Last Pivot high T2 = Previous Pivot high (before T1) B1 = Last Pivot low B2 = Previous Pivot low (before B1) Buy = Close > T1 and T1 > T2 and B1 > B2 Sell = Close < B1 I think from code u gave us, its possible to extract these values Please help Regards PS: I will post this as AFL. Also see attached chart Last edited by Ajax; 22nd October 2008 at 10:52 PM. |
|
#16
|
|||
|
|||
|
Quote:
I am adding the Analysis AFL . Please help... ////////////////////// >>>>>>> // -- what will be our lookback range for the hh and ll? farback= 70 ; //Param("How Far back to go",100,50,5000,10); nBars = Param("Number of bars", 12, 5, 40); // -- Plot basic candle chart PlotOHLC(Open, High, Low, Close, "BIdx = " + BarIndex() + "\n" + "O = " + O + ", H = "+ H + ", L = " + L + ", C ", colorBlack, styleCandle); GraphXSpace=7; // -- Create 0-initialized arrays the size of barcount aHPivs = H - H; aLPivs = L - L; // -- More for future use, not necessary for basic plotting aHPivHighs = H - H; aLPivLows = L - L; aHPivIdxs = H - H; aLPivIdxs = L - L; 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); // -- Would like to set this up so pivots are calculated back from // last visible bar to make it easy to "go back" and see the pivots // this code would find. However, the first instance of // _Trace output will show a value of 0 aVisBars = Status("barvisible"); nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0))); _TRACE("Last visible bar: " + nLastVisBar); // -- Initialize value of curTrend curBar = (BarCount-1); curTrend = ""; if (aLLVBars[curBar] < aHHVBars[curBar]) { curTrend = "D"; } else { curTrend = "U"; } // -- Loop through bars. Search for // entirely array-based approach // in future version for (i=0; i<farback; i++) { curBar = (BarCount - 1) - 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 } // -- Basic attempt to add a pivot this logic may have missed // -- OK, now I want to look at last two pivots. If the most // recent low pivot is after the last high, I could // still have a high pivot that I didn't catch // -- Start at last bar curBar = (BarCount-1); candIdx = 0; candPrc = 0; lastLPIdx = aLPivIdxs[0]; lastLPL = aLPivLows[0]; lastHPIdx = aHPivIdxs[0]; lastHPH = aHPivHighs[0]; if (lastLPIdx > lastHPIdx) { // -- Bar and price info for candidate pivot candIdx = curBar - aHHVBars[curBar]; candPrc = aHHV[curBar]; if ( lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar) { // -- OK, we'll add this as a pivot... aHPivs[candIdx] = 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] = candPrc ; aHPivIdxs[0] = candIdx; nHPivs++; } } else { // -- Bar and price info for candidate pivot candIdx = curBar - aLLVBars[curBar]; candPrc = aLLV[curBar]; if ( lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar) { // -- OK, we'll add this as a pivot... aLPivs[candIdx] = 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] = candPrc; aLPivIdxs[0] = candIdx; nLPivs++; } } // -- Dump inventory of high pivots for debugging /* for (k=0; k<nHPivs; k++) { _TRACE("High pivot no. " + k + " at barindex: " + aHPivIdxs[k] + ", " + WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k], DateTime(), 1), formatDateTime) + ", " + aHPivHighs[k]); } */ // -- OK, let's plot the pivots using arrows PlotShapes( IIf(aHPivs==1, shapeDownArrow, shapeNone), colorRed, 0, High, Offset=-15); PlotShapes( IIf(aLPivs==1, shapeUpArrow , shapeNone), colorGreen, 0, Low, Offset=-15); //........... GraphXSpace = 20; dist = 1.1*ATR(20); for(m=0;m<=BarCount-1;m++){ if(aHPivs[m] == 1)PlotText("" + (BarCount - m - 1), m, H[m]+dist[m],colorBlack); if(aLPivs[m] == 1)PlotText("" + (BarCount - m - 1), m, L[m]-dist[m], colorBlack); } GraphXSpace = 20; dist = 1.1*ATR(20); for(m=0;m<=BarCount-1;m++){ if(aHPivs[m] == 1)PlotText("" + (BarCount - m - 1) + "H" + C[m], m, H[m]+dist[m],colorBlack); if(aLPivs[m] == 1)PlotText("" + (BarCount - m - 1) + "L" + C[m], m, L[m]-dist[m], colorBlack); } //////////////// T1 = ? ; // Last Pivot High ; T2 = ? ; // Previous Pivot High (before T1) B1 = ? ; // Last Pivot Low B2 = ? ; // Previous Pivot Low (before B1) Buy = Close > T1 AND T1 > T2 AND B1 > B2 ; Sell = Close < B1 ; |
|
#17
|
|||
|
|||
|
Hi Ajax,
Remove the previous code and add this instead: Code:
GraphXSpace = 20;
dist = 1.1*ATR(20);
T1 = 0; T2 = 0; B1 = 0; B2 = 0;
for(m=0;m<=BarCount-1;m++){
if(aHPivs[m] == 1){
PlotText("" + (BarCount - m - 1)+ "C" + C[m], m, H[m]+dist[m],colorBlack);
if (T1 != 0) T2 = T1;
T1 = H[m];
}
if(aLPivs[m] == 1){
PlotText("" + (BarCount - m - 1)+ "C" + C[m], m, L[m]-dist[m], colorBlack);
if(B1!=0) B2 = B1;
B1 = L[m];
}
}
Buy = C > T1 AND T1 > T2 AND B1 > B2 ;
Sell = C < B1 ;
|
|
#18
|
|||
|
|||
|
Quote:
Excellent Coding. Hello Ajax, Besides using HHV / LLV (as you have done) for the plotting of the pivot points we can also use zigzag function. If you have tried coding patterns like 3BR, you can use similar code for marking PPs, will post the code after mrkts. Overall a very nice effort, keep plugging. Regards Sanjay Code:
_SECTION_BEGIN("Plot-Pivots");
change = Param("% change",0.05,0.1,25,0.05);
ZigZArray = Zig(C, change);
j = k = PH[0] = PL[0] = 0;
for( i = 1; i < BarCount-1; i++ )
{
if (ZigZArray[i] < ZigZArray[i-1] AND ZigZArray[i] < ZigZArray[i+1])
{
if (PL[k] > ZigZArray[i])
{
PlotText("LL",i, L[i]-5, colorLime);
}
else
{
PlotText("HL",i, L[i]-5, colorBlueGrey);
}
k = k + 1;
PL[k] = ZigZArray[i];
}
if (ZigZArray[i] > ZigZArray[i-1] AND ZigZArray[i] > ZigZArray[i+1])
{
if (PH[j] < ZigZArray[i])
{
PlotText("HH", i, H[i]+5, colorBlueGrey);
}
else
{
PlotText("LH", i, H[i]+5, colorLime);
}
j = j + 1;
PH[j] = ZigZArray[i];
}
}
_SECTION_END();
Last edited by SGM; 12th March 2008 at 03:29 PM. Reason: Attached Code |
|
#19
|
|||
|
|||
|
Quote:
Tried to run the automatic analysis with Pivot code + above code. Its giving following error: Line 111 column 20..Error 10 Subscript out of range. You must not access array elements outside 0..(Barcount-1) range. It seems program does not run beyond Line 111 because of this error. I am totally ignorant about how to program. Ashutosh u have to bail us out. Waiting for u to fix this problem Regards Ajax |
|
#20
|
|||
|
|||
|
Quote:
I know very little about the program. I picked this Pivot AFL from AMibroker library. It shows very nicely on charts, even better with Ashutosh/s code. But I wish to run automatic analysis with this AFL with Buy & Sell arguements as given earlier.. Hope u can help Regards Ajax |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Indemnity, Disclaimer & Disclosure
Notice:
• By visiting Traderji.com you indicate your acceptance of our Forum
Rules Disclaimer & Disclosure and indemnify Traderji.com, its
associates and related parties of all claims howsoever resulting from
the usage of the forum.
• Disclaimer: Trading or investing in stocks & commodities
is a high risk activity. Any action you choose to take in the markets
is totally your own responsibility. Traderji.com will not be liable for
any, direct or indirect, consequential or incidental damages or loss arising out of the use of this information.
• Disclosure: The information in this forum is neither an offer to sell nor solicitation to buy any of the securities mentioned herein.
The writers may or may not be trading in the securities mentioned.
• All names or products mentioned are trademarks or registered trademarks of their respective owners.
General Content Disclaimer Notice:
In light of our policy of encouraging candid, open exchanges of views and the rapid distribution of information originating from many sources, Traderji.com cannot determine the accuracy of information that may be uploaded to the forum. Opinions, advice and all other information expressed by participants in discussions are those of the author. You rely on such information at your own risk. You are urged to seek professional advice for specific, individual situations and not rely solely on advice or opinions given in the discussions. Since Traderji.com is an open and free discussion forum, any comments made by members of this forum in their posts reflect their own views and not of the owner or administrator of Traderji.com. Thus the owner/administrator indemnify themselves of all claims whatsoever and will not be liable or responsible for any members comments/views in this forum Traderji.com. If you find any objectionable or offensive posts made by members of this forum which you would like to bring to our notice for removal then please Contact Us.