Simple Coding Help - No Promise.

sir please see attached images

actual ribbon of 10 min which should appear as it is on 5 min, but on 5 min chart ribbon is very different then 10 min chart
Its Logic flaw and will reveal itself to you if you plot BridgeT2f.

You are showing 5 min chart, but you compute at 10 min levels. So AB computes once for every two candles being shown. It merges two candles as one. When you expand, it assigns same value to both the candles.

Your color assignment IIF stmt only assigns red or blue color if values are different but assign gray for equal values and that is what you see.

That is what shows up. One solution would be to change the iif statement to have >= instead of > or <= instead of <. Another solution is already given by extremist (to assign color at 10 min level and expand it back)

Lastly, How on earth (all pun intended) does this code reveal trades?
 

Nehal_s143

Well-Known Member
extremist sir, I want to use 10min TF code in buy sell condition, if I expand ribbon directly then it will show correctly on chart but cant use it in buy and sell condition

//on price chart
Buy =C>O AND (BridgeT2f >= Ref(BridgeT2f, -1));
Sell=C<O AND (BridgeT2f <= Ref(BridgeT2f, -1));

PlotShapes(Buy*shapeUpArrow,colorBlue,0,L,-42);
PlotShapes(Sell*shapeDownArrow,colorRed,0,H,-42);

I tried modify 10min TF code using extremist sir and matermind sir suggestion so that ribbon can be plotted after expanding indicator and not expanding ribbon
but result is not as required.

master mind sir re. does this code reveal trades? yes it does,
10 min chart will give current intra day trend, if ribbon is blue trend is up and if red trend is down, (mostly in rangebound market it will show clear trend)

i use this ribbon as additional confirmation for trade, but now want to use indicator code in buy sell condition itself

Code:
_SECTION_BEGIN("10min Earth");
tf=Param("Time Frame (min)",10,1,10,1);tfrm=in1Minute*tf;
TimeFrameSet(tfrm);

VarT2	= ( High + Low + Close * 2 ) / 4;
BT2		= (EMA((VarT2 - LLV(VarT2,15))/(HHV(Low, 15) - LLV(VarT2, 15)), 2)) * 38;
BotT2	= (((-1)) * (EMA( (VarT2- LLV(VarT2,15) ) / (HHV(Low, 15)-LLV(VarT2, 15)), 2) + 0.01)) * 38;
Var2T2	= ((Close-LLV(Low, 10))/(HHV(High, 10)-LLV(Low, 10))) * 100;
Var3T2	= EMA(Var2T2, 10);
Var4T2	= EMA(Var3T2, 10);
Var5T2	= 3 * Var3T2 - 2 * Var4T2;
Var6T2	= EMA(Var5T2, 5);
BridgeT2 = EMA(Var6T2, 1);

TimeFrameRestore() ;

BridgeT2f = TimeFrameExpand(BridgeT2, tfrm);

myc2ef=IIf(BridgeT2f >= Ref(BridgeT2f, -1),colorBlue,
       IIf(BridgeT2f <= Ref(BridgeT2f, -1),colorRed,31));

//myc2ef=TimeFrameExpand(myc2e, tfrm);

Plot(bridget2f, "", IIf(bridget2f > Ref(bridget2f,-1),colorBlue,colorRed), 1+4);
//Plot(-bridget2, "", IIf(bridget2f > Ref(bridget2f,-1),colorBlue,colorRed), 1+4);

Plot(6, "ribbon", myc2ef, styleOwnScale | styleArea|styleNoLabel, 0.1, 100);
_SECTION_END();

_SECTION_BEGIN("Earth-2");
VAR2=(High+Low+(Close)*(2))/(4);
B = ((EMA((VAR2-LLV(VAR2,15))/(HHV(Low,15)-LLV(VAR2,15)),2))*(38));
//Plot(b, "", 4, 1+4);
bot1 = ((((-1))*(EMA((VAR2-LLV(VAR2,15))/(HHV(Low,15)-LLV(VAR2,15)),2))+0.01)*(38));
//Plot(bot1, "", 4, 1+4);
VAR22=((Close-LLV(Low,10))/(HHV(High,10)-LLV(Low,10)))*(100);
VAR33=EMA(VAR22,10);
VAR44=EMA(VAR33,10);
VAR55=(3)*(VAR33)-(2)*(VAR44);
VAR66=EMA(VAR55,5);
BridgeT = (EMA(VAR66,1));
//Plot(bridget, "", IIf(bridget > Ref(bridget,-1),colorBlue,colorRed), 1+4);
//Plot(-bridget, "", IIf(bridget > Ref(bridget,-1),colorBlue,colorRed), 1+4);

myc=IIf(BridgeT > Ref(BridgeT, -1),colorBlue,
    IIf(BridgeT < Ref(BridgeT, -1),colorRed,31));

//Plot(12, "ribbon", myc, styleOwnScale| styleArea|styleNoLabel,-0.5,100);

//Plot(0,"",colorYellow,styleLine);

_SECTION_END();
 

extremist

Well-Known Member
extremist sir, I want to use 10min TF code in buy sell condition, if I expand ribbon directly then it will show correctly on chart but cant use it in buy and sell condition

