Simple Coding Help - No Promise.

extremist

Well-Known Member
Hello traders,

Adding to this thread..

Would anyone know how to create an indicator that would return a value
relative to the moving average.
Example 1:
Say current price = 50, 21 period EMA = 45. Value returned = 5 (50-45)

Example 2:
Say current price = 50, 21 period EMA = 52. Value returned = -2 (50-52)

thanks
Mathew
if u want to get the above indicator plotted use MACD.

Apply macd
then by right clicking on it go to parameters.
Change the parameter 12 to 1 and 26 to 21

u will get ur desired indicator plotted.
 
if u want to get the above indicator plotted use MACD.

Apply macd
then by right clicking on it go to parameters.
Change the parameter 12 to 1 and 26 to 21

u will get ur desired indicator plotted.
Hello traders,

Adding to this thread..

Would anyone know how to create an indicator that would return a value
relative to the moving average.
Example 1:
Say current price = 50, 21 period EMA = 45. Value returned = 5 (50-45)

Example 2:
Say current price = 50, 21 period EMA = 52. Value returned = -2 (50-52)

thanks
Mathew
Try this please.


var=iif((c>=ema(c,21)),(c-ema(c,21)),(ema(c,21)-c));
 

Blackhole

Well-Known Member
hi everyone!


this is an excellent thread! simply loved it.


I need some some in afl, hope programmers can help.


like i want to start trade nifty with 200 unit (8 lots) and start booking profit after

25 point book 50 %
25point book 25%
25 point book 25%

if in any case prf booking missed selll or cover entire position in reverse trend or move sl in afl

if incurred loss increase by 2 lot in our case 250 : 10 lots, if again loss increase by 2 lots.........


only intraday....ie 4 loss in same day 4 times lot is increased, if entire day is in loss...next day trading with same lot size....\\\\



i searched on net and download some codes with scale in and outbut got errors and its not working.

....same code with pyramiding....ie instead of booking profit it should add at regular internals and then sell off.....




thanks
 
Friends,

Attached is the Camarilla Afl. Please highlight the resistance and support levels on the right side so that it will be easy to see the corresponding levels.

Also, S3 and R3 lines needs to be thick to easily differentiate from others.

//---- pivot points
DayH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); // low
DayC = TimeFrameGetPrice("C", inDaily, -1); // close
DayO = TimeFrameGetPrice("O", inDaily); // current day open


//............camarilla pivots

H4 = ( (DayH-DayL) * (1.1/2) ) + DayC;
H3 = ( (DayH-DayL) * (1.1/4) ) + DayC;
H2 = ( (DayH-DayL) * (1.1/6) ) + DayC;
H1 = ( (DayH-DayL) * (1.1/12) ) + DayC;

L1 = DayC - ( (DayH-DayL) * (1.1/12) );
L2 = DayC - ( (DayH-DayL) * (1.1/6) ) ;
L3 = DayC - ( (DayH-DayL) * (1.1/4) ) ;
L4 = DayC - ( (DayH-DayL) * (1.1/2) ) ;

Plot(H4, "R4",colordarkgreen,styleLine+styleNoLabel);
Plot(H3, "R3",colordarkgreen,styleLine+styleNoLabel);
Plot(H2, "R2",colordarkgreen,styleline+styleNoLabel);
Plot(H1, "R1",colordarkgreen,styleLine+styleNoLabel);

Plot(L4, "S4",colorRed,styleLine+styleNoLabel);
Plot(L3, "S3",colorRed,styleLine+styleNoLabel);
Plot(L2, "S2",colorRed,styleLine+styleNoLabel);
Plot(L1, "S1",colorRed,styleLine+styleNoLabel);

_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();
 

amitrandive

Well-Known Member
Friends,

Attached is the Camarilla Afl. Please highlight the resistance and support levels on the right side so that it will be easy to see the corresponding levels.

Also, S3 and R3 lines needs to be thick to easily differentiate from others.
Try this

Also for changing the color for any area ,modify the color highlighted as required.
Code:
PlotOHLC(L3,L3,L4,L4,"",[B][COLOR="Blue"]colorPink[/COLOR][/B],styleCloud);
Code:
_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(); 
//---- pivot points
DayH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); // low
DayC = TimeFrameGetPrice("C", inDaily, -1); // close
DayO = TimeFrameGetPrice("O", inDaily); // current day open


