Fibonacci Ratracements for Amibroker
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);
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[i];
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);
if (bDraw) {
Plot(MA(C, 21), "21 bar MA", colorAqua,
styleLine+styleNoRescale+styleNoLabel);
Plot(MA(C, 55), "55 bar MA", colorGreen,
styleLine+styleNoRescale+styleNoLabel);
//Plot(MA(C, 233), "233 bar MA", colorDarkRed,
// styleLine+styleNoRescale+styleNoLabel);
}
// -- 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),
colorDarkRed, 0, High, Offset=-15);
PlotShapes(
IIf(aLPivs==1, shapeUpArrow , shapeNone),
colorGreen, 0, Low, Offset=-15);
PlotShapes(
IIf(aAddedLPivs==1, shapeUpArrow , shapeNone),
colorDarkGreen, 0, Low, Offset=-15);
}
/* ****************************************
// -- Done with discovering and plotting pivots
***************************************** */
// -- I'm going to want to look for possible retracement
risk = 0;
profInc = 0;
nLeg0Pts = 0;
nLeg0Bars = 0;
nLeg0Vol = 0;
nLeg1Pts = 0;
nLeg1Bars = 0;
nLeg1Vol = 0;
nLegBarsDiff = 0;
nRtrc0Pts = 0;
nRtrc0Bars = 0;
nRtrc0Vol = 0;
nRtrc1Pts = 0;
nRtrc1Bars = 0;
nRtrc1Vol = 0;
minRtrc = 0;
maxRtrc = 0;
minLine = 0;
maxLine = 0;
triggerLine = 0;
firstProfitLine = 0;
triggerInc = 0;
triggerPrc = 0;
firstProfitPrc = 0;
retrcPrc = 0;
retrcBar = 0;
retrcBarIdx = 0;
retrcRng = 0;
aRetrcPrc = H-H;
aRetrcPrcBars = H-H;
aRetrcClose = C;
retrcClose = 0;
// -- Do TCZ calcs. Arrangement of pivs very specific
// for this setup.
if (nHPivs >= 2 AND
nLPivs >=2 AND
aHPivHighs[0] > aHPivHighs[1] AND
aLPivLows[0] > aLPivLows[1]) {
tcz500 =
(aHPivHighs[0] -
(.5 * (aHPivHighs[0] - aLPivLows[1])));
tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[0] - aLPivLows[1])));
tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));
retrcRng = curBar - aHPivIdxs[0];
aRetrcPrc = LLV(L, retrcRng);
retrcPrc = aRetrcPrc[curBar];
aRetrcPrcBars = LLVBars(L, retrcRng);
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];
// -- bTCZLong setup?
bTCZLong = (
// -- Are retracement levels arranged in
// tcz order?
tcz500 >= (tcz786 * (1 - tczTolerance))
AND
// .681 is below .786 for long setups
tcz618 <= (tcz786 * (1 + tczTolerance))
AND
// -- Is the low in the tcz range
// -- Is the close >= low of tcz range
// and low <= high of tcz range
retrcClose >= ((1 - retrcTolerance) * tcz618)
AND
retrcPrc <= ((1 + retrcTolerance) * tcz500)
);
// -- risk would be high of signal bar minus low of zone
//risk = 0;
// -- lower highs and lower lows
} else if (nHPivs >= 2 AND nLPivs >=2
AND aHPivHighs[0] < aHPivHighs[1]
AND aLPivLows[0] < aLPivLows[1]) {
tcz500 =
(aHPivHighs[1] -
(.5 * (aHPivHighs[1] - aLPivLows[0])));
tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[1] - aLPivLows[0])));
tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));
retrcRng = curBar - aLPivIdxs[0];
aRetrcPrc = HHV(H, retrcRng);
retrcPrc = aRetrcPrc[curBar];
aRetrcPrcBars = HHVBars(H, retrcRng);
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];
bTCZShort = (
// -- Are retracement levels arranged in
// tcz order?
// .500 is below .786 for short setups
tcz500 <= (tcz786 * (1 + tczTolerance))
AND
// .681 is above .786 for short setups
tcz618 >= (tcz786 * (1 - tczTolerance))
AND
// -- Is the close <= high of tcz range
// and high >= low of tcz range
retrcClose <= ((1 + retrcTolerance) * tcz618)
AND
retrcPrc >= ((1 - retrcTolerance) * tcz500)
);
// -- Risk would be top of zone - low of signal bar
//risk = 0;
}
Filter = (bTCZShort OR bTCZLong);
AddColumn(C, "Close");
AddColumn(IIf(bTCZLong, 76, 83), "L/S", formatChar);
// **************************
// END EXPLORATION CODE
// **************************
// **************************
// BEGIN INDICATOR CODE
// **************************
// -- 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[i];
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);
if (bDraw) {
Plot(MA(C, 21), "21 bar MA", colorAqua,
styleLine+styleNoRescale+styleNoLabel);
Plot(MA(C, 55), "55 bar MA", colorGreen,
styleLine+styleNoRescale+styleNoLabel);
//Plot(MA(C, 233), "233 bar MA", colorDarkRed,
// styleLine+styleNoRescale+styleNoLabel);
}
// -- 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
}
}
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];
if (lastHPIdx > lastLPIdx) {
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++;
}
} 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++;
}
}
} 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;
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++;
}
} else {
if (nHHVAfterLastPiv > aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= nMinBarsBtwPivs
AND nHHVIdxAfterLastPiv != curBar ) {
aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 1;
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++;
}
}
}
}
if (bDraw) {
PlotShapes(
IIf(aHPivs==1, shapeDownArrow, shapeNone),
colorRed, 0, High, Offset=-15);
PlotShapes(
IIf(aAddedHPivs==1, shapeDownArrow, shapeNone),
colorDarkRed, 0, High, Offset=-15);
PlotShapes(
IIf(aLPivs==1, shapeUpArrow , shapeNone),
colorGreen, 0, Low, Offset=-15);
PlotShapes(
IIf(aAddedLPivs==1, shapeUpArrow , shapeNone),
colorDarkGreen, 0, Low, Offset=-15);
}
risk = 0;
profInc = 0;
nLeg0Pts = 0;
nLeg0Bars = 0;
nLeg0Vol = 0;
nLeg1Pts = 0;
nLeg1Bars = 0;
nLeg1Vol = 0;
nLegBarsDiff = 0;
nRtrc0Pts = 0;
nRtrc0Bars = 0;
nRtrc0Vol = 0;
nRtrc1Pts = 0;
nRtrc1Bars = 0;
nRtrc1Vol = 0;
minRtrc = 0;
maxRtrc = 0;
minLine = 0;
maxLine = 0;
triggerLine = 0;
firstProfitLine = 0;
triggerInc = 0;
triggerPrc = 0;
firstProfitPrc = 0;
retrcPrc = 0;
retrcBar = 0;
retrcBarIdx = 0;
retrcRng = 0;
aRetrcPrc = H-H;
aRetrcPrcBars = H-H;
aRetrcClose = C;
retrcClose = 0;
if (nHPivs >= 2 AND
nLPivs >=2 AND
aHPivHighs[0] > aHPivHighs[1] AND
aLPivLows[0] > aLPivLows[1]) {
tcz500 =
(aHPivHighs[0] -
(.5 * (aHPivHighs[0] - aLPivLows[1])));
tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[0] - aLPivLows[1])));
tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));
retrcRng = curBar - aHPivIdxs[0];
aRetrcPrc = LLV(L, retrcRng);
aRetrcPrcBars = LLVBars(L, retrcRng);
retrcPrc = aRetrcPrc[curBar];
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];
bTCZLong = (
tcz500 >= (tcz786 * (1 - tczTolerance))
AND
tcz618 <= (tcz786 * (1 + tczTolerance))
AND
retrcClose >= ((1 - retrcTolerance) * tcz618)
AND
retrcPrc <= ((1 + retrcTolerance) * tcz500)
);
} else if (nHPivs >= 2 AND nLPivs >=2
AND aHPivHighs[0] < aHPivHighs[1]
AND aLPivLows[0] < aLPivLows[1]) {
tcz500 =
(aHPivHighs[1] -
(.5 * (aHPivHighs[1] - aLPivLows[0])));
tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[1] - aLPivLows[0])));
tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));
retrcRng = curBar - aLPivIdxs[0];
aRetrcPrc = HHV(H, retrcRng);
retrcPrc = aRetrcPrc[curBar];
aRetrcPrcBars = HHVBars(H, retrcRng);
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];
bTCZShort = (
tcz500 <= (tcz786 * (1 + tczTolerance))
AND
tcz618 >= (tcz786 * (1 - tczTolerance))
AND
retrcClose <= ((1 + retrcTolerance) * tcz618)
AND
retrcPrc >= ((1 - retrcTolerance) * tcz500)
);
}
if (bTCZShort OR bTCZLong) {
if (bTCZShort) {
if (aLPivIdxs[0] > aHPivIdxs[0]) {
nRtrc0Pts = aHPivHighs[0] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[0] - aLPivIdxs[1] + 1;
nRtrc1Pts = retrcPrc - aLPivLows[0];
nRtrc1Bars = retrcBarIdx - aLPivIdxs[0] + 1;
} else {
nRtrc0Pts = aHPivHighs[1] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[1] - aLPivIdxs[1] + 1;
nRtrc1Pts = aHPivHighs[0] - aLPivLows[0];
nRtrc1Bars = aHPivIdxs[0] - aLPivIdxs[0] + 1;
}
} else {
if (aLPivIdxs[0] > aHPivIdxs[0]) {
nRtrc0Pts = aHPivHighs[0] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[0] - aLPivIdxs[1] + 1;
nRtrc1Pts = retrcPrc - aLPivLows[0];
nRtrc1Bars = retrcBarIdx - aLPivIdxs[0] + 1;
} else {
nRtrc0Pts = aHPivHighs[1] - aLPivLows[0];
nRtrc0Bars = aLPivIdxs[0] - aHPivIdxs[1] + 1;
nRtrc1Pts = aHPivHighs[0] - aLPivLows[0];
nRtrc1Bars = aLPivIdxs[0] - aHPivIdxs[0] + 1;
}
}
if (bShowTCZ) {
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz500, curBar, tcz500 , 0),
"tcz500", colorPaleBlue, styleLine);
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz618, curBar, tcz618, 0),
"tcz618", colorPaleBlue, styleLine);
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz786, curBar, tcz786, 0),
"tcz786", colorTurquoise, styleLine);
}
}
if (bDraw) {
Title = Name() + " (" + StrLeft(FullName(), 10) +
") ATR: " + NumToStr(ATR(1), 4.2) + " ( " +
NumToStr((C - Ref(C, -1)), 4.2) + " / " +
NumToStr((((C - Ref(C, -1)) / Ref(C, -1)) * 100), 2.1) + "% ) " +
WriteVal( SelectedValue( DateTime() ), formatDateTime) +
" \nO: " + Open +
", \nH: " + High +
", \nL: " + Low +
", \nC: " + Close + ", \n" +
"Rtrc 0/1 Pts: " + WriteVal(nRtrc0Pts, 2.1) + "/" +
WriteVal(nRtrc1Pts, 2.1) + " \n" +
"Rtrc 0/1 Bars: " + WriteVal(nRtrc0Bars, 2.0) + "/" +
WriteVal(nRtrc1Bars, 2.0);
}
// **************************
// END INDICATOR CODE
// **************************
Friday, 27 February 2015
Volatility Stop Afl For Amibroker
Volatility Stop Afl
_SECTION_BEGIN("Volatility Stop");
k=Param("multiplication factor", 1,0.5,5,0.1);
period=k*9;
VS_raw = 2.5 * EMA(ATR(1), period);
loline = VS_below_price = HHV(Close, period) - VS_raw;
hiline = VS_above_price = LLV(Close, period) + VS_raw;
between = IIf (C < hiline AND C > loline, 1, 0);
up = IIf(C > hiline OR (H > Ref(H, -1) AND H > hiline), 1, 0);
dn = IIf(C < loline OR (L < Ref(L, -1) AND L < loline), 1, 0);
upcond = IIf(between AND BarsSince(up) < BarsSince(dn) , 1, 0);
dncond = IIf(between AND BarsSince(dn) < BarsSince(up) , 1, 0);
upline = IIf(up OR upcond, loline, Null);
dnline = IIf(dn OR dncond, hiline, Null);
Plot(C, "", colorLightGrey, styleBar);
Plot(upline, "", colorRed, styleStaircase) ;
Plot(dnline, "", colorGreen, styleStaircase) ;
Buy=upline;
Sell=dnline;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PlotShapes(Buy*shapeUpArrow,colorGreen);
PlotShapes(Sell*shapeDownArrow,colorRed);
_SECTION_BEGIN("Volatility Stop");
k=Param("multiplication factor", 1,0.5,5,0.1);
period=k*9;
VS_raw = 2.5 * EMA(ATR(1), period);
loline = VS_below_price = HHV(Close, period) - VS_raw;
hiline = VS_above_price = LLV(Close, period) + VS_raw;
between = IIf (C < hiline AND C > loline, 1, 0);
up = IIf(C > hiline OR (H > Ref(H, -1) AND H > hiline), 1, 0);
dn = IIf(C < loline OR (L < Ref(L, -1) AND L < loline), 1, 0);
upcond = IIf(between AND BarsSince(up) < BarsSince(dn) , 1, 0);
dncond = IIf(between AND BarsSince(dn) < BarsSince(up) , 1, 0);
upline = IIf(up OR upcond, loline, Null);
dnline = IIf(dn OR dncond, hiline, Null);
Plot(C, "", colorLightGrey, styleBar);
Plot(upline, "", colorRed, styleStaircase) ;
Plot(dnline, "", colorGreen, styleStaircase) ;
Buy=upline;
Sell=dnline;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PlotShapes(Buy*shapeUpArrow,colorGreen);
PlotShapes(Sell*shapeDownArrow,colorRed);
Thursday, 26 February 2015
Simple Trading Signal
Simple Trading Signal
_SECTION_BEGIN("Simple Trading Signal");
range = Param("Periods", 2, 2, 50, 1 );
p=PDI(range);
pbuy = Param("Buy if +DI <", 15, 5, 25, 1 );
psell = Param("Sell if +DI >", 45, 25, 75, 1 );
Buy = p > Ref(p,-1) AND Ref(p,-1) < Ref(p,-2) AND Ref(p,-1) < pbuy ;
Sell = p < Ref(p,-1) AND Ref(p,-1) > Ref(p,-2) AND Ref(p,-1) > psell ;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Plot(C,"",colorWhite,64);
PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Low,Offset=-20);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High,Offset=-20);
_SECTION_END();
_SECTION_BEGIN("Simple Trading Signal");
range = Param("Periods", 2, 2, 50, 1 );
p=PDI(range);
pbuy = Param("Buy if +DI <", 15, 5, 25, 1 );
psell = Param("Sell if +DI >", 45, 25, 75, 1 );
Buy = p > Ref(p,-1) AND Ref(p,-1) < Ref(p,-2) AND Ref(p,-1) < pbuy ;
Sell = p < Ref(p,-1) AND Ref(p,-1) > Ref(p,-2) AND Ref(p,-1) > psell ;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Plot(C,"",colorWhite,64);
PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Low,Offset=-20);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High,Offset=-20);
_SECTION_END();
All-In-One for Amibroker (AFL) Pivot Trading
All-In-One for Amibroker (AFL) Pivot Trading
_SECTION_BEGIN("Main");
pivotCalc = ParamList("Pivot Calculation", "Suryo|FB", 0);
rulesSuryo=ParamList("Suryo Rules","Enable|Disable",0);
rulesFB=ParamList("FB Rules","Enable|Disable",1);
rulesGado2=ParamList("Gado-Gado Rules","Enable|Disable",1);
speculativeBuyArrow=ParamList("Speculative Buy Arrow","Enable|Disable",1);
buyArrow=ParamList("Buy Arrow","Enable|Disable",0);
sellArrow=ParamList("Sell Arrow","Enable|Disable",0);
nPivot = Param("Jumlah Tangga Merah", 1, 1, 20);
pivotUpColor=ParamColor("Pivot Up Color", colorGreen );
pivotDownColor=ParamColor("Pivot Down Color", colorRed );
arrowSuryoColor=ParamColor("Arrow Suryo Color", colorRed );
arrowFBColor=ParamColor("Arrow FB Color", colorBlue );
arrowGado2Color=ParamColor("Arrow Gado-Gado Color", colorGreen );
_SECTION_END();
Plot(C,"C",colorBlack,styleCandle); //Plot bar harga
if(pivotCalc == "Suryo")//Kalau Pivot Calculation: Suryo
{
// tentukan Pivot berdasarkan data kemarin
P = (H+L+C) / 3;
}
else //Kalau Pivot Calculation: FB
{
// tentukan Pivot berdasarkan data kemarin
// asumsi C=O, define P
P =(H+L+2*C)/4;
// if C>O define new P, otherwise use P above
P = IIf(C>O,(2*H+L+C)/4, P);
// if C<O define new P, otherwise use P above
P = IIf(C<O,(H+2*L+C)/4, P);
};//end PivotCalc
//berapa tangga merah sebelum boleh ada sinyal beli?
tanggaMerah=1;
for( i = 0; i < nPivot; i++ )
{
tanggaMerah= Ref(P,-1*i-1) <Ref(P,-1*i-2) AND tanggaMerah;
} ;//end berapa tangga merah sebelum boleh ada sinyal beli
//Hitung S dan R
R1= (P * 2) - L;
S1= (P * 2) - H;
R2 = P + (R1 - S1); // P + (H - L)
S2 = P - (R1 - S1); // P - (H - L)
R3 = H + 2*(P - L);
S3 = L - 2*(H - P);
//Plot SRP
Displace=1;
Plot(R3,"R3",colorRed,styleDots|styleNoLine,0,0,Displace);
Plot(R2,"R2",colorRed,styleDots|styleNoLine,0,0,Displace);
Plot(R1,"R1",colorRed,styleDots|styleNoLine,0,0,Displace);
Plot(P,"P",IIf( Ref(p,0)>Ref(p,-1), pivotUpColor, pivotDownColor ), styleStaircase,0,0,Displace);
Plot(S1,"S1",colorGreen,styleDots|styleNoLine,0,0,Displace);
Plot(S2,"S2",colorGreen,styleDots|styleNoLine,0,0,Displace);
Plot(S3,"S3",colorGreen,styleDots|styleNoLine,0,0,Displace);
if (rulesSuryo=="Enable")
{
specBuySuryo= tanggaMerah AND L>Ref(P,-1) AND L>=Ref(L,-1);
BuySuryo= specBuySuryo AND H>Ref(H,-1) AND C>Ref(C,-1);
SellSuryo= Ref(P,-1)>Ref(P,-2) AND H<Ref(P,-1) AND L<Ref(L,-1);
//Lets plot buy sell signal
if (speculativeBuyArrow=="Enable") PlotShapes(IIf(specBuySuryo, shapeHollowUpArrow , shapeNone), arrowSuryoColor, 0, Low, Offset=-50);
if (buyArrow=="Enable") PlotShapes(IIf(BuySuryo, shapeUpArrow , shapeNone), arrowSuryoColor, 0, Low, Offset=-50);
if (sellArrow=="Enable") PlotShapes(IIf(SellSuryo, shapeDownArrow, shapeNone), arrowSuryoColor, 0,High, Offset=-50);
};//end Suryo Rules
if (rulesFB=="Enable") //Rules FB
{
specBuyFB= tanggaMerah AND C>Ref(P,-1) AND L>=Ref(L,-1);
BuyFB= specBuyFB AND H>Ref(H,-1) AND C>Ref(C,-1);
SellFB= Ref(P,-1)>Ref(P,-2) AND C<Ref(P,-1) AND L<Ref(L,-1);
//Lets plot buy sell signal
if (speculativeBuyArrow=="Enable") PlotShapes(IIf(specBuyFB, shapeHollowUpArrow , shapeNone), arrowFBColor, 0, Low, Offset=-60);
if (buyArrow=="Enable") PlotShapes(IIf(BuyFB, shapeUpArrow , shapeNone), arrowFBColor, 0, Low, Offset=-60);
if (sellArrow=="Enable") PlotShapes(IIf(SellFB, shapeDownArrow, shapeNone), arrowFBColor, 0,High, Offset=-60);
};//end Rules FB
if (rulesGado2=="Enable") //Rules Gado-Gado
{
specBuyGado2= Ref(tanggaMerah,-1) AND Ref(C,-1)<=Ref(P,-2) AND L>=Ref(L,-1) AND C>=Ref(P,-1) AND O<C;
BuyGado2= specBuyGado2 AND H>Ref(H,-1) AND C>Ref(C,-1);
SellGado2= Ref(P,-1)>Ref(P,-2) AND H<Ref(P,-1) AND L<Ref(L,-1);
//Lets plot buy sell signal
if (speculativeBuyArrow=="Enable") PlotShapes(IIf(specBuyGado2, shapeHollowUpArrow , shapeNone), arrowGado2Color, 0, Low, Offset=-70);
if (buyArrow=="Enable")PlotShapes(IIf(BuyGado2, shapeUpArrow , shapeNone), arrowGado2Color, 0, Low, Offset=-70);
if (sellArrow=="Enable") PlotShapes(IIf(SellGado2, shapeDownArrow, shapeNone), arrowGado2Color, 0,High, Offset=-70);
};//end Rules Gado-Gado
function selip(besar,kecil,tengah,text) //untuk menyelipkan nilai array antara PSR dan akan ditulis bersama Title
{
result=WriteIf (tengah<Ref(besar,-1) AND tengah>Ref(kecil,-1), EncodeColor(colorBlack) + "\n" + text +" = " + tengah , "");
return result;
} ;//end function
function sama(Value1,Value2,text) //untuk nilai array yang sama dengan PSR dan akan ditulis bersama title
{
result=WriteIf (Value2==Ref(Value1,-1), EncodeColor(colorBlack) + " = " +text,"");
return result;
} //end function
//Tulis title vertical
HR3=selip(1000000,R3,C,"C");
R3R2 = selip(R3,R2,C,"C");
R2R1 = selip(R2,R1,C,"C");
R1P= selip(R1,P,C,"C");
PS1 = selip(P,S1,C,"C");
S1S2 = selip(S1,S2,C,"C");
S2S3 = selip(S2,S3,C,"C");
S3L=selip(S3,0,C,"C");
R3C = sama(R3,C,"C");
R2C = sama(R2,C,"C");
R1C = sama(R1,C,"C");
PC = sama(P,C,"C");
S3C = sama(S3,C,"C");
S2C = sama(S2,C,"C");
S1C = sama(S1,C,"C");
Title =
"All-In-One Pivot Trading\n\n"+
Date()+
" "+Name()+
EncodeColor(colorBlue)+" O "+EncodeColor(colorBlack)+"= "+O+
EncodeColor(colorBlue)+" H "+EncodeColor(colorBlack)+"= "+H+
EncodeColor(colorBlue)+" L "+EncodeColor(colorBlack)+"= "+L+
EncodeColor(colorBlue)+" C "+EncodeColor(colorBlack)+"= "+C+
EncodeColor(colorBlue)+" V "+EncodeColor(colorBlack)+"= "+ WriteVal(Volume/500,0)+ " lot"+
"\n"+
HR3+"\n"+ EncodeColor(colorRed)+"R3 = "+Ref(R3,-1)+ R3C+
R3R2+
EncodeColor(colorRed)+"\nR2 = "+ Ref(R2,-1)+R2C+
R2R1 +
EncodeColor(colorRed)+"\nR1 = "+Ref(R1,-1) +R1C+
R1P+
EncodeColor(colorViolet)+"\nP = "+ Ref(P,-1)+PC+
PS1+
EncodeColor(colorGreen)+"\nS1 = "+ Ref(S1,-1)+S1C+
S1S2+
EncodeColor(colorGreen)+"\nS2 = "+ Ref(S2,-1)+S2C+
S2S3+
EncodeColor(colorGreen)+"\nS3 = "+ Ref(S3,-1)+S3C+S3L+
"\n\n"+
EncodeColor(colorRed)+"R3 besok = "+ R3 +
EncodeColor(colorRed)+"\nR2 besok = "+ R2 +
EncodeColor(colorRed)+"\nR1 besok = "+ R1 +
EncodeColor(colorViolet)+"\nP besok = "+ P+
EncodeColor(colorGreen)+"\nS1 besok = "+ S1 +
EncodeColor(colorGreen)+"\nS2 besok = "+ S2 +
EncodeColor(colorGreen)+"\nS3 besok = "+ S3;
_SECTION_BEGIN("Main");
pivotCalc = ParamList("Pivot Calculation", "Suryo|FB", 0);
rulesSuryo=ParamList("Suryo Rules","Enable|Disable",0);
rulesFB=ParamList("FB Rules","Enable|Disable",1);
rulesGado2=ParamList("Gado-Gado Rules","Enable|Disable",1);
speculativeBuyArrow=ParamList("Speculative Buy Arrow","Enable|Disable",1);
buyArrow=ParamList("Buy Arrow","Enable|Disable",0);
sellArrow=ParamList("Sell Arrow","Enable|Disable",0);
nPivot = Param("Jumlah Tangga Merah", 1, 1, 20);
pivotUpColor=ParamColor("Pivot Up Color", colorGreen );
pivotDownColor=ParamColor("Pivot Down Color", colorRed );
arrowSuryoColor=ParamColor("Arrow Suryo Color", colorRed );
arrowFBColor=ParamColor("Arrow FB Color", colorBlue );
arrowGado2Color=ParamColor("Arrow Gado-Gado Color", colorGreen );
_SECTION_END();
Plot(C,"C",colorBlack,styleCandle); //Plot bar harga
if(pivotCalc == "Suryo")//Kalau Pivot Calculation: Suryo
{
// tentukan Pivot berdasarkan data kemarin
P = (H+L+C) / 3;
}
else //Kalau Pivot Calculation: FB
{
// tentukan Pivot berdasarkan data kemarin
// asumsi C=O, define P
P =(H+L+2*C)/4;
// if C>O define new P, otherwise use P above
P = IIf(C>O,(2*H+L+C)/4, P);
// if C<O define new P, otherwise use P above
P = IIf(C<O,(H+2*L+C)/4, P);
};//end PivotCalc
//berapa tangga merah sebelum boleh ada sinyal beli?
tanggaMerah=1;
for( i = 0; i < nPivot; i++ )
{
tanggaMerah= Ref(P,-1*i-1) <Ref(P,-1*i-2) AND tanggaMerah;
} ;//end berapa tangga merah sebelum boleh ada sinyal beli
//Hitung S dan R
R1= (P * 2) - L;
S1= (P * 2) - H;
R2 = P + (R1 - S1); // P + (H - L)
S2 = P - (R1 - S1); // P - (H - L)
R3 = H + 2*(P - L);
S3 = L - 2*(H - P);
//Plot SRP
Displace=1;
Plot(R3,"R3",colorRed,styleDots|styleNoLine,0,0,Displace);
Plot(R2,"R2",colorRed,styleDots|styleNoLine,0,0,Displace);
Plot(R1,"R1",colorRed,styleDots|styleNoLine,0,0,Displace);
Plot(P,"P",IIf( Ref(p,0)>Ref(p,-1), pivotUpColor, pivotDownColor ), styleStaircase,0,0,Displace);
Plot(S1,"S1",colorGreen,styleDots|styleNoLine,0,0,Displace);
Plot(S2,"S2",colorGreen,styleDots|styleNoLine,0,0,Displace);
Plot(S3,"S3",colorGreen,styleDots|styleNoLine,0,0,Displace);
if (rulesSuryo=="Enable")
{
specBuySuryo= tanggaMerah AND L>Ref(P,-1) AND L>=Ref(L,-1);
BuySuryo= specBuySuryo AND H>Ref(H,-1) AND C>Ref(C,-1);
SellSuryo= Ref(P,-1)>Ref(P,-2) AND H<Ref(P,-1) AND L<Ref(L,-1);
//Lets plot buy sell signal
if (speculativeBuyArrow=="Enable") PlotShapes(IIf(specBuySuryo, shapeHollowUpArrow , shapeNone), arrowSuryoColor, 0, Low, Offset=-50);
if (buyArrow=="Enable") PlotShapes(IIf(BuySuryo, shapeUpArrow , shapeNone), arrowSuryoColor, 0, Low, Offset=-50);
if (sellArrow=="Enable") PlotShapes(IIf(SellSuryo, shapeDownArrow, shapeNone), arrowSuryoColor, 0,High, Offset=-50);
};//end Suryo Rules
if (rulesFB=="Enable") //Rules FB
{
specBuyFB= tanggaMerah AND C>Ref(P,-1) AND L>=Ref(L,-1);
BuyFB= specBuyFB AND H>Ref(H,-1) AND C>Ref(C,-1);
SellFB= Ref(P,-1)>Ref(P,-2) AND C<Ref(P,-1) AND L<Ref(L,-1);
//Lets plot buy sell signal
if (speculativeBuyArrow=="Enable") PlotShapes(IIf(specBuyFB, shapeHollowUpArrow , shapeNone), arrowFBColor, 0, Low, Offset=-60);
if (buyArrow=="Enable") PlotShapes(IIf(BuyFB, shapeUpArrow , shapeNone), arrowFBColor, 0, Low, Offset=-60);
if (sellArrow=="Enable") PlotShapes(IIf(SellFB, shapeDownArrow, shapeNone), arrowFBColor, 0,High, Offset=-60);
};//end Rules FB
if (rulesGado2=="Enable") //Rules Gado-Gado
{
specBuyGado2= Ref(tanggaMerah,-1) AND Ref(C,-1)<=Ref(P,-2) AND L>=Ref(L,-1) AND C>=Ref(P,-1) AND O<C;
BuyGado2= specBuyGado2 AND H>Ref(H,-1) AND C>Ref(C,-1);
SellGado2= Ref(P,-1)>Ref(P,-2) AND H<Ref(P,-1) AND L<Ref(L,-1);
//Lets plot buy sell signal
if (speculativeBuyArrow=="Enable") PlotShapes(IIf(specBuyGado2, shapeHollowUpArrow , shapeNone), arrowGado2Color, 0, Low, Offset=-70);
if (buyArrow=="Enable")PlotShapes(IIf(BuyGado2, shapeUpArrow , shapeNone), arrowGado2Color, 0, Low, Offset=-70);
if (sellArrow=="Enable") PlotShapes(IIf(SellGado2, shapeDownArrow, shapeNone), arrowGado2Color, 0,High, Offset=-70);
};//end Rules Gado-Gado
function selip(besar,kecil,tengah,text) //untuk menyelipkan nilai array antara PSR dan akan ditulis bersama Title
{
result=WriteIf (tengah<Ref(besar,-1) AND tengah>Ref(kecil,-1), EncodeColor(colorBlack) + "\n" + text +" = " + tengah , "");
return result;
} ;//end function
function sama(Value1,Value2,text) //untuk nilai array yang sama dengan PSR dan akan ditulis bersama title
{
result=WriteIf (Value2==Ref(Value1,-1), EncodeColor(colorBlack) + " = " +text,"");
return result;
} //end function
//Tulis title vertical
HR3=selip(1000000,R3,C,"C");
R3R2 = selip(R3,R2,C,"C");
R2R1 = selip(R2,R1,C,"C");
R1P= selip(R1,P,C,"C");
PS1 = selip(P,S1,C,"C");
S1S2 = selip(S1,S2,C,"C");
S2S3 = selip(S2,S3,C,"C");
S3L=selip(S3,0,C,"C");
R3C = sama(R3,C,"C");
R2C = sama(R2,C,"C");
R1C = sama(R1,C,"C");
PC = sama(P,C,"C");
S3C = sama(S3,C,"C");
S2C = sama(S2,C,"C");
S1C = sama(S1,C,"C");
Title =
"All-In-One Pivot Trading\n\n"+
Date()+
" "+Name()+
EncodeColor(colorBlue)+" O "+EncodeColor(colorBlack)+"= "+O+
EncodeColor(colorBlue)+" H "+EncodeColor(colorBlack)+"= "+H+
EncodeColor(colorBlue)+" L "+EncodeColor(colorBlack)+"= "+L+
EncodeColor(colorBlue)+" C "+EncodeColor(colorBlack)+"= "+C+
EncodeColor(colorBlue)+" V "+EncodeColor(colorBlack)+"= "+ WriteVal(Volume/500,0)+ " lot"+
"\n"+
HR3+"\n"+ EncodeColor(colorRed)+"R3 = "+Ref(R3,-1)+ R3C+
R3R2+
EncodeColor(colorRed)+"\nR2 = "+ Ref(R2,-1)+R2C+
R2R1 +
EncodeColor(colorRed)+"\nR1 = "+Ref(R1,-1) +R1C+
R1P+
EncodeColor(colorViolet)+"\nP = "+ Ref(P,-1)+PC+
PS1+
EncodeColor(colorGreen)+"\nS1 = "+ Ref(S1,-1)+S1C+
S1S2+
EncodeColor(colorGreen)+"\nS2 = "+ Ref(S2,-1)+S2C+
S2S3+
EncodeColor(colorGreen)+"\nS3 = "+ Ref(S3,-1)+S3C+S3L+
"\n\n"+
EncodeColor(colorRed)+"R3 besok = "+ R3 +
EncodeColor(colorRed)+"\nR2 besok = "+ R2 +
EncodeColor(colorRed)+"\nR1 besok = "+ R1 +
EncodeColor(colorViolet)+"\nP besok = "+ P+
EncodeColor(colorGreen)+"\nS1 besok = "+ S1 +
EncodeColor(colorGreen)+"\nS2 besok = "+ S2 +
EncodeColor(colorGreen)+"\nS3 besok = "+ S3;
Saturday, 24 January 2015
For Intraday Trading for Amibroker (AFL)
For Intraday Trading for Amibroker (AFL)
This indicaror given by my friend & its giving good result in
intraday trading…so plz first check from your side…do back testing &
if u satisfy then ENJOY TRADING….Thx
_SECTION_BEGIN("System");
SetChartOptions(0,chartShowArrows|chartShowDates);
Title = ("" + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");
per1=Param("First Period",6,2,30,1);
per2=Param("Second Period",2,2,30,1);
Om=MA(O,per1);
hm=MA(H,per1);
lm=MA(L,per1);
Cm=MA(C,per1);
//==============================================================================================================
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorBlack, styleCandle | styleNoLabel );
Of=MA(Haopen,per2);
Cf=MA(Haclose,per2);
Lf=IIf(haOpen<haClose,MA(Halow,per2),MA(Hahigh,per2));
Hf=IIf(haOpen<haClose,MA(Hahigh,per2),MA(Halow,per2));
PlotOHLC( Of, Hf, Lf, Cf, "" + Name(), colorGreen, styleCandle | styleNoLabel );
Plot(C,"Close",colorLime,styleLine);
//=======================================================================================================================
MO=MA(O,40);
ML=MA(L,40);
MH=MA(H,40);
Plot(MO,"",colorBlue,styleDashed);
Plot(ML,"",4,styleDashed);
Plot(MH,"",colorDarkGreen,styleDashed);
_SECTION_BEGIN("Background text");
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
_SECTION_BEGIN("Background Color");
BKswitch = ParamToggle("Background Color","On,Off");
OUTcolor = ParamColor("Outer Panel Color",colorLightBlue);
INUPcolor = ParamColor("Inner Panel Upper",colorLightYellow);
INDNcolor = ParamColor("Inner Panel Lower",colorSeaGreen);
TitleColor = ParamColor("Title Color ",ColorRGB(245,245,245));
if (NOT BKswitch)
{
SetChartBkColor(OUTcolor); // color of outer border
SetChartBkGradientFill(INUPcolor,INDNcolor,TitleColor); // color of inner panel
}
_SECTION_END();
/*1. Here are some observations to keep in mind that will help assure
you are in a good trending move which is detrimental to the success
of the trade moving higher before the inevitable over exhausted trend.
2 Consider only going long on the 5M if the 30M (two rows above) is also blue.
3 Consider the 1hr row as well being blue since it has an effect too.
4 The 15M row has to be blue with NO exceptions
5 The 30M row if blue has less effect on the trade as compared to the 15M row
but keep this in mind. The 30M row being blue helps the 15M row continue to stay blue.
6 The 1hr row has even less effect OR importance but it too keeps the 30M
from weakening to some minor degree.
*/
// Define label bar (x) position location
blankRightBars = 5; //insert actual blank right bars specified in Preferences
barsInView = Status("lastvisiblebarindex") - Status("firstvisiblebarindex") - blankRightBars;
Offset = Param("Offset Bar", 0.95, 0, 1, 0.01);
textOffset = BarCount - (Offset * barsInView);
_SECTION_BEGIN("default");
HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
PlotText("Heinkein 4T tf :"+Interval(2), textoffset, 41.01, colorYellow);
Color = IIf( Haopen > Haclose,4, IIf( Haopen == Haclose,colorYellow, 6));
Plot(10,"", Color, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 11,"",colorBlack,styleOwnScale|styleArea|styleNoLabel,0, 100 );
_SECTION_BEGIN("2");
Compress2= Param("Compression",2,1,3,1);
TimeFrameSet(Compress2* Interval());
HaClose2 =EMA((O+H+L+C)/4,3);
HaOpen2 = AMA( Ref( HaClose2, -1 ), 0.5 );
HaHigh2 = Max( H, Max( HaClose2, HaOpen2 ) );
HaLow2 = Min( L, Min( HaClose2, HaOpen2 ) );
PlotText("Heinkein 4T tf :"+Interval(2), textoffset, 41.055, colorYellow);
TimeFrameRestore();
HAopen2f=TimeFrameExpand( Haopen2, Compress2* Interval());
Haclose2f=TimeFrameExpand( Haclose2, Compress2* Interval());
HaHigh2f=TimeFrameExpand( Hahigh2, Compress2* Interval());
HaLow2f=TimeFrameExpand( Halow2, Compress2* Interval());
Color2 = IIf( Haopen2f > Haclose2f,4, IIf(Haopen2f == Haclose2f,colorYellow, 6));
Plot(20,"", Color2, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 21,"",colorBlack,styleOwnScale|styleArea|styleNoLabel,0, 100 );
_SECTION_BEGIN("3");
Compress3= Param("Compression3",4,2,6,1);
TimeFrameSet(Compress3* Interval());
HaClose3 =EMA((O+H+L+C)/4,3);
HaOpen3 = AMA( Ref( HaClose3, -1 ), 0.5 );
HaHigh3 = Max( H, Max( HaClose3, HaOpen3 ) );
HaLow3 = Min( L, Min( HaClose3, HaOpen3 ) );
PlotText("Heinkein 4T tf :"+Interval(2), textoffset,41.10, colorYellow);
TimeFrameRestore();
HAopen3f=TimeFrameExpand( Haopen3, Compress3* Interval());
Haclose3f=TimeFrameExpand( Haclose3, Compress3* Interval());
HaHigh3f=TimeFrameExpand( Hahigh3, Compress3* Interval());
HaLow3f=TimeFrameExpand( Halow3, Compress3* Interval());
color3 = IIf( Haopen3f > Haclose3f,4, IIf( Haopen3f == Haclose3f,colorYellow,6));
Plot(30,"", Color3, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 31,"",colorBlack,styleOwnScale|styleArea|styleNoLabel,0, 100 );
_SECTION_BEGIN("4");
Compress4= Param("Compression4",8,2,10,1);
TimeFrameSet(Compress4* Interval());
HaClose4 =EMA((O+H+L+C)/4,3);
HaOpen4 = AMA( Ref( HaClose4, -1 ), 0.5 );
HaHigh4 = Max( H, Max( HaClose4, HaOpen4 ) );
HaLow4 = Min( L, Min( HaClose4, HaOpen4 ) );
PlotText("Heinkein 4T tf :"+Interval(2), textoffset, 41.14, colorYellow);
TimeFrameRestore();
HAopen4f=TimeFrameExpand( Haopen4, Compress4* Interval());
Haclose4f=TimeFrameExpand( Haclose4, Compress4* Interval());
HaHigh4f=TimeFrameExpand( Hahigh4, Compress4* Interval());
HaLow4f=TimeFrameExpand( Halow4, Compress4* Interval());
Color4 = IIf( Haopen4f > Haclose4f,4, IIf( Haopen4f == Haclose4f ,colorYellow, 6));
Plot(40,"", Color4, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 41,"",colorBlack,styleOwnScale|styleArea|styleNoLabel,0, 100 );
_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}} "+_DEFAULT_NAME()+" : {{OHLCX}} {{VALUES}}" );
Previous Pivots for Amibroker (AFL)
Previous Pivots for Amibroker (AFL)
i have found in technical stories, most of the peoples are working with todays and tomorrows pivots. but yesterdays pivots are working very good most of the times…….Enjoy…….
ppl = ParamToggle("","Off|On",1);
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = -33.5;
PO=TimeFrameGetPrice( "O", inDaily, -1 );
PL=TimeFrameGetPrice( "L", inDaily, -1 );
PH=TimeFrameGetPrice( "H", inDaily, -1 );
PC=TimeFrameGetPrice( "C", inDaily, -1 );
P=((PH+PL+PC)/3);PI=LastValue(P,1);
R1=((2*P)-PL);R1I=LastValue(R1,1);
S1=((2*P)-PH);S1I=LastValue(S1,1);
R2=((P-S1)+R1);R2I=LastValue(R2,1);
S2=(P-(R1-S1));S2I=LastValue(S2,1);
R3=PH+(2*(P-PL));R3I=LastValue(R3,1);
S3=PL-(2*(PH-P));S3I=LastValue(S3,1);
if(ppl==1) {
Plot(R1,"Resistance 1",colorRed,styleDashed);
Plot(R2,"Resistance 1",colorRed,styleDashed);
Plot(R3,"Resistance 1",colorRed,styleDashed);
Plot(S1,"Support 1",colorBrightGreen,styleDashed);
Plot(S2,"support 2",colorBrightGreen,styleDashed);
Plot(S3,"Support 3",colorBrightGreen,styleDashed);
Plot(P,"Resistance 1",colorWhite,styleDashed);
PlotText(" Y Day Pivot = " + WriteVal(P,fraction), LastValue(BarIndex())-(numbars/Hts), PI +0.05, colorWhite);
PlotText(" Y Day Resistance 1 = " + WriteVal(R1,fraction), LastValue(BarIndex())-(numbars/Hts), R1I +0.05, colorRed);
PlotText(" Y Day Resistance 2 = " + WriteVal(R2,fraction), LastValue(BarIndex())-(numbars/Hts), R2I +0.05, colorRed);
PlotText(" Y Day Resistance 3 = " + WriteVal(R3,fraction), LastValue(BarIndex())-(numbars/Hts), R3I +0.05, colorRed);
PlotText(" Y Day Support 1 = " + WriteVal(S1,fraction), LastValue(BarIndex())-(numbars/Hts), S1I +0.05, colorBrightGreen);
PlotText(" Y Day Support 2 = " + WriteVal(S2,fraction), LastValue(BarIndex())-(numbars/Hts), S2I +0.05, colorBrightGreen);
PlotText(" Y Day Support 3 = " + WriteVal(S3,fraction), LastValue(BarIndex())-(numbars/Hts), S3I +0.05, colorBrightGreen);
}
_SECTION_BEGIN("@Candle great");
A=(H+L)/2;
var1=Wilders(A,34);
var2=Wilders(A,5);
var3=var2-var1;
var4=var3-Wilders(var3,5);
Var5=(H-L)/V;
AO=Var3;
AC=Var4;
barcolor=IIf(AO>Ref(AO,-1) AND AC>Ref(AC,-1),colorGreen,IIf(AO<Ref(AO,-1) AND AC<Ref(AC,-1),colorRed,IIf(V>0 AND Var5<Ref(Var5,-1) AND V>Ref(V,-1),colorGold,colorBrown)));
Plot(C,"Close",barcolor,64+styleNoTitle );
_SECTION_END();
_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---SUNDAY---MONDAY--TUESDAYWEDNESDAY-THURSDAY--FRIDAY--SATURDAY", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",10,-55,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( "L.T.P. : "+ C +"", Status("pxwidth")/C14, Status("pxheight")/C15*2 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( ""+DD+ " ( "+xx+"%)", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
_SECTION_BEGIN("Title");
DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
Title = EncodeColor(colorWhite)+" "+EncodeColor(colorWhite)+ Name() + ", " + Interval(2) + ", " + Date() + " - "+strWeekday + " - " +
EncodeColor(colorWhite) + "\nO " + EncodeColor(colorWhite) + O +
", H : " + H +
", L : " + L +
", C : " + C +
EncodeColor(colorWhite)+ "\n Day-Open : " +DODay + " Day-High : " +DHiDay + " Day-Low : " + DLoDay
;
MACD ON PRICE CHART for Amibroker (AFL)
MACD ON PRICE CHART for Amibroker (AFL)
Hi friendsThis is a plain Macd formula the 26-12-9 ema plotted on a price chart and if used to detect divergence or price to macd discrepancy clearly shown in chart works wonders.
Those who trade with macd will be very useful.Please see the inserted image and have clearly marked the areas of discrepancy with price and macd indicator.This indicator has to be used with a regular macd indicator at bottom.
Thank You all
Hope will be useful to you all
Here is a screenshot of how the indicator looks:
_SECTION_BEGIN("EMA Crossover");
Plot(Close, "Price", colorWhite, styleCandle);
Plot(EMA(Close,12),"12-EMA",colorBlue,styleThick);
Plot(EMA(Close,26),"26-EMA",colorRed,styleThick);
Plot(EMA(Close,9),"9-EMA",colorBrightGreen,styleDots,styleThick);
//Formula for EMA Crossover Price
XR=(EMA(Close,5) * (2 / 6 - 1) - EMA(Close,10) * (2 / 11 - 1)) / (2 / 6 - 2 / 11);
Title = Name() + " " + Date() + EncodeColor( colorBlue ) + " Close: " + C + EncodeColor( colorBlack ) + " Open: " + O + " High: " + H + " Low: " + L + EncodeColor( colorBlue )+ "\n" + EncodeColor(colorDarkGreen) + WriteVal (XR, format=1.2 ) + " Price Required for EMA Crossover";
_SECTION_END();
_SECTION_BEGIN("Fibo Retrace and Extensions");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd = Param("Plot Forward", 0, 0, 500, 1);
text = ParamToggle("Plot Text","Off|On",1);
hts = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;
function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
AND xSp0 > xRp0, ySp0 + retval, Null))));
return FibVal;
}
x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
if(fibs==1)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
}
if(text==1)
{
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
_SECTION_END();
RSI - With Overbought & Oversold coloured for Amibroker (AFL)
This is RSI Indicator, with coloured Overbought and Oversold area , to make easier to analyze.
Here is a screenshot of how the indicator looks:
_SECTION_BEGIN("RSI");
SetChartOptions(0,0,ChartGrid30|ChartGrid70,0,100);
periods = Param( "Periods", 14, 1, 200, 1 );
z = RSI( periods);
RSILineColor = ParamColor("RSI Line Color",ColorRGB(127,0,83));
RSIOverboughtColor = ParamColor("RSI Overbought Color",ColorRGB(127,0,83));
RSIOversoldColor = ParamColor("RSI Oversold Color",colorRed);
Plot( z, _DEFAULT_NAME(), RSILineColor , styleLine );
Plot( 50, _DEFAULT_NAME(), RSILineColor , styleDashed|styleNoTitle );
Plot( 70, _DEFAULT_NAME(), RSILineColor , styleLine|styleNoTitle );
Plot( 30, _DEFAULT_NAME(), RSILineColor , styleLine|styleNoTitle );
PlotOHLC(z,z,50,z,"",IIf(z>50,RSIOverboughtColor,RSIOversoldColor),styleCloud|styleClipMinMax,30,70);
_SECTION_END();
Wise wave for Amibroker (AFL) -David Weis a veteran VSA teacher commercialized
Wise wave for Amibroker (AFL)
David Weis a veteran VSA teacher commercialized his Weis Wave indicator which is considered as A Modern Adaptation of the Wyckoff Wave & Volume. Get introduced about Weis wave reading the description “Weis Wave Plugin_ A Modern Adaptation of the Wyckoff Wave & Volume” from the link-This is collected one and thanks to original author who took the pain in transforming the code for amibroker also regretting for not mentioning his name as I cant recall his name right now.
Here is a screenshot of how the indicator looks:
_SECTION_BEGIN("WeisWave");
//up[0] = V[0];
//dn[0] = V[0];
//vol[0] = V[0];
trend[0] = 0;
wave[0] = 0;
vol[0] = 0;
mov[0] = 0;
dif=1;
rp = Param("Reversal Bars", 0.03,0.1,5,0.1);
for( i=1; i<BarCount; i++) {
if (Close[i]-Close[i-1]>rp) mov[i]=1;
if (Close[i]-Close[i-1]==rp) mov[i]=0;
if (Close[i]-Close[i-1]<-rp) mov[i]=-1;
if ((mov[i]!=0) && (mov[i]!=mov[i-1]))
{
trend[i]=mov[i];
}
else {trend[i]=trend[i-1];}
if ((trend[i]!=wave[i-1]) && (abs(Close[i]-Close[i-1])*10000>=dif))
{
wave[i]=trend[i];
}
else
{
wave[i]=wave[i-1];
}
if (wave[i]==wave[i-1])
{
vol[i]=vol[i-1]+Volume[i];
}
else
{
vol[i]=Volume[i];
}
if (wave[i]==1)
{
up[i]=vol[i];
dn[i]=0;
}
if (wave[i]==-1)
{
dn[i]=vol[i];
up[i]=0;
}
if (wave[i]==0)
{
dn[i]=vol[i-1];
up[i]=vol[i-1];
}
}
PlotOHLC(0,up,0,up,"SwingWave",5 , 2|styleThick ) ;
PlotOHLC(0,dn,0,dn,"",4 , 2|styleThick ) ;
GfxSetOverlayMode(1);
GfxSetTextColor(10);
GfxSelectFont("MS Sans Serif", 6, 300, False, False, 0);
GfxTextOut(" By : Casoni ", Status("pxwidth")-60 , Status("pxheight")-13 );
_SECTION_END();
Advanced Elliott for Amibroker (AFL)
Advanced Elliott for Amibroker (AFL)
_SECTION_BEGIN("Advanced Elliot Wave ");
//Elliot Wave Metastock to AFL
//-- Script Start -------
_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+_DEFAULT_NAME()+" : {{VALUES}} "
);
Option = ParamToggle("Insert To", "Price Chart|Indicator");
pr=Param("Elliot Wave minimum % move",0.5, 0.25,3,0.25);
//{ Beginner Elliot Wave stuff }
EWpk=PeakBars(H,pr)==0;
EWtr=TroughBars(L,pr)==0;
//{ Intermediate Elliot Wave stuff }
zz=Zig(C,pr);
zzHi=Zig(H,pr);
zzLo=Zig(L,pr);
Avg=(zzHi+zzLo)/2;
//{ Advanced Elliot Wave stuff }
RetroSuccessSecret=IIf(EWpk,zzHi,
IIf(EWtr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
EW=Zig(RetroSuccessSecret,pr);
//{ Plot on price chart }
if (Option==0)
Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick));
else
{
//{ Plot on own window }
Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick));
}
//{ Buy/Sell Elliot Wave stuff }
EWbuy=TroughBars(EW,pr)==1;
EWsell=PeakBars(EW,pr)==1;
Plot(C,"",47,128+4);
PlotShapes(EWbuy*shapeUpArrow,5,0,L,-5);
PlotShapes(EWsell*shapeDownArrow,4,0,H,-5);
//-- Script End -------
_SECTION_END();
AutoTrade Control For NEST/NOW for Amibroker (AFL)
AutoTrade Control For NEST/NOW
This is the updation of Manual Trade Control for NEST/NOW. This afl have new features like it will have all the trades in its memory.This AFL is not a strategy for trading. It is only integrating the Amibroker to NEST/NOW through NEST PLUS API.
You have to replace the existing buy/sell strategy with your buy/sell strategy.
Strictly do not use the buy/sell strategy in this afl for real trading.
Title = " ";
_SECTION_BEGIN("AutoTrade1V00 ");
EnableRealTimeControl = ParamList("Enable Controls", "No|Yes", 0);
EnableStrategy = ParamList("Enable Strategy", "No|Yes", 0);
StrategyType = ParamList("StrategyType", "Long/Short|Long|Short", 0);
EnableAutoTrade = ParamList("Enable Autotrade", "No|Yes", 0);
BuyPriceSelection = ParamList("Buy Price", "Bid Price|Ask Price|LTP", 0);
SellPriceSelection = ParamList("Sell Price", "Ask Price|Bid Price|LTP", 0);
ProductType = ParamList("Product Type", "MIS|NRML", 0);
OrderType = ParamList("Order Type", "LIMIT|MARKET", 0);
ClientIdValue = ParamStr("Client Id", "CLIENTID");
LotQuantity = Param("Lot Quantity", 1000, 50, 100000, 10);
X2 = Param("Button X Offset", 0, 0, 2000, 100);
Y2 = Param("Button Y Offset", 0, 0, 2000, 100);
X1 = Param("Button Size", 100, 100, 300, 50);
Buy = 0;
Sell = 0;
Short = 0;
Cover = 0;
if(EnableStrategy == "Yes")
{
Buy = Cross(MACD(12, 26), Signal(12, 26, 9));
Sell = Cross(Signal(12, 26, 9), MACD(12, 26));
Short = Cross(Signal(12, 26, 9), MACD(12, 26));
Cover = Cross(MACD(12, 26), Signal(12, 26, 9));
}
if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes")
{
if(StaticVarGetText("firstflagforNest")=="")
{
nestplus = Null;
if(IsNull(nestplus))
{
nestplus = CreateStaticObject("Nest.PlusApi");
nestplus.SetObjectName("AutoTrade");
}
StaticVarSetText ("firstflagforNest","0", 1);
}
}
X0 = 20;
Y0 = 10;
procedure DashBoard (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
GfxSetOverlayMode(0);
GfxSelectFont("Segoe UI", 8.5, 500);
GfxSetBkMode(1);
GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);
DashBoard (" Strategy: " + EnableStrategy, X0, Y0, X0+150, Y0+13, colorGrey40, colorGrey40);
DashBoard (" Strategy Type: " + StrategyType, X0, Y0+13, X0+150, Y0+26, colorGrey40, colorGrey40);
DashBoard (" Auto Trade: " + EnableAutoTrade, X0, Y0+26, X0+150, Y0+38, colorGrey40, colorGrey40);
DashBoard (" Buy Price: " + BuyPriceSelection, X0, Y0+38, X0+150, Y0+50, colorGrey40, colorGrey40);
DashBoard (" Sell Price: " + SellPriceSelection, X0, Y0+50, X0+150, Y0+62, colorGrey40, colorGrey40);
DashBoard (" Product Type: " + ProductType, X0, Y0+62, X0+150, Y0+75, colorGrey40, colorGrey40);
DashBoard (" Order Type: " + OrderType, X0, Y0+75, X0+150, Y0+88, colorGrey40, colorGrey40);
DashBoard ("", X0+1, Y0+88, X0+149, Y0+89, colorRed, colorRed);
GfxSetTextColor(colorAqua);
DashBoard (" ", X0, Y0+89, X0+150, Y0+105, colorBlack, colorBlack);
X0 = 180;
Y0 = 10;
procedure DrawData (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
GfxSetOverlayMode(0);
GfxSelectFont("Segoe UI", 8.5, 600);
GfxSetBkMode(1);
GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);
DrawData (" " + Name(), X0, Y0, X0+200, Y0+15, colorGrey40, colorGrey40);
DrawData (" " + Date(), X0+205, Y0, X0+360, Y0+15, colorGrey40, colorGrey40);
DrawData (" Open : " + Open, X0+365, Y0, X0+505, Y0+15, colorGrey40, colorGrey40);
DrawData (" Close : " + Close, X0+510, Y0, X0+650, Y0+15, colorGrey40, colorGrey40);
DrawData (" High : " + High, X0+655, Y0, X0+795, Y0+15, colorGrey40, colorGrey40);
DrawData (" Low : " + Low, X0+800, Y0, X0+940, Y0+15, colorGrey40, colorGrey40);
DrawData (" Volume : " + NumToStr(Volume,1,0), X0+945, Y0, X0+1100, Y0+15, colorGrey40, colorGrey40);
DrawData (" % Change : " + NumToStr( (((C-O)*100)/O), 1.2, True), X0+1105, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
if(StaticVarGetText("firstflag")=="")
{
StaticVarSet("OrderNo", 0);
StaticVarSetText ("firstflag","0");
}
if(StaticVarGetText("firstflag"+Name())=="")
{
StaticVarSet(("BuyIndex" + Name()), 0);
StaticVarSet(("BuyCount" + Name()), 0);
StaticVarSet(("BuyFlag" + Name()), 0);
StaticVarSet(("BuyPrice" + Name()), 0);
StaticVarSet(("BuyQty" + Name()), 0);
StaticVarSet(("SellIndex" + Name()), 0);
StaticVarSet(("SellCount" + Name()), 0);
StaticVarSet(("SellFlag" + Name()), 0);
StaticVarSet(("SellPrice" + Name()), 0);
StaticVarSet(("SellQty" + Name()), 0);
StaticVarSet(("ShortIndex" + Name()), 0);
StaticVarSet(("ShortCount" + Name()), 0);
StaticVarSet(("ShortFlag" + Name()), 0);
StaticVarSet(("ShortPrice" + Name()), 0);
StaticVarSet(("ShortQty" + Name()), 0);
StaticVarSet(("CoverIndex" + Name()), 0);
StaticVarSet(("CoverCount" + Name()), 0);
StaticVarSet(("CoverFlag" + Name()), 0);
StaticVarSet(("CoverPrice" + Name()), 0);
StaticVarSet(("CoverQty" + Name()), 0);
StaticVarSet("LTPSave" + Name(), 0);
StaticVarSet("LTQSave" + Name(), 0);
StaticVarSet("VolumeTemp" + Name(), 0);
StaticVarSet("AskSave" + Name(), 0);
StaticVarSet("BidSave" + Name(), 0);
StaticVarSet("LastLTPColor" + Name(), colorGrey40);
StaticVarSet("LastLTQColor" + Name(), colorGrey40);
StaticVarSet("LastAskColor" + Name(), colorGrey40);
StaticVarSet("LastBidColor" + Name(), colorGrey40);
StaticVarSetText("firstflag"+Name(), "0");
}
CurrentAskPrice = LastValue(Aux1);
CurrentBidPrice = LastValue(Aux2);
CurrentTradedPrice = LastValue(C);
CurrentVolume = LastValue(Volume);
if(BuyPriceSelection == "Bid Price")
{
BuyPriceValue = CurrentBidPrice;
}
else if(BuyPriceSelection == "Ask Price")
{
BuyPriceValue = CurrentAskPrice;
}
else
{
BuyPriceValue = CurrentTradedPrice;
}
if(SellPriceSelection == "Ask Price")
{
SellPriceValue = CurrentAskPrice;
}
else if(SellPriceSelection == "Bid Price")
{
SellPriceValue = CurrentBidPrice;
}
else
{
SellPriceValue = CurrentTradedPrice;
}
LTPTemp = StaticVarGet("LTPSave" + Name());
LTQTemp = StaticVarGet("LTQSave" + Name());
VolumeTemp = StaticVarGet("VolumeTemp" + Name());
AskTemp = StaticVarGet("AskSave" + Name());
BidTemp = StaticVarGet("BidSave" + Name());
CurrentLTQ = (CurrentVolume - VolumeTemp);
if(CurrentLTQ < 0)
{
CurrentLTQ = CurrentLTQ * -1;
}
if(CurrentLTQ == 0)
{
CurrentLTQ = LTQTemp;
}
LTPColor = StaticVarGet("LastLTPColor" + Name());
LTQColor = StaticVarGet("LastLTQColor" + Name());
AskColor = StaticVarGet("LastAskColor" + Name());
BidColor = StaticVarGet("LastBidColor" + Name());
if(LTPTemp > CurrentTradedPrice)
{
LTPColor = colorRed;
}
else if(LTPTemp < CurrentTradedPrice)
{
LTPColor = colorGreen;
}
if(LTQTemp > CurrentLTQ)
{
LTQColor = colorRed;
}
else if(LTQTemp < CurrentLTQ)
{
LTQColor = colorGreen;
}
if(AskTemp > CurrentAskPrice)
{
AskColor = colorRed;
}
else if(AskTemp < CurrentAskPrice)
{
AskColor = colorGreen;
}
if(BidTemp > CurrentBidPrice)
{
BidColor = colorRed;
}
else if(BidTemp < CurrentBidPrice)
{
BidColor = colorGreen;
}
StaticVarSet("LastLTPColor" + Name(), LTPColor);
StaticVarSet("LastLTQColor" + Name(), LTQColor);
StaticVarSet("LastAskColor" + Name(), AskColor);
StaticVarSet("LastBidColor" + Name(), BidColor);
StaticVarSet("LTPSave" + Name(), CurrentTradedPrice);
StaticVarSet("LTQSave" + Name(), CurrentLTQ);
StaticVarSet("VolumeTemp" + Name(), CurrentVolume);
StaticVarSet("AskSave" + Name(), CurrentAskPrice);
StaticVarSet("BidSave" + Name(), CurrentBidPrice);
X0 = X2 + 20;
Y0 = Y2 + 120;
LBClick = GetCursorMouseButtons() == 9; // Click
MouseX = Nz(GetCursorXPosition(1)); //
MouseY = Nz(GetCursorYPosition(1)); //
procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
GfxSetOverlayMode(0);
GfxSelectFont("Segoe UI", 9, 700);
GfxSetBkMode(1);
GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);
}
GfxSetTextColor(colorWhite);
if(EnableRealTimeControl == "Yes")
{
DrawBut ("Buy", X0, Y0, X0+X1, Y0+30, colorGreen, colorGreen);
CursorInBuyButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0 AND MouseY <= Y0+30;
BuyButtonClick = CursorInBuyButton AND LBClick;
if (BuyButtonClick || NumPad7 )
{
TempBuy = Buy;
Buy = IIf((DateTime() == LastValue(DateTime())) || (TempBuy == True), True, False);
}
DrawBut ("Sell", X0, Y0+40, X0+X1, Y0+70, colorRed, colorRed);
CursorInSellButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+40 AND MouseY <= Y0+70;
SellButtonClick = CursorInSellButton AND LBClick;
if (SellButtonClick || NumPad8)
{
TempSell = Sell;
Sell = IIf((DateTime() == LastValue(DateTime())) || (TempSell == True), True, False);
}
DrawBut ("Short", X0, Y0+80, X0+X1, Y0+110, colorOrange, colorOrange);
CursorInShortButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
ShortButtonClick = CursorInShortButton AND LBClick;
if (ShortButtonClick || NumPad4)
{
TemShort = Short;
Short = IIf((DateTime() == LastValue(DateTime())) || (TemShort == True), True, False);
}
DrawBut ("Cover", X0, Y0+120, X0+X1, Y0+150, colorTurquoise, colorTurquoise);
CursorInCoverButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+120 AND MouseY <= Y0+150;
CoverButtonClick = CursorInCoverButton AND LBClick;
if (CoverButtonClick || NumPad5)
{
TempCover = Cover;
Cover = IIf((DateTime() == LastValue(DateTime())) || (TempCover == True), True, False);
}
DrawBut ("Clear Data", X0, Y0+160, X0+X1, Y0+190, colorGrey40, colorGrey40);
CursorInClearButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+160 AND MouseY <= Y0+190;
ClearButtonClick = CursorInClearButton AND LBClick;
if (ClearButtonClick || NumPad0 )
{
DrawBut("Clear", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40);
StaticVarSetText("firstflag"+Name(), "");
}
//TempBuy = Buy;
TempBuy = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Buy) == True), True, False);
BuyTempData = StaticVarGet("BuyIndex" + Name());
TempCount = StaticVarGet("BuyCount" + Name());
BuyPrevTemp = 0;
for(i = 0; i <= TempCount; i++)
{
BuyPrevTemp = BuyPrevTemp | (IIf(DateTime() == BuyTempData[i], True, False));
}
Buy = IIf(((BuyPrevTemp == True) || (TempBuy == True)), True, False);
//TempSell = Sell;
TempSell = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Sell) == True), True, False);
SellTempData = StaticVarGet("SellIndex" + Name());
TempCount = StaticVarGet("SellCount" + Name());
SellPrevTemp = 0;
for(i = 0; i <= TempCount; i++)
{
SellPrevTemp = SellPrevTemp | (IIf(DateTime() == SellTempData[i], True, False));
}
TempCount = StaticVarGet("BuyCount" + Name());
Sell = IIf((TempCount > 0) && ((SellPrevTemp == True) || (TempSell == True)), True, False);
//TempShort = Short;
TempShort = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Short) == True), True, False);
ShortTempData = StaticVarGet("ShortIndex" + Name());
TempCount = StaticVarGet("ShortCount" + Name());
ShortPrevTemp = 0;
for(i = 0; i <= TempCount; i++)
{
ShortPrevTemp = ShortPrevTemp | (IIf(DateTime() == ShortTempData[i], True, False));
}
Short = IIf(((ShortPrevTemp == True) || (TempShort == True)), True, False);
//TempCover = Cover;
TempCover = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Cover) == True), True, False);
CoverTempData = StaticVarGet("CoverIndex" + Name());
TempCount = StaticVarGet("CoverCount" + Name());
CoverPrevTemp = 0;
for(i = 0; i <= TempCount; i++)
{
CoverPrevTemp = CoverPrevTemp | (IIf(DateTime() == CoverTempData[i], True, False));
}
TempCount = StaticVarGet("ShortCount" + Name());
Cover = IIf((TempCount > 0) && ((CoverPrevTemp == True) || (TempCover == True)), True, False);
}
if(StrategyType == "Long")
{
Short = 0;
Cover = 0;
}
else if(StrategyType == "Short")
{
Buy = 0;
Sell = 0;
}
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeDownArrow;
PlotShapes( Buyshape, colorBrightGreen, 0, Low );
PlotShapes( SellShape, colorRed, 0, High );
Shortshape = Short * shapeDownArrow;
CoverShape = Cover * shapeUpArrow;
PlotShapes( Shortshape, colorOrange, 0, High, -30);
PlotShapes( CoverShape, colorTurquoise, 0, Low, -30 );
GraphXSpace = 5;
if(EnableRealTimeControl == "Yes")
{
if((LastValue(Buy) == True) && (StaticVarGet(("BuyFlag" + Name())) != LastValue(DateTime())))
{
StaticVarSet(("BuyFlag" + Name()), LastValue(DateTime()));
DrawBut("Buy", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40);
TempCount = StaticVarGet("BuyCount" + Name());
TempIndex = StaticVarGet("BuyIndex" + Name());
TempPrice = StaticVarGet("BuyPrice" + Name());
TempQty = StaticVarGet("BuyQty" + Name());
TempIndex[TempCount] = LastValue(DateTime());
TempPrice[TempCount] = BuyPriceValue;
TempQty[TempCount] = LotQuantity;
TempCount++;
StaticVarSet("BuyCount" + Name(), TempCount);
StaticVarSet(("BuyIndex" + Name()), TempIndex);
StaticVarSet(("BuyPrice" + Name()), TempPrice);
StaticVarSet(("BuyQty" + Name()), TempQty);
if(EnableAutoTrade == "Yes")
{
LastOrderNo = StaticVarGet("OrderNo");
LastOrderNo++;
StaticVarSet("OrderNo", LastOrderNo);
TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
TempName = Name() + "-EQ";
nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
}
}
if((LastValue(Sell) == True) && (StaticVarGet(("SellFlag" + Name())) != LastValue(DateTime())))
{
StaticVarSet(("SellFlag" + Name()), LastValue(DateTime()));
DrawBut("Sell", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40);
TempCount = StaticVarGet("SellCount" + Name());
TempIndex = StaticVarGet("SellIndex" + Name());
TempPrice = StaticVarGet("SellPrice" + Name());
TempQty = StaticVarGet("SellQty" + Name());
TempIndex[TempCount] = LastValue(DateTime());
TempPrice[TempCount] = SellPriceValue;
TempQty[TempCount] = LotQuantity;
TempCount++;
StaticVarSet("SellCount" + Name(), TempCount);
StaticVarSet(("SellIndex" + Name()), TempIndex);
StaticVarSet(("SellPrice" + Name()), TempPrice);
StaticVarSet(("SellQty" + Name()), TempQty);
if(EnableAutoTrade == "Yes")
{
LastOrderNo = StaticVarGet("OrderNo");
LastOrderNo++;
StaticVarSet("OrderNo", LastOrderNo, 1);
TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
TempName = Name() + "-EQ";
nestplus.PlaceOrder("SELL", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, SellPriceValue, 0.0, 0, ProductType, ClientIdValue);
}
}
if((LastValue(Short) == True) && (StaticVarGet(("ShortFlag" + Name())) != LastValue(DateTime())))
{
StaticVarSet(("ShortFlag" + Name()), LastValue(DateTime()));
DrawBut("Short", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40);
TempCount = StaticVarGet("ShortCount" + Name());
TempIndex = StaticVarGet("ShortIndex" + Name());
TempPrice = StaticVarGet("ShortPrice" + Name());
TempQty = StaticVarGet("ShortQty" + Name());
TempIndex[TempCount] = LastValue(DateTime());
TempPrice[TempCount] = SellPriceValue;
TempQty[TempCount] = LotQuantity;
TempCount++;
StaticVarSet("ShortCount" + Name(), TempCount);
StaticVarSet(("ShortIndex" + Name()), TempIndex);
StaticVarSet(("ShortPrice" + Name()), TempPrice);
StaticVarSet(("ShortQty" + Name()), TempQty);
if(EnableAutoTrade == "Yes")
{
LastOrderNo = StaticVarGet("OrderNo");
LastOrderNo++;
StaticVarSet("OrderNo", LastOrderNo);
TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
TempName = Name() + "-EQ";
nestplus.PlaceOrder("SELL", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, SellPriceValue, 0.0, 0, ProductType, ClientIdValue);
}
}
if((LastValue(Cover) == True) && (StaticVarGet(("CoverFlag" + Name())) != LastValue(DateTime())))
{
StaticVarSet(("CoverFlag" + Name()), LastValue(DateTime()));
DrawBut("Cover", X0+X1+10, Y0, X0+X1+75, Y0+30, colorGrey40, colorGrey40);
TempCount = StaticVarGet("CoverCount" + Name());
TempIndex = StaticVarGet("CoverIndex" + Name());
TempPrice = StaticVarGet("CoverPrice" + Name());
TempQty = StaticVarGet("CoverQty" + Name());
TempIndex[TempCount] = LastValue(DateTime());
TempPrice[TempCount] = BuyPriceValue;
TempQty[TempCount] = LotQuantity;
TempCount++;
StaticVarSet("CoverCount" + Name(), TempCount);
StaticVarSet(("CoverIndex" + Name()), TempIndex);
StaticVarSet(("CoverPrice" + Name()), TempPrice);
StaticVarSet(("CoverQty" + Name()), TempQty);
if(EnableAutoTrade == "Yes")
{
LastOrderNo = StaticVarGet("OrderNo");
LastOrderNo++;
StaticVarSet("OrderNo", LastOrderNo, 1);
TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
TempName = Name() + "-EQ";
nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
}
}
}
X0 = 180;
Y0 = 30;
if(EnableRealTimeControl == "Yes")
{
TotPrice = 0;
TotQty = 0;
TotVal = 0;
TempPriceArray = StaticVarGet("BuyPrice" + Name());
TempQtyArray = StaticVarGet("BuyQty" + Name());
TempCount = StaticVarGet("BuyCount" + Name());
for(i = 0; i < TempCount; i++)
{
TotPrice = TotPrice + TempPriceArray[i];
TotQty = TotQty + TempQtyArray[i];
TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
}
if(TempCount == 0)
{
AvgBuyPrice = 0;
LastBuyPrice = 0;
LastBuyQty = 0;
}
else
{
AvgBuyPrice = (TotPrice / TempCount);
LastBuyPrice = TempPriceArray[(TempCount - 1)];
LastBuyQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
}
TotBuyQty = NumToStr(TotQty, 1, 0);
NetBuyQty = TotQty;
NetBuyValue = TotVal;
TotPrice = 0;
TotQty = 0;
TotVal = 0;
TempPriceArray = StaticVarGet("SellPrice" + Name());
TempQtyArray = StaticVarGet("SellQty" + Name());
TempCount = StaticVarGet("SellCount" + Name());
for(i = 0; i < TempCount; i++)
{
TotPrice = TotPrice + TempPriceArray[i];
TotQty = TotQty + TempQtyArray[i];
TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
}
if(TempCount == 0)
{
AvgSellPrice = 0;
LastSellPrice = 0;
LastSellQty = 0;
}
else
{
AvgSellPrice = (TotPrice / TempCount);
LastSellPrice = TempPriceArray[(TempCount - 1)];
LastSellQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
}
TotSellQty = NumToStr(TotQty, 1, 0);
NetSellQty = TotQty;
NetSellValue = TotVal;
TotPrice = 0;
TotQty = 0;
TotVal = 0;
TempPriceArray = StaticVarGet("ShortPrice" + Name());
TempQtyArray = StaticVarGet("ShortQty" + Name());
TempCount = StaticVarGet("ShortCount" + Name());
for(i = 0; i < TempCount; i++)
{
TotPrice = TotPrice + TempPriceArray[i];
TotQty = TotQty + TempQtyArray[i];
TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
}
if(TempCount == 0)
{
AvgShortPrice = 0;
LastShortPrice = 0;
LastShortQty = 0;
}
else
{
AvgShortPrice = (TotPrice / TempCount);
LastShortPrice = TempPriceArray[(TempCount - 1)];
LastShortQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
}
TotShortQty = NumToStr(TotQty, 1, 0);
NetShortQty = TotQty;
NetShortValue = TotVal;
TotPrice = 0;
TotQty = 0;
TotVal = 0;
TempPriceArray = StaticVarGet("CoverPrice" + Name());
TempQtyArray = StaticVarGet("CoverQty" + Name());
TempCount = StaticVarGet("CoverCount" + Name());
for(i = 0; i < TempCount; i++)
{
TotPrice = TotPrice + TempPriceArray[i];
TotQty = TotQty + TempQtyArray[i];
TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
}
if(TempCount == 0)
{
AvgCoverPrice = 0;
LastCoverPrice = 0;
LastCoverQty = 0;
}
else
{
AvgCoverPrice = (TotPrice / TempCount);
LastCoverPrice = TempPriceArray[(TempCount - 1)];
LastCoverQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
}
TotCoverQty = NumToStr(TotQty, 1, 0);
NetCoverQty = TotQty;
NetCoverValue = TotVal;
NetQty = NetSellQty - NetBuyQty + NetShortQty - NetCoverQty;
NetValue = NetSellValue - NetBuyValue + NetShortValue - NetCoverValue;
NetQuantityColor = colorGrey40;
NetValueColor = colorGrey40;
if(NetQty > 0)
{
NetQuantityColor = colorRed;
NetValueColor = colorRed;
}
else if(NetQty < 0)
{
NetQuantityColor = colorGreen;
NetValueColor = colorGreen;
}
else if(NetQty == 0)
{
if(NetValue > 0)
{
NetValueColor = colorGreen;
}
else if(NetValue < 0)
{
NetValueColor = colorRed;
}
}
DrawData (" AvgBuyPr: " + AvgBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
DrawData (" TotBuyQty: " + TotBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
DrawData (" AvgSellPr: " + AvgSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
DrawData (" TotSellQty: " + TotSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
DrawData (" AvgShortPr: " + AvgShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
DrawData (" TotShortQty: " + TotShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
DrawData (" AvgCoverPr: " + AvgCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
DrawData (" TotCoverQty: " + TotCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
Y0 = 50;
DrawData (" LastBuyPr: " + LastBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastBuyQty: " + LastBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastSellPr: " + LastSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastSellQty: " + LastSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastShortPr: " + LastShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastShortQty: " + LastShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastCoverPr: " + LastCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
DrawData (" LastCoverQty: " + LastCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
Y0 = 70;
DrawData (" LTP : " + CurrentTradedPrice, X0, Y0, X0+125, Y0+15, LTPColor, LTPColor);
DrawData (" LTQ : " + NumToStr(CurrentLTQ,1,0), X0+130, Y0, X0+255, Y0+15, LTQColor, LTQColor);
DrawData (" Bid : " + CurrentBidPrice, X0+260, Y0, X0+385, Y0+15, AskColor, AskColor);
DrawData (" Ask : " + CurrentAskPrice, X0+390, Y0, X0+515, Y0+15, BidColor, BidColor);
NestOredrNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + StaticVarGet("OrderNo");
DrawData (" NetQty : " + NetQty, X0+520, Y0, X0+670, Y0+15, NetQuantityColor, NetQuantityColor);
DrawData (" NetValue : " + NetValue, X0+675, Y0, X0+900, Y0+15, NetValueColor, NetValueColor);
DrawData (" Order No : " + NestOredrNo, X0+905, Y0, X0+1150, Y0+15, colorGrey40, colorGrey40);
}
_SECTION_END();
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \nOpen : %g, Close : %g (%.1f%%) \nLow : %g, High : %g (%.1f%%) \nVolume : " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, C,(((C-O)*100)/O), L, H, (((H-L)*100)/L) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 10, 2, 200, 1 );
Plot( MA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorGreen ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 30, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorOrange ), ParamStyle("Style", styleLine | styleNoLabel) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 45, 2, 400, 1 );
Plot( MA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorYellow ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Color = ColorBlend( Color, GetChartBkColor(), 0.5 );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), /*"BBTop" + _PARAM_VALUES()*/ "", Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), /*"BBBot" + _PARAM_VALUES()*/ "", Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, GetChartBkColor(), 0.7 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();
_SECTION_BEGIN("Volume");
Color = ParamColor("Color", ColorRGB( 128, 128, 192 ) );
Plot( Volume, /*_DEFAULT_NAME()*/"", ColorBlend( Color, GetChartBkColor(), 0.2 ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );
_SECTION_END();
Subscribe to:
Posts (Atom)