//on price chart
Buy =C>O AND (BridgeT2f >= Ref(BridgeT2f, -1));
Sell=C<O AND (BridgeT2f <= Ref(BridgeT2f, -1));

PlotShapes(Buy*shapeUpArrow,colorBlue,0,L,-42);
PlotShapes(Sell*shapeDownArrow,colorRed,0,H,-42);

I tried modify 10min TF code using extremist sir and matermind sir suggestion so that ribbon can be plotted after expanding indicator and not expanding ribbon
but result is not as required.

master mind sir re. does this code reveal trades? yes it does,
10 min chart will give current intra day trend, if ribbon is blue trend is up and if red trend is down, (mostly in rangebound market it will show clear trend)

i use this ribbon as additional confirmation for trade, but now want to use indicator code in buy sell condition itself

Code:
_SECTION_BEGIN("10min Earth");
tf=Param("Time Frame (min)",10,1,10,1);tfrm=in1Minute*tf;
TimeFrameSet(tfrm);

VarT2	= ( High + Low + Close * 2 ) / 4;
BT2		= (EMA((VarT2 - LLV(VarT2,15))/(HHV(Low, 15) - LLV(VarT2, 15)), 2)) * 38;
BotT2	= (((-1)) * (EMA( (VarT2- LLV(VarT2,15) ) / (HHV(Low, 15)-LLV(VarT2, 15)), 2) + 0.01)) * 38;
Var2T2	= ((Close-LLV(Low, 10))/(HHV(High, 10)-LLV(Low, 10))) * 100;
Var3T2	= EMA(Var2T2, 10);
Var4T2	= EMA(Var3T2, 10);
Var5T2	= 3 * Var3T2 - 2 * Var4T2;
Var6T2	= EMA(Var5T2, 5);
BridgeT2 = EMA(Var6T2, 1);

TimeFrameRestore() ;

BridgeT2f = TimeFrameExpand(BridgeT2, tfrm);

myc2ef=IIf(BridgeT2f >= Ref(BridgeT2f, -1),colorBlue,
       IIf(BridgeT2f <= Ref(BridgeT2f, -1),colorRed,31));

//myc2ef=TimeFrameExpand(myc2e, tfrm);

Plot(bridget2f, "", IIf(bridget2f > Ref(bridget2f,-1),colorBlue,colorRed), 1+4);
//Plot(-bridget2, "", IIf(bridget2f > Ref(bridget2f,-1),colorBlue,colorRed), 1+4);

Plot(6, "ribbon", myc2ef, styleOwnScale | styleArea|styleNoLabel, 0.1, 100);
_SECTION_END();

_SECTION_BEGIN("Earth-2");
VAR2=(High+Low+(Close)*(2))/(4);
B = ((EMA((VAR2-LLV(VAR2,15))/(HHV(Low,15)-LLV(VAR2,15)),2))*(38));
//Plot(b, "", 4, 1+4);
bot1 = ((((-1))*(EMA((VAR2-LLV(VAR2,15))/(HHV(Low,15)-LLV(VAR2,15)),2))+0.01)*(38));
//Plot(bot1, "", 4, 1+4);
VAR22=((Close-LLV(Low,10))/(HHV(High,10)-LLV(Low,10)))*(100);
VAR33=EMA(VAR22,10);
VAR44=EMA(VAR33,10);
VAR55=(3)*(VAR33)-(2)*(VAR44);
VAR66=EMA(VAR55,5);
BridgeT = (EMA(VAR66,1));
//Plot(bridget, "", IIf(bridget > Ref(bridget,-1),colorBlue,colorRed), 1+4);
//Plot(-bridget, "", IIf(bridget > Ref(bridget,-1),colorBlue,colorRed), 1+4);

myc=IIf(BridgeT > Ref(BridgeT, -1),colorBlue,
    IIf(BridgeT < Ref(BridgeT, -1),colorRed,31));

//Plot(12, "ribbon", myc, styleOwnScale| styleArea|styleNoLabel,-0.5,100);

//Plot(0,"",colorYellow,styleLine);

_SECTION_END();
MR. Nehal...
It seems tht u didn't read my explanation properly.
U r again doing the same mistake.
Once u expand any HTF array on LTF there is possibility tht ref wont work properly on tht expanded array.
i explained it in detailed in my first post.

Now i would suggest u to please go through it again.

I took pain of typing so tht u wont need again any help on TF expand.
If u go through it calmly u will click the right note.
 
extremist sir, I want to use 10min TF code in buy sell condition, if I expand ribbon directly then it will show correctly on chart but cant use it in buy and sell condition

//on price chart
Buy =C>O AND (BridgeT2f >= Ref(BridgeT2f, -1));
Sell=C<O AND (BridgeT2f <= Ref(BridgeT2f, -1));

Can you not JUMP the candle? Instead of looking at preceding expanded bar, look at the 2 bars backwards.

Buy =C>O AND (BridgeT2f >= Ref(BridgeT2f, -2));
Sell=C<O AND (BridgeT2f <= Ref(BridgeT2f, -2));