//............camarilla pivots

H4 = ( (DayH-DayL) * (1.1/2) ) + DayC;
H3 = ( (DayH-DayL) * (1.1/4) ) + DayC;
H2 = ( (DayH-DayL) * (1.1/6) ) + DayC;
H1 = ( (DayH-DayL) * (1.1/12) ) + DayC;

L1 = DayC - ( (DayH-DayL) * (1.1/12) );
L2 = DayC - ( (DayH-DayL) * (1.1/6) ) ;
L3 = DayC - ( (DayH-DayL) * (1.1/4) ) ;
L4 = DayC - ( (DayH-DayL) * (1.1/2) ) ;

Plot(H4, "R4",colorDarkGreen,styleLine+styleNoLabel);
Plot(H3, "R3",colorDarkGreen,styleLine+styleNoLabel+styleThick);
Plot(H2, "R2",colorDarkGreen,styleLine+styleNoLabel);
Plot(H1, "R1",colorDarkGreen,styleLine+styleNoLabel);

Plot(L4, "S4",colorRed,styleLine+styleNoLabel);
Plot(L3, "S3",colorRed,styleLine+styleNoLabel+styleThick);
Plot(L2, "S2",colorRed,styleLine+styleNoLabel);
Plot(L1, "S1",colorRed,styleLine+styleNoLabel);
PlotOHLC(H1,H1,H2,H2,"",colorYellow,styleCloud);
PlotOHLC(H2,H2,H3,H3,"",colorAqua,styleCloud);
PlotOHLC(H3,H3,H4,H4,"",colorPink,styleCloud);
PlotOHLC(H1,H1,L1,L1,"",colorWhite,styleCloud);
PlotOHLC(L1,L1,L2,L2,"",colorYellow,styleCloud);
PlotOHLC(L2,L2,L3,L3,"",colorAqua,styleCloud);
PlotOHLC(L3,L3,L4,L4,"",colorPink,styleCloud);
 
Reposting - Need a code snippet for plotting the value of stochastics as the second line on a basic price chart just like in a basic price chart, the values of OHLC are written on the chart as the first line.Thanks
 

Blackhole

Well-Known Member
hi everyone!


this is an excellent thread! simply loved it.


I need some some in afl, hope programmers can help.


like i want to start trade nifty with 200 unit (8 lots) and start booking profit after

25 point book 50 %
25point book 25%
25 point book 25%

if in any case prf booking missed selll or cover entire position in reverse trend or move sl in afl

if incurred loss increase by 2 lot in our case 250 : 10 lots, if again loss increase by 2 lots.........


only intraday....ie 4 loss in same day 4 times lot is increased, if entire day is in loss...next day trading with same lot size....\\\\



i searched on net and download some codes with scale in and outbut got errors and its not working.

....same code with pyramiding....ie instead of booking profit it should add at regular internals and then sell off.....


want to add 2 lots when nifty moves 35 points or fifity points in our favour and exit all @eod only keep 1 lot in trade in favour

thanks
reposting please help with this. thanks


how can improve payoff ratio or profit ratio of the system, i tried different time frame filters but it goes below 1 or above 1.3 not above 2 or 3....how to trade such system?
 
Last edited:
Hi Seniors,

Happy to share with the code ..got breakthrough after trail and error...its my duty to share with you has you guys are really helpful to new comers .

got success for regular classic pivots..for another variation like camarilla /woodie/fibo...if you guys can do it then share it and oblige.


Regards,
Kedarnath

GraphXSpace = 5 ;
SetChartOptions(0,chartShowArrows|chartShowDates);

// custom function definition
function ShowLastDay( array )
{
dn = DateNum();
lastDay = dn == LastValue( dn );

return IIf( lastDay, array, Null );
}

Plot(C,"Close",colorBlack, styleCandle);
ppl = ParamToggle("Plot Pivot Levels","Off|On",1);

numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = -33.5;

/* This code calculates the previous days high, low and close */
Hi1 = IIf(Day()!=Ref(Day(),-1),Ref(HighestSince(Day()!=Ref(Day(),-1),H,1),-1),0);
Hi = ValueWhen(Day()!=Ref(Day(),-1),Hi1,1);
Lo1 = IIf(Day()!=Ref(Day(),-1),Ref(LowestSince(Day()!=Ref(Day(),-1),L,1),-1),0);
Lo = ValueWhen(Day()!=Ref(Day(),-1),Lo1,1);
Cl1 = IIf(Day()!=Ref(Day(),-1),Ref(C,-1),0);
C1 = ValueWhen(Day()!=Ref(Day(),-1),Cl1,1);

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

