Help in Exploration in RSI divergence AFL

I am EOD trader and I have only EOD data base.
When I am doing exploration - signals are coming after one day.

For example : in the below exploration chart - Buy Signal generated on 29th Aug , Buy Signal displayed after Importing 1st Sep EOD data. How to get signal on 29th Aug only?
Trading days after 29th Aug : 30 Aug & 1st Sep.
Please help .

_N(Title = StrFormat("{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption( "AllowPositionShrinking", True );

indName = "RSI"; // Specify the name of the indicator. This is cosmetic only.
length = Param(indName + " Length", 14, 8, 100, 1); // Indicator length
threshold = Param("Zig/Zag Threshold %", 10, 1, 50, 1); // Minimum % change in indicator value to be considered a zig/zag
indVal = RSI(length); // Load the indVal array with the values from the indicator of your choice
indZig = Zig(indVal, threshold); // Set the zig/zag values for the indicator
indPeakVal1 = Peak(indVal, threshold, 1); // Most recent peak value
indPeakBars1 = PeakBars(indVal, threshold, 1); // Bars since most recent peak
indPeakVal2 = Peak(indVal, threshold, 2); // Second most recent peak value
indPeakBars2 = PeakBars(indVal, threshold, 2); // Bars since second most recent peak
indTroughVal1 = Trough(indVal, threshold, 1); // Most recent trough value
indTroughBars1 = TroughBars(indVal, threshold, 1); // Bars since most recent trough
indTroughVal2 = Trough(indVal, threshold, 2); // Second most recent trough value
indTroughBars2 = TroughBars(indVal, threshold, 2); // Bars since second most recent trough
// Determine if current bar is a peak or trough
peakBar = indPeakBars1 == 0;
troughBar = indTroughBars1 == 0;

printf("\n peakBar  : " + peakBar ); 
printf("\n troughBar  : " + troughBar ); 

// Bearish divergence
divergeBear = IIf(peakBar AND (indPeakVal1 < indPeakVal2) AND High > Ref(High, -indPeakBars2), True, False);
// Bullish divergence
divergeBull = IIf((indTroughBars1 == 0) AND (indTroughVal1 > indTroughVal2) AND Low < Ref(Low, -indTroughBars2), True, False);

printf("\n divergeBear  : " + divergeBear ); 
printf("\n divergeBull  : " + divergeBull ); 


printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);


Filter=Buy OR Sell OR Short OR Cover;
 AddColumn(IIf(Buy,BUY,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
 AddColumn(IIf(Sell,Sell,Null)," Sell Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Short,Short,Null)," Short Signal ", 6.2,1.2,colorRed); 
AddColumn(IIf(Cover,Cover,Null)," Cover Signal ",6.2,1.2,colorBlue);

@ jp_b4u, please note that when you post a formula, you must always include it in the required code tags.

The delays are set using the SetTradeDelays(). See the documentation and search the forum for further details about the correct use (in combination with the BuyPrice/SellPrice, etc.)

In any case, your formula results seem unrealistic since you are using the Zig() function (again, please, search the forum to learn about the problems related to its usage and in general about future quotes leaks).

I suggest using the "Check Code and Profile" tool provided by AmiBroker to make sure you no longer have this type of problem.


Here is the result applied to your formula:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.