Simple Coding Help - No Promise.

ocil

Well-Known Member
Dear Romeo i am using below code for trading. if yesterday high-low brk i will buy or sell. i want to add when nifty in - I will sell and + I will buy. How to add nifty trend in below code for trading. thanks for your help.

//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low

//PLOTS
Plot( cdl( H1 ), "PRE_HIGH", colorDarkRed, styleLine + styleDashed + styleNoRescale);
Plot( cdl( L1 ), "PRE_LOW", colorDarkGreen, styleLine + styleDashed + styleNoRescale);
_SECTION_END();

//BUY-SELL
Buy= COVER=C>H1;
Short =SELL=C<L1;
 

Romeo1998

Well-Known Member
Dear friend ocil,
use this code :happy:
Code:
// We can check whether price is in + or - by comparing current price with yesterday's close

//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low
C1 = TimeFrameGetPrice( "C", inDaily, -1 ); // yesterday's close

//PLOTS
Plot( cdl( H1 ), "PRE_HIGH", colorDarkRed, styleLine + styleDashed + styleNoRescale);
Plot( cdl( L1 ), "PRE_LOW", colorDarkGreen, styleLine + styleDashed + styleNoRescale);
Plot( C1, "PRE_CLOSE", colorYellow, styleLine + styleDashed + styleNoRescale );

// BUY-SELL :)
Buy = COVER = C > H1 AND C > C1;
Short = Sell = C < L1 AND C < C1;
:happy:
 
Last edited:

ocil

Well-Known Member
Sorry, Romeo, I need to check the nifty current price to buy or sell stocks. When the nifty current price is + compare to yesterday closed and stock brk high buy signal and sell vice versa. Thanks again for your help.

Dear friend ocil,
use this code :happy:
Code:
// We can check whether price is in + or - by comparing current price with yesterday's close

//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low
C1 = TimeFrameGetPrice( "C", inDaily, -1 ); // yesterday's close

//PLOTS
Plot( cdl( H1 ), "PRE_HIGH", colorDarkRed, styleLine + styleDashed + styleNoRescale);
Plot( cdl( L1 ), "PRE_LOW", colorDarkGreen, styleLine + styleDashed + styleNoRescale);
Plot( C1, "PRE_CLOSE", colorYellow, styleLine + styleDashed + styleNoRescale );

// BUY-SELL :)
Buy = COVER = C > H1 AND C > C1;
Short = Sell = C < L1 AND C < C1;
:happy:
 

Romeo1998

Well-Known Member
Dear friend ocil,
use this code :happy:
u can change the symbol name from parameters ( i have used NIFTY ) :happy:
let me know if everything is working as it should :D as i make many mistakes too :D
Code:
// code to get Nifty's closing price of yesterday :)
fs=ParamStr("Symbol","NIFTY");
SetForeign(fs);
Y1 = TimeFrameGetPrice( "C", inDaily, -1 );
symbolplus = C>Y1; // check whether nifty is in plus
symbolminus = C<Y1; // check whether nifty is in minus
RestorePriceArrays();

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

//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low

//PLOTS
Plot( cdl( H1 ), "PRE_HIGH", colorDarkRed, styleLine + styleDashed + styleNoRescale);
Plot( cdl( L1 ), "PRE_LOW", colorDarkGreen, styleLine + styleDashed + styleNoRescale);


// BUY-SELL :)
Buy = COVER = C > H1 AND symbolplus;
Short = Sell = C < L1 AND symbolminus;
:happy:
 
Last edited:
Hi dear romeo. have you any predict divergence afl according tomorrow low and high???
is it possible to specify which divergent occur.i mean if we have RSI divergent have text(( rsi divergent)) or different color of star for exaple red and green star for RSI and blue and yellow star for MFI and...FOR STOCHASTIC. and text ((hidden)) for hiden divergentce ?
Code:
_SECTION_BEGIN("Divergence Detector for ");
SetChartOptions(3,chartGridMiddle);
SetChartOptions(0,chartShowArrows|chartShowDates);
EnableTextOutput(False);
mfyperiod=Param("MFI period",14,5,100);
rsyperiod=Param("RSI period",14,5,100);