/* This code calculates Daily Piovts */

rg = (Hi - Lo);
bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1);
r1 = (bp*2)-Lo; r1I = LastValue (r1,1);
s1 = (bp*2)-Hi; s1I = LastValue (s1,1);
r2 = bp + r1 - s1; r2I = LastValue (r2,1);
s2 = bp - r1 + s1; s2I = LastValue (s2,1);
r3 = bp + r2 - s1; r3I = LastValue (r3,1);
s3 = bp - r2 + s1; s3I = LastValue (s3,1);
r4 = bp + r2 - s2; r4I = LastValue (r4,1);
s4 = bp - r2 + s2; s4I = LastValue (s4,1);

if(ppl==1) {
Plot( ShowLastDay( bp ),"",colorBlue,styleLine|styleDots|styleNoRescale);
Plot( ShowLastDay( s1 ),"",colorRed,styleLine|styleNoRescale);
Plot( ShowLastDay( s2 ),"",colorRed,styleLine|styleNoRescale);
Plot( ShowLastDay( s3 ),"",colorRed,styleLine|styleNoRescale);
Plot( ShowLastDay( s4 ),"",colorRed,styleLine|styleNoRescale);
Plot( ShowLastDay( r1 ),"",colorGreen,styleLine|styleNoRescale);
Plot( ShowLastDay( r2 ),"",colorGreen,styleLine|styleNoRescale);
Plot( ShowLastDay( r3 ),"",colorGreen,styleLine|styleNoRescale);
Plot( ShowLastDay( r4 ),"",colorGreen,styleLine|styleNoRescale);
PlotText(" Pivot = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts), bpI +0.05, colorBlue);
PlotText(" r1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorGreen);
PlotText(" s1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorRed);
PlotText(" r2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numbars/Hts), r2I +0.05, colorGreen);
PlotText(" s2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars/Hts), s2I +0.05, colorRed);
PlotText(" r3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numbars/Hts), r3I +0.05, colorGreen);
PlotText(" s3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars/Hts), s3I +0.05, colorRed);
PlotText(" r4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numbars/Hts), r4I +0.05, colorGreen);
PlotText(" s4 = " + WriteVal(s4,fraction), LastValue(BarIndex())-(numbars/Hts), s4I +0.05, colorRed);
}









To Lvgandhi,

Hi,

From below pivot points...i want to plot levels lines for the current day only...


prv.day line makes it difficult to read the chart as scale changes...


Pivot point code :

_SECTION_BEGIN("Pivot Points");

//---------------------------------------------------------------------------
// This section gets whether they want pivot level for intraday or thier eod
//---------------------------------------------------------------------------

_N(ioreod =ParamList("Pivot Levels for ", "EOD|Intraday"));

if (ioreod=="Intraday")
{
yh = TimeFrameGetPrice( "H", inDaily, -1 );
yl = TimeFrameGetPrice( "L", inDaily, -1 );
yc = TimeFrameGetPrice( "C", inDaily, -1 );
}
else
{
yh = TimeFrameGetPrice( "H", inDaily, 0 );
yl = TimeFrameGetPrice( "L", inDaily, 0 );
yc = TimeFrameGetPrice( "C", inDaily, 0 );
}

//---------------------------------------------------------------------------
// To calculate the Pivot Levels
//---------------------------------------------------------------------------

to = TimeFrameGetPrice( "O", inDaily, 0 );
pivot = (yh + yl + yc) / 3;
range = yh - yl;
_N(pist =ParamList("Select Pivot Type ", "Classical Pivot|Woodie Pivot|Caramilla Pivot|Fibonacci Pivot"));

if (pist =="Classical Pivot" )
{
r1 = (2 * pivot) - yl ;
s1 = (2 * pivot) - yh ;
r2 = pivot - s1 + r1;
s2 = pivot - (r1 - s1) ;
r3 = 2 * (pivot - yl) + yh ;
s3 = yl - (2 * (yh - pivot));
}

else if(pist =="Woodie Pivot" )
{
pivot = (yh + yl + yc + to) / 4;
r1 = (2 * pivot) - yl;
r2 = pivot + range;
r3 = yh + 2 * (pivot - yl);
r4 = r3 + range;
s1 = (2 * pivot) - yh;
s2 = pivot - range;
s3 = yl - 2 * (yh - pivot);
s4 = S3 - range;
}

else if(pist =="Caramilla Pivot" )
{
r4 = yc + range * 1.1/2;
r3 = yc + range * 1.1/4;
r2 = yc + range * 1.1/6;
r1 = yc + range * 1.1/12;
s1 = yc - range * 1.1/12;
s2 = yc - range * 1.1/6;
s3 = yc - range * 1.1/4;
s4 = yc - range * 1.1/2;
}

else
{
r3 = pivot + 1.000 * (yh - yl);
r2 = pivot + 0.618 * (yh - yl);
r1 = pivot + 0.382 * (yh - yl);
s1 = pivot - 0.382 * (yh - yl);
s2 = pivot - 0.618 * (yh - yl);
s3 = pivot - 1.000 * (yh - yl);
}

//---------------------------------------------------------------------------
// To Plot Pivot Levels in the screen
//---------------------------------------------------------------------------

_N(dsr =ParamList("Draw Intraday Pivot Levels ", "None|Both|Support|Resistance"));

if (dsr =="Support" OR dsr == "Both")
{
Plot(pivot, "\n Pivot - ",colorGreen,1);
Plot(r1, "Resistance 1 - ",colorDarkRed,1);
Plot(r2, "Resistance 2 - ",colorDarkRed,1);
Plot(r3, "Resistance 3 - ",colorDarkRed,1);
Plot((pivot+r1)/2, "Mid Value of R1 & Pivot ",colorLightBlue,1);
Plot((r3+r2)/2, "Mid Value of R2 & R3 - ",colorLightBlue,1);
Plot((r1+r2)/2, "Mid Value of R1 & R2 - ",colorLightBlue,1);
}

if( dsr == "Resistance" OR dsr == "Both")
{
Plot(pivot, "\n Pivot - ",colorGreen,1);
Plot(s3, "Support 2 - ",colorDarkGreen,1);
Plot(s2, "Support 2 - ",colorDarkGreen,1);
Plot(s1, "Support 1 - ",colorDarkGreen,1);
Plot((s3+s2)/2, "Mid Value of S2 & S3 ",colorWhite,1);
Plot((s1+s2)/2, "Mid Value of S1 & S2 - ",colorWhite,1);
Plot((pivot+s1)/2, "Mid Value of S1 & Pivot ",colorWhite,1);
}

//---------------------------------------------------------------------------
// Printing the pivot level in interpretation window
//---------------------------------------------------------------------------


printf(Name()+ "\n\nResistance - 3 | %g\nResistance - 2 | %g\nResistance - 1 | %g\n" +
"Pivot | %g\nSupport - 1 | %g\nSupport - 2 | %g\nSupport - 3 | %g",
r3,r2,r1,pivot,s1,s2,s3);


//---------------------------------------------------------------------------
// This section is for Exploration
//---------------------------------------------------------------------------

Filter = 1;
AddColumn(r3,"Resistance 3");
AddColumn(r2,"Resistance 2");
AddColumn(r1,"Resistance 1");
AddColumn(Pivot,"Pivot");
AddColumn(s1,"Support 1");
AddColumn(s2,"Support 2");
AddColumn(s3,"Support 3");

//---------------------------------------------------------------------------
// Add Pivot levels along with the title
//---------------------------------------------------------------------------

_N(Title = EncodeColor(colorBrown)+ StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g(%.1f%%)\n"+
EncodeColor(4)+"Resistance 3 -=- %g ::::: Resistance 2 -=- %g ::::: Resistance 1 -=- %g :::::"+
EncodeColor(colorGreen)+" Pivot -=- %g"+
EncodeColor(29)+"\nSupport 1 -=- %g ::::: Support 2 -=- %g ::::: Support 3 -=- %g\n ",
O, H, L, C,SelectedValue( ROC( C, 1 ) ),r3,r2,r1,pivot,s1,s2,s3));

//---------------------------------------------------------------------------
// End of Pivot Point
//---------------------------------------------------------------------------



Regards,
Kedarnath
 

Similar threads