Do understand that once you do this, you are effectively locking lower timeframe as 5 and HTF as 10. If you experiment with 1 min or 3 min or something like that, such code will again fail
 

ethan hunt

Well-Known Member
Whenever we run a backtest we have option to choose trade at open,hi,lo,close,avg with a delay of n bars.

Suppose if we get a signal to enter a trade on EOD charts.

We try to get into a trade at open next day which is not at all practically possible, hence the backtesting results are not correct.

Is there a standard formula (or some other way within amibroker) which can be added to an AFL so that the entry trade (for back test) is considered at open of say 2nd or 3rd bar in Intraday charts once we have an entry signal from EOD charts the previous day.
 

Nehal_s143

Well-Known Member
Can you not JUMP the candle? Instead of looking at preceding expanded bar, look at the 2 bars backwards.

Buy =C>O AND (BridgeT2f >= Ref(BridgeT2f, -2));
Sell=C<O AND (BridgeT2f <= Ref(BridgeT2f, -2));

Do understand that once you do this, you are effectively locking lower timeframe as 5 and HTF as 10. If you experiment with 1 min or 3 min or something like that, such code will again fail
Thank you very much mastermind sir, it worked perfectly for me :) Thank you once again
 
Can someone help me creating a function or a loop that will only plot the recent x number of the array.

Specifically I am using one of E.M. Pottash trendlines and I would like to only plot the last 3 or 5 trendlines. Does anyone know how can I do that?
 
Can someone help me creating a function or a loop that will only plot the recent x number of the array.

Specifically I am using one of E.M. Pottash trendlines and I would like to only plot the last 3 or 5 trendlines. Does anyone know how can I do that?

for (i = 0; i < 5; i++)
Plot(LastValue(Ref (X, -i)), "", color..., style...);

Edit underlined portion as needed.
 

hmp

Well-Known Member
It would be great help if someone can add buy/sell scanning to this afl.

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

trendup = IIf(MACD(12,26) > 0 AND MACD(12,26) > Signal(12,26,9), colorGreen, colorWhite);
trendcolor = IIf(MACD(12,26) < 0 AND MACD(12,26) < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleBar | styleThick );

//RSIup = RSI(7) > 70;
//RSIdown = RSI(7) < 30;

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;

shape = RSIup * shapeSmallUpTriangle + RSIdown * shapeSmallDownTriangle;
PlotShapes(shape, IIf( RSIup, colorGreen, colorRed ), 0, IIf( RSIup, Low, High ) );

if( ParamToggle("Tooltip shows", "All Values | Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();


_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 12, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style") | styleNoRescale;
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );

// calcul average daily range pe ultimele 7 zile

HD1 = TimeFrameGetPrice("H", inDaily, -1);
LD1 = TimeFrameGetPrice("L", inDaily, -1);
M1 = HD1 - LD1;
HD2 = TimeFrameGetPrice("H", inDaily, -2);
LD2 = TimeFrameGetPrice("L", inDaily, -2);
M2 = HD2 - LD2;
HD3 = TimeFrameGetPrice("H", inDaily, -3);
LD3 = TimeFrameGetPrice("L", inDaily, -3);
M3 = HD3 - LD3;
HD4 = TimeFrameGetPrice("H", inDaily, -4);
LD4 = TimeFrameGetPrice("L", inDaily, -4);
M4 = HD4 - LD4;
HD5 = TimeFrameGetPrice("H", inDaily, -5);
LD5 = TimeFrameGetPrice("L", inDaily, -5);
M5 = HD5 - LD5;
HD6 = TimeFrameGetPrice("H", inDaily, -6);
LD6 = TimeFrameGetPrice("L", inDaily, -6);
M6 = HD6 - LD6;
HD7 = TimeFrameGetPrice("H", inDaily, -7);
LD7 = TimeFrameGetPrice("L", inDaily, -7);
M7 = HD7 - LD7;

//ADR = MA(High - Low,7);
ADR = (M1+M2+M3+M4+M5+M6+M7)/7;
tp = ADR*0.15;
sl = ADR*0.1;
//TimeFrameRestore();
Plot(ADR, "\nADR", colorBlue, styleNoLine | styleNoRescale | styleNoLabel);
Plot(tp, "TP", colorBlue, styleNoLine | styleNoRescale | styleNoLabel);
Plot(sl, "SL", colorBlue, styleNoLine | styleNoRescale | styleNoLabel);

// ----------------

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

trendup = IIf(MACD(12,26) > 0 AND MACD(12,26) > Signal(12,26,9), colorGreen, colorBlack);
trendcolor = IIf(MACD(12,26) < 0 AND MACD(12,26) < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleBar | styleThick );

//RSIup = RSI(7) > 70;
//RSIdown = RSI(7) < 30;

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;

shape = RSIup * shapeSmallUpTriangle + RSIdown * shapeSmallDownTriangle;
PlotShapes(shape, IIf( RSIup, colorGreen, colorRed ), 0, IIf( RSIup, Low, High ) );

if( ParamToggle("Tooltip shows", "All Values | Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();

Thanks & regards
 

Similar threads