procedure CalDivergence()
{
global stchbulld;
global stchbeard;
global rsybulld;
global rsybeard;
global mfybulld;
global mfybeard;
global ispeak;
global istrough;

zzg=Zig(C,5);
// find the Peaks and trough of Close
ispeak=zzg>Max(Ref(zzg,-1),Ref(zzg,1));
istrough=zzg<Min(Ref(zzg,-1),Ref(zzg,1));


// Get the value of Price At Peaks
yp2=LastValue(ValueWhen(ispeak,C,2));
yp1=LastValue(ValueWhen(ispeak,C,1));

//yp2=(ValueWhen(ispeak,C,2));
//yp1=(ValueWhen(ispeak,C,1));

// Get the value of Price At Troughs
yb2=LastValue(ValueWhen(istrough,C,2));
yb1=LastValue(ValueWhen(istrough,C,1));

//yb2=(ValueWhen(istrough,C,2));
//yb1=(ValueWhen(istrough,C,1));

stchbulld=(yb1<yb2)*(LastValue(ValueWhen(istrough,StochK(15,3),1))>LastValue(ValueWhen(istrough,StochK(15,3),2)));
stchbeard=(yp1>yp2)*(LastValue(ValueWhen(ispeak,StochK(15,3),1))<LastValue(ValueWhen(ispeak,StochK(15,3),2)));

rsybulld=(yb1<yb2)*(LastValue(ValueWhen(istrough,RSI(rsyperiod),1))>LastValue(ValueWhen(istrough,RSI(rsyperiod),2)));
rsybeard=(yp1>yp2)*(LastValue(ValueWhen(ispeak,RSI(rsyperiod),1))<LastValue(ValueWhen(ispeak,RSI(rsyperiod),2)));

mfybulld=(yb1<yb2)*(LastValue(ValueWhen(istrough,MFI(mfyperiod),1))>LastValue(ValueWhen(istrough,MFI(mfyperiod),2)));
mfybeard=(yp1>yp2)*(LastValue(ValueWhen(ispeak,MFI(mfyperiod),1))<LastValue(ValueWhen(ispeak,MFI(mfyperiod),2)));

}
procedure DrawPrice()
{
_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 )) ));
Plot( C, "Close", colorBlack, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
x=Cum(1);
// Get the x-ordinate of Close at Peaks
xp1=LastValue(ValueWhen(ispeak,x,1))-1;
xp2=LastValue(ValueWhen(ispeak,x,2))-1;
//Get the x-ordinate of Close at Troughs
xb1=LastValue(ValueWhen(istrough,x,1))-1;
xb2=LastValue(ValueWhen(istrough,x,2))-1;

// Get the value of Price At Peaks
yp2=LastValue(ValueWhen(ispeak,C,2));
yp1=LastValue(ValueWhen(ispeak,C,1));
// Get the value of Price At Troughs
yb2=LastValue(ValueWhen(istrough,C,2));
yb1=LastValue(ValueWhen(istrough,C,1));


PlotShapes(IIf(x==xb1+1,shapeStar,shapeNone),colorDarkGreen,0,L,-8);
//PlotShapes(IIf(istrough,shapeStar,shapeNone),colorDarkGreen,0,L,-8);
PlotShapes(IIf(x==xb2+1,shapeStar,shapeNone),colorDarkGreen,0,L,-8);
PlotShapes(IIf(x==xp1+1,shapeStar+shapePositionAbove,shapeNone),colorRed,0,H,-8);
PlotShapes(IIf(x==xp2+1,shapeStar+shapePositionAbove,shapeNone),colorRed,0,H,-8);

}


CalDivergence();
DrawPrice();

Filter=mfybulld+mfybeard+rsybulld+rsybeard+stchbulld+stchbeard;
AddColumn(mfybulld,"MFI Bull.D");
AddColumn(mfybeard,"MFI Bearish");

AddColumn(rsybulld,"RSI Bull.D");
AddColumn(rsybeard,"RSI Bearish");

AddColumn(stchbulld,"Stoch Bull.D");
AddColumn(stchbeard,"Stoch Bearish");
_SECTION_END();
 

ocil

Well-Known Member
Dear Romeo,
I want to add one more condition. That first candle must close green above pivot to buy.
and for sell first candle must close red below the pivot. Pls check below code and fix if wrong code.
Thanks for your help.

PV=(h1+L1+C1)/3;

Buy = COVER = C > H1 AND symbolplus AND C=(C>pv);
Short = Sell = C < L1 AND symbolminus AND C=(C<pv);


Dear friend ocil,
use this code :happy:
u can change the symbol name from parameters ( i have used NIFTY ) :happy:
let me know if everything is working as it should :D as i make many mistakes too :D
Code:
// code to get Nifty's closing price of yesterday :)
fs=ParamStr("Symbol","NIFTY");
SetForeign(fs);
Y1 = TimeFrameGetPrice( "C", inDaily, -1 );
symbolplus = C>Y1; // check whether nifty is in plus
symbolminus = C<Y1; // check whether nifty is in minus
RestorePriceArrays();

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

//TIME FRAME CALCULATION
H1 = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
L1 = TimeFrameGetPrice( "L", inDaily, -1 ); // low

//PLOTS
Plot( cdl( H1 ), "PRE_HIGH", colorDarkRed, styleLine + styleDashed + styleNoRescale);
Plot( cdl( L1 ), "PRE_LOW", colorDarkGreen, styleLine + styleDashed + styleNoRescale);


// BUY-SELL :)
Buy = COVER = C > H1 AND symbolplus;
Short = Sell = C < L1 AND symbolminus;
:happy:
 

Similar threads