Simple Coding Help - No Promise.

Dear @Happy_Singh Kindly help me in the following

I have this AFL which plots Central Pivot Range (CPR) and Pivot support/resistances, for both the current day and for the upcoming/next day.

What I really need is, it should also plot ‘DEVELOPING CPR OF THE DAY’ starting from the first candle of the intraday chart and ending at the last candle.

It simply means, how the CPR is shaping up during the intraday, which at the end of the trading day, becomes ‘next’ day CPR.

Here is the code:

_SECTION_BEGIN( "CPR" );
dtDayStartComp = TimeFrameCompress( DateTime(), inDaily, compressOpen );
dtDayStartExp = TimeFrameExpand( dtDayStartComp, inDaily, expandFirst );
dtDayEndComp = TimeFrameCompress( DateTime(), inDaily, compressLast );
dtDayEndExp = TimeFrameExpand( dtDayEndComp, inDaily, expandFirst );
DayCond = DateTime() >= dtDayStartExp AND DateTime() < dtDayEndExp;

// Previous Days High Low Close
PDH = TimeFrameGetPrice( "H", inDaily, -1 );
PDL = TimeFrameGetPrice( "L", inDaily, -1 );
PDC = TimeFrameGetPrice( "C", inDaily, -1 );

PV = ( PDH + PDL + PDC ) / 3;
LB = ( PDH + PDL ) / 2;
UB = (PV - LB) + PV;

Plot( IIf( DayCond, UB, Null ), "UB", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, UB, Null ), "UB", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );

Plot( IIf( DayCond, PV, Null), "Pivot", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, PV, Null), "Pivot", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );

Plot( IIf( DayCond, LB, Null), "LB", colorBlack, styleLine, styleNoRescale, Null, Null, 0 );
Plot( IIf( DayCond, LB, Null), "LB", colorBlack, styleLine, styleNoRescale, Null, Null, 2 );
_SECTION_END();

_SECTION_BEGIN( "Pivot Levels" );
//PDH = TimeFrameGetPrice( "H", inDaily, -1 );
//PDL = TimeFrameGetPrice( "L", inDaily, -1 );
//PDC = TimeFrameGetPrice( "C", inDaily, -1 );

//PV = ( PDH + PDL + PDC ) / 3;
R1 = 2 * PV - PDL;
R2 = PV + PDH - PDL;
S1 = 2 * PV - PDH;
S2 = PV - PDH + PDL;

Plot( IIf( DayCond, R1, Null ), "R1", colorBlue, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, R1, Null ), "R1", colorBlue, styleLine, styleNoRescale, Null, Null, 2 );

Plot( IIf( DayCond, R2, Null ), "R2", colorRed, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, R2, Null ), "R2", colorRed, styleLine, styleNoRescale, Null, Null, 2 );

Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, S1, Null ), "S1", colorGreen, styleLine, styleNoRescale, Null, Null, 2 );

Plot( IIf( DayCond, S2, Null ), "S2", colorDarkGreen, styleLine + styleThick, Null, Null, 0 );
Plot( IIf( DayCond, S2, Null ), "S2", colorDarkGreen, styleLine, styleNoRescale, Null, Null, 2 );
_SECTION_END();

_SECTION_BEGIN( "Price1" );
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN( "To view Pivots of Next Day as Today closes" );
shift = 10; //Number of Bars to be shifted, could use a Param if needed
bi = BarIndex();
lvbi = LastValue( bi );
LAx0 = lvbi - shift + 1;
LAx1 = lvbi;

// Present Days High Low Close
// These levels will be dynamic as day progresses and would ahow up in the no bar region after the last visible Bar for shifted number of bars (i.e. 10 in this case)
// Do use "Bar Replay" to figure out what I mean
dH = TimeFrameGetPrice( "H", inDaily, 0 );
dL = TimeFrameGetPrice( "L", inDaily, 0 );
dC = TimeFrameGetPrice( "C", inDaily, 0 );

//Central Pivots shifted for Next Day
dPV = ( dH + dL + dC ) / 3;
LB = ( dH + dL ) / 2;
UB = (dPV - LB) + dPV;

y = LastValue( dPV );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "PV", colorBlack, styleLine, Null, Null, shift );

y = LastValue( LB );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "LB", colorBlack, styleLine, Null, Null, shift );

y = LastValue( UB );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "UB", colorBlack, styleLine, Null, Null, shift );

//Pivot Levels shifted for Next Day
R1 = 2 * dPV - dL;
R2 = dPV + dH - dL;
S1 = 2 * dPV - dH;
S2 = dPV - dH + dL;

y = LastValue( R1 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "R1", colorBlue, styleLine + styleThick, Null, Null, shift );

y = LastValue( R2 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "R2", colorRed, styleLine + styleThick, Null, Null, shift );

y = LastValue( S1 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "S1", colorGreen, styleLine + styleThick, Null, Null, shift );

y = LastValue( S2 );
la = LineArray( LAx0, y, LAx1, y );
Plot( la, "S2", colorDarkGreen, styleLine + styleThick, Null, Null, shift );
_SECTION_END();


Thanks and regards,
 
I never said this is written by me. I am not sure, where I saw this code, a lot of googling perhaps. I found it interesting and wanted to add Developing CPR in the same as mentioned by Frank Ochoa in his book. I have no intention of hijacking and taking credit for anyone's effort. I am sorry if I have offended you in any way.
 
A lot of heated words here, and a lot of reported posts.

The reported posts have been deleted and I have advised restraints on some members.

I request all the readers, specially the thread starters, to immediately report any off-topic posts immediately.

@CougarTrader , you have done a commendable job of noticing Amibroker pirates. I request that in future, when you notice any such posts, just report them to the mods instead of replying to those posts.
 

sanju005ind

Investor, Option Writer
Cougar Bro it is great that you have highlighted the issues about Ami Piracy in a separate thread.However pursuing every individual in this forum on every thread like some folks might have just clicked on Like button reeks of trolling. There is thin line between highlighting the issues and vigilantism, for which a valuable member like you should not be excluded. I URGE to not keep following members into each and every thread and admonish them. I wish you all the best.

How come you are interested in AmiBroker now???

View attachment 38038

To all the big-shots participating here, STOP using pirated versions of AmiBroker. Piracy is a crime and you can be traced.
 

toocool

Well-Known Member
hi

can experts please code simple vwap/atp code which extends final vwap or atp price of current day to the next day as a line for full trading day , and so on ..............

regards
 

CougarTrader

Well-Known Member
Cougar Bro it is great that you have highlighted the issues about Ami Piracy in a separate thread.However pursuing every individual in this forum on every thread like some folks might have just clicked on Like button reeks of trolling. There is thin line between highlighting the issues and vigilantism, for which a valuable member like you should not be excluded. I URGE to not keep following members into each and every thread and admonish them. I wish you all the best.
The problem is that people shamelessly steal and still shout... It's no longer a question of being right or wrong! It's a question on everyone's character...
 
Dear Happy Singh

Iam a beginner and trying to learn backtesting

Pls let me know why this simple code does not work?

I have written detailed comments besides the code. I have been searching the forums for an understanding of the code issue but in vain.

Pls do check and advice where iam erring. Let me know if you require more info.

Thanks a lot !!

if(entrytrigger =2); /*pls refer to the last code comment, just before "Buy = Entry;". This is being checked because i do not want to take a new trade unless the previous trade's SL or Profit is hit.*/
{
Entry = Open < Close AND Ref(High,1) > High ; /*Simple buy rule to buy on a green candle and when the next bar crosses high of the green bar. The next bar can be a red bar but only condition is that it should cross the previous high. The buy will trigger only when the immediate next bar crosses the high of the green bar else the trade is off*/
if (Entry = True); /*iam checking whether there is an entry and if true then iam setting the SL and Profit target as per below codes. Unless there is an entry, there should not be any SL or Profit targets*/
{
SLLong = Low; /*SL is set at the low of the green bar*/
PRLong = High+((High-Low)*2); /*Profit target is set at twice the range of the green bar*/
entrytrigger = 1; /*iam setting this to control that the backtest engine does not take another entry unless either the SL is triggered or the profit target is hit.*/
}
}

if (Entry = True AND entrytrigger = 1); /*iam setting the condition to check whether the SL or Profit target is hit only when there is an entry is true and entrytrigger is set as 1*/
{
SLPRhit = IIf(High >= PRLong OR Low < SLLong,1,0); /* checking either SL or Profit is hit in subsequent bars
entrytrigger = IIf(SLPRhit=1,2,1); //Resetting the entry trigger to 2 once the SL or Profit is hit so that the next entry can be searched as per the first line of the code*/
}

Buy = Entry;
Sell = SLPRhit;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
 
Please re-read the basic sections in the manual / AFL reference
assignment operator is = where as
logical comparison operator is ==


ExRem removes all the extra buy/short signals


.
 

Similar threads