help me please

#1
mere paas ek system hai jisme current profit loss 1 box me dekhta hai. mujhe aisa chaiye ki wo current p/l sirf current day ke liye he dikhe. matlab agar koi siganl next day ke liye continue ho raha hai phir bhi at 3.30 ke close price ke sath hi p/l dekhna chaiye. aur wahi continue hona chaiye jab tak dusare signal nahi aata. maine codeme change kiya hai

ye actually code hai

GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 170, y-21);;

maine ye change kiye hai.
GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(IIf(TimeNum() < 153000, 0, (C-entry))),IIf(TimeNum() < 153000, 0, (entry-C))),2.2)), 170, y-21);;

abhi system me p/l khali 3.30 ko hi dekhta hai. baki time nahi dekhta hai. mujhe aisa chaiye ki p/l sirf 3.30 tak hi dekhe agle din nahi dekhe jab tak signal change nahi hota. please help.
 
#2
mere paas ek system hai jisme current profit loss 1 box me dekhta hai. mujhe aisa chaiye ki wo current p/l sirf current day ke liye he dikhe. matlab agar koi siganl next day ke liye continue ho raha hai phir bhi at 3.30 ke close price ke sath hi p/l dekhna chaiye. aur wahi continue hona chaiye jab tak dusare signal nahi aata. maine codeme change kiya hai

ye actually code hai

GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 170, y-21);;

maine ye change kiye hai.
GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(IIf(TimeNum() < 153000, 0, (C-entry))),IIf(TimeNum() < 153000, 0, (entry-C))),2.2)), 170, y-21);;

abhi system me p/l khali 3.30 ko hi dekhta hai. baki time nahi dekhta hai. mujhe aisa chaiye ki p/l sirf 3.30 tak hi dekhe agle din nahi dekhe jab tak signal change nahi hota. please help.
can u send Post ya Send Full AFl so Can Check Celarly
 
#3
can u send Post ya Send Full AFl so Can Check Celarly
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - O %g, H %g, L %g, C %g {{DATE}} {{VALUES}} {{INTERVAL}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("Volume Price Analysis - V.1.2");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartOptions(2, chartWrapTitle );
//=======================================================================================
DTL=Param("Linear regression period",60,10,100,10);
wbf=Param("WRB factor",1.5,1.3,2.5,.1);
nbf=Param("NRB factor",0.7,0.3,0.9,0.1);
TL=LinRegSlope(MA(C, DTL),2);
Vlp=Param("Volume lookback period",30,20,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(wbf*arg);
nrb=rg<(nbf*arg);
Vl=V<Ref(V,-1) AND V<Ref(V,-2);
upbar=C>Ref(C,-1);
dnbar=C<Ref(C,-1);
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc==0,arg,x);
Vb=V>Vrg OR V>Ref(V,-1);
ucls=x1<2;
dcls=x1>2;
mcls=x1<2.2 AND x1>1.8 ;
Vlcls=x1>4;
Vhcls=x1<1.35;
j=MA(C,5);
TLL=LinRegSlope(j,40) ;
Tlm=LinRegSlope(j,15) ;
tls=LinRegSlope(j,5);
mp=(H+L)/2;
_SECTION_END();
//==========================================================================================
_SECTION_BEGIN("VSA");
utbar=wrb AND dcls AND tls>0 ;
utcond1=Ref(utbar,-1) AND dnbar ;
utcond2=Ref(utbar,-1) AND dnbar AND V>Ref(V,-1);
utcond3=utbar AND V> 2*Vrg;
trbar=Ref(V,-1)>Vrg AND Ref(upbar,-1) AND Ref(wrb,-1) AND dnbar AND dcls AND wrb AND tll>0 AND H==HHV(H,10);
Hutbar=Ref(upbar,-1) AND Ref(V,-1)>1.5*Vrg AND dnbar AND dcls AND NOT wrb AND NOT utbar;
Hutcond=Ref(Hutbar,-1) AND dnbar AND dcls AND NOT utbar;
tcbar=Ref(upbar,-1) AND H==HHV(H,5)AND dnbar AND (dcls OR mcls) AND V>vrg AND NOT wrb AND NOT Hutbar ;
Scond1=(utcond1 OR utcond2 OR utcond3) ;
Scond2=Ref(scond1,-1)==0;
scond=scond1 AND scond2;
stdn0= tll<0 AND V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0;
stdn= V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0;
stdn1= tll<0 AND V>(vrg*1.5) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls)AND tls<0 AND tlm<0;
stdn2=tls<0 AND Ref(V,-1)<Vrg AND upbar AND vhcls AND V>Vrg;
bycond1= stdn OR stdn1;
bycond= upbar AND Ref(bycond1,-1);
stvol= L==LLV(L,5) AND (ucls OR mcls) AND V>1.5*Vrg AND tll<0;
ndbar=upbar AND nrb AND Vl AND dcls ;
nsbar=dnbar AND nrb AND Vl AND dcls ;
nbbar= C>Ref(C,-1) AND Vl AND nrb AND x1<2;
nbbar= IIf(C>Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2) AND x1<1.1,1,0);
lvtbar= vl AND L<Ref(L,-1) AND ucls;
lvtbar1= V<Vrg AND L<Ref(L,-1) AND ucls AND tll>0 AND tlm>0 AND wrb;
lvtbar2= Ref(Lvtbar,-1) AND upbar AND ucls;
dbar= V>2*Vrg AND dcls AND upbar AND tls>0 AND tlm>0 AND NOT Scond1 AND NOT utbar;
eftup=H>Ref(H,-1) AND L>Ref(L,-1) AND C>Ref(C,-1) AND C>=((H-L)*0.7+L) AND rg>arg AND V>Ref(V,-1);
eftupfl=Ref(eftup,-1) AND (utbar OR utcond1 OR utcond2 OR utcond3);
eftdn=H<Ref(H,-1) AND L<Ref(L,-1) AND C<Ref(C,-1) AND C<=((H-L)*0.25+L) AND rg>arg AND V>Ref(V,-1);
_SECTION_END();
//=======================================================================================================================

//============================================================================================================================
// commentary

_SECTION_BEGIN( "KBrain" );
//========================Initiation================ ========
bts = ParamToggle( "BrainTrend1 signal", "No|Yes" , 1 );
btst = ParamToggle( "BrainTrend1 stop", "No|Yes" , 1 );
btsl = ParamToggle( "BrainTrend1 stop line", "No|Yes" , 1 );
period = Param( "Period", 14, 6, 20, 1 );
x1 = 53;
x2 = 47;
d = 2.3;
f = 7;
s = 1.5;
range = ATR( f );
Range1 = ATR( f ) / d;
Range2 = ( ATR( f ) * s ) / 4;
range3 = ATR( 10 );
R = ( ( HHV( H, period ) - C ) / ( HHV ( H, period ) - LLV ( L, period ) ) ) * -100;
EMA1 = EMA( R, Period );
EMA2 = EMA( EMA1, 5 );
Difference = EMA1 - EMA2;
ZeroLagEMA = EMA1 + Difference;
value2 = abs( ZeroLagEMA );


function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C ) / ( HHV( H, periods ) - LLV( L, periods ) );
}


for ( i = 1; i < Period - 1; i++ )
{


tm = 1;
bstop = 1;
sstop = 1;
p = 1;
}

for ( i = period + 10; i < BarCount; i++ )
{
C[0] = 0;
Value2[0] = 0;
p[0] = 0;
Plot1[0] = 0;
Plot2[0] = 0;
Val1 = 0;
Val2 = 0;
temp[0] = 0;
Value3[0] = 0;
tm[0] = 0;
p1 = 0;
bt1[0] = 0;
bt2[0] = 0;
r[0] = 0;
bt1a[0] = 0;
bt2a[0] = 0;
istop[0] = Val1[0];
stop = Val1[0];
bstop[0] = 0;
sstop = 0;
//==================================Indicators====== ======================
{
if ( value2 < x2 AND abs( Close - Close[i-2] ) > range1 )
p = 1 ;
else
{
if ( value2 > x1 AND abs( Close - Close[i-2] ) > Range1 )
p = 2 ;

else

p = 0;
}
}

if ( ( value2 < x2 AND p == 1 ) OR ( value2 < x2 AND p == 0 ) )

{
if ( abs( Close - Close[i-2] ) > Range1 )
{
Plot1 = H;
Plot2 = L;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}
else
{
if ( ( value2 > x1 AND p == 2 ) OR ( value2 > x1 AND p == 0 ) )

{
Plot1 = L;
Plot2 = H;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}

//==================KBrain Signal ====================================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 1 OR p == 0 )
Value3 = L - range3;

val1 = Value3;

p = 1;

temp = 1;
}
else
{
temp = temp[i-1];
}

{
if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 2 OR p == 0 )
Value3 = H + range3;

val2 = Value3;

p = 2;

temp = 2;;
}

}
}

{

if ( temp == 1 AND Plot1 > 0 AND tm != 1 )
tm = 1;

if ( temp == 2 AND Plot2 > 0 AND tm != 2 )
tm = 2;

}

//===============================stop=============== =========================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 2 )

{
value3 = L - range3;
va1 = Value3;
p1 = 2;
r = Va1;
bstop = Va1;
bt2 = bt2[i-1];
}

if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 1 )

{
Value3 = H + range3;
va2 = Value3;
p1 = 1;

r = Va2;
sstop = Value3;
bt1 = bt1[i-1];
}

}



if ( val1 == 0 AND val2 == 0 AND p == 0 )
{
bstop = bstop[i-1];
sstop = sstop[i-1];
}


if ( bstop < bstop[i-1] AND tm == 1 AND tm[i-1] == 1 )
bstop = bstop[i-1];

if ( sstop > sstop[i-1] AND tm == 2 AND tm[i-1] == 2 )
sstop = sstop[i-1];

}

//=============================SYSTEM=============== =======================
Mycolor = IIf( p == 1, colorLime, IIf( p == 2, colorRed, colorBlue ) );

PlotShapes( IIf( btst AND p == 1, shapeSmallCircle, Null ), colorWhite, 0, bstop, 0 );

Plot( IIf( btsl AND tm == 1, bstop, Null ), "", colorWhite, 1 );

PlotShapes( IIf( btst AND p == 2, shapeSmallCircle, Null ), colorWhite, 0, sstop, 0 );

Plot( IIf( btsl AND tm == 2, sstop, Null ), "", colorWhite, 1 );

PlotShapes( shapeUpArrow* ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 ), colorGreen, 0, bstop, 0 );

PlotShapes( shapeDownArrow* ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 ), colorRed, 0, sstop, 0 );


Buy = Cover = ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 );

Sell = Short = ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 );

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

_SECTION_END();

//=================TITLE============================ ================================================== ==================
/*_SECTION_BEGIN( "Title" );

if ( Status( "action" ) == actionIndicator )
(
Title = EncodeColor( colorWhite ) + "KBrain V 1.1. " + " - " + Name() + " - " + EncodeColor( colorRed ) + Interval( 2 ) + EncodeColor( colorWhite ) +
" - " + Date() + " - " + EncodeColor( colorYellow ) + "Op-" + O + " " + "Hi-" + H + " " + "Lo-" + L + " " +
"Cl-" + C + " " + "Vol= " + WriteVal( V ) + "\n" +
EncodeColor( colorLime ) +
WriteIf ( Buy , "\n"+"GO LONG / Reverse Signal at " + StrFormat("%.2f%", C) + " ", "" ) +
WriteIf ( Sell , "\n"+"EXIT LONG / Reverse Signal at " + StrFormat("%.2f%", C) + " ", "" ) + "\n" +
EncodeColor( colorWhite ) +
WriteIf( Sell , "Total Profit/Loss for the Last Trade Tk." + StrFormat("%.2f%", ( C - BuyPrice )) + "", "" ) +
WriteIf( Buy , "Total Profit/Loss for the Last trade Tk." + StrFormat("%.2f%", ( SellPrice - C )) + "", "" ) +
WriteIf( Long AND NOT Buy, "Trade : Long - Entry price Tk." + StrFormat("%.2f%", ( BuyPrice )), "" ) +
WriteIf( shrt AND NOT Sell, "Trade : Short - Entry price Tk." + StrFormat("%.2f%", ( SellPrice )), "" ) + "\n" +
WriteIf( Long AND NOT Buy, "Current Profit/Loss Tk." + StrFormat("%.2f%", ( C - BuyPrice )) + "", "" ) +
WriteIf( shrt AND NOT Sell, "Current Profit/Loss Tk." + StrFormat("%.2f%", ( SellPrice - C )) + "", "" ) );

_SECTION_END();
*/


//Explore Analysis
BuyPrice = ValueWhen( Buy, C );
SellPrice = ValueWhen( Sell, C );
Filter = ( Buy OR Sell );;
AddColumn( IIf( Buy, BuyPrice, Null ), "Buy ", 6.2, 1, colorGreen );
AddColumn( IIf( Sell, SellPrice, Null ), "Sell ", 6.2, 1, colorRed );

//Alerts
AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1);
AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short", 1);

////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////

// The current bar should be more than previous bar value + 5 points for buy in uptrend
BuyV = Buy;
// the current bar should be less than previous bar value - 5 points for sell in downtrend
SellV = Sell ;

// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1));
SellSB= BarsSince(Ref(SellV,-1));

// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,1);
//Datefine = 1;


// Check if it is time to close the postions.
EOD = IIf(TimeNum() < 153000, 0, 1);
noEOD = IIf(TimeNum() < 153000, 1, 0);

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
// We can signal sell only if previous signal was a buy.
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
Sell = EOD AND BuySB < SellSB;



messageboard = ParamToggle("Message Board","Show|Hide",0);


Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
Sell = EOD AND BuySB < SellSB;
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";

tar1 = entry + (entry * .0089);
tar2 = entry + (entry * .0178);
tar3 = entry + (entry * .0216);

bars = i;
i = 0;
}
if(Short == 1)
{
sig = "SELL";
entry = C;

tar1 = entry - (entry * .0099);
tar2 = entry - (entry * .0175);
tar3 = entry - (entry * .0216);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);

Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);


}


printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 70, x2, y , 7, 7 ) ;
GfxTextOut( ( " NK intraday "),88,y-71);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-46) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-21);
GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 170, y-21);;

}
 
#4
ye actually code hai

GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 170, y-21);;

maine ye change kiye hai.
GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(IIf(TimeNum() < 153000, 0, (C-entry))),IIf(TimeNum() < 153000, 0, (entry-C))),2.2)), 170, y-21);;

abhi system me p/l khali 3.30 ko hi dekhta hai. baki time nahi dekhta hai. mujhe aisa chaiye ki p/l sirf 3.30 tak hi dekhe agle din nahi dekhe jab tak signal change nahi hota. please help.

mujhe aisa chaiye ki wo current p/l sirf current day ke liye he dikhe. matlab agar koi siganl next day ke liye continue ho raha hai phir bhi at 3.30 ke close price ke sath hi p/l dekhna chaiye. aur wahi continue hona chaiye jab tak dusare signal nahi aata. check 3.30 candle of below afl.




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


_SECTION_BEGIN("Volume Price Analysis - V.1.2");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartOptions(2, chartWrapTitle );
//=======================================================================================
DTL=Param("Linear regression period",60,10,100,10);
wbf=Param("WRB factor",1.5,1.3,2.5,.1);
nbf=Param("NRB factor",0.7,0.3,0.9,0.1);
TL=LinRegSlope(MA(C, DTL),2);
Vlp=Param("Volume lookback period",30,20,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(wbf*arg);
nrb=rg<(nbf*arg);
Vl=V<Ref(V,-1) AND V<Ref(V,-2);
upbar=C>Ref(C,-1);
dnbar=C<Ref(C,-1);
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc==0,arg,x);
Vb=V>Vrg OR V>Ref(V,-1);
ucls=x1<2;
dcls=x1>2;
mcls=x1<2.2 AND x1>1.8 ;
Vlcls=x1>4;
Vhcls=x1<1.35;
j=MA(C,5);
TLL=LinRegSlope(j,40) ;
Tlm=LinRegSlope(j,15) ;
tls=LinRegSlope(j,5);
mp=(H+L)/2;
_SECTION_END();
//==========================================================================================
_SECTION_BEGIN("VSA");
utbar=wrb AND dcls AND tls>0 ;
utcond1=Ref(utbar,-1) AND dnbar ;
utcond2=Ref(utbar,-1) AND dnbar AND V>Ref(V,-1);
utcond3=utbar AND V> 2*Vrg;
trbar=Ref(V,-1)>Vrg AND Ref(upbar,-1) AND Ref(wrb,-1) AND dnbar AND dcls AND wrb AND tll>0 AND H==HHV(H,10);
Hutbar=Ref(upbar,-1) AND Ref(V,-1)>1.5*Vrg AND dnbar AND dcls AND NOT wrb AND NOT utbar;
Hutcond=Ref(Hutbar,-1) AND dnbar AND dcls AND NOT utbar;
tcbar=Ref(upbar,-1) AND H==HHV(H,5)AND dnbar AND (dcls OR mcls) AND V>vrg AND NOT wrb AND NOT Hutbar ;
Scond1=(utcond1 OR utcond2 OR utcond3) ;
Scond2=Ref(scond1,-1)==0;
scond=scond1 AND scond2;
stdn0= tll<0 AND V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0;
stdn= V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0;
stdn1= tll<0 AND V>(vrg*1.5) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls)AND tls<0 AND tlm<0;
stdn2=tls<0 AND Ref(V,-1)<Vrg AND upbar AND vhcls AND V>Vrg;
bycond1= stdn OR stdn1;
bycond= upbar AND Ref(bycond1,-1);
stvol= L==LLV(L,5) AND (ucls OR mcls) AND V>1.5*Vrg AND tll<0;
ndbar=upbar AND nrb AND Vl AND dcls ;
nsbar=dnbar AND nrb AND Vl AND dcls ;
nbbar= C>Ref(C,-1) AND Vl AND nrb AND x1<2;
nbbar= IIf(C>Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2) AND x1<1.1,1,0);
lvtbar= vl AND L<Ref(L,-1) AND ucls;
lvtbar1= V<Vrg AND L<Ref(L,-1) AND ucls AND tll>0 AND tlm>0 AND wrb;
lvtbar2= Ref(Lvtbar,-1) AND upbar AND ucls;
dbar= V>2*Vrg AND dcls AND upbar AND tls>0 AND tlm>0 AND NOT Scond1 AND NOT utbar;
eftup=H>Ref(H,-1) AND L>Ref(L,-1) AND C>Ref(C,-1) AND C>=((H-L)*0.7+L) AND rg>arg AND V>Ref(V,-1);
eftupfl=Ref(eftup,-1) AND (utbar OR utcond1 OR utcond2 OR utcond3);
eftdn=H<Ref(H,-1) AND L<Ref(L,-1) AND C<Ref(C,-1) AND C<=((H-L)*0.25+L) AND rg>arg AND V>Ref(V,-1);
_SECTION_END();
//=======================================================================================================================

//============================================================================================================================
// commentary

_SECTION_BEGIN( "KBrain" );
//========================Initiation================ ========
bts = ParamToggle( "BrainTrend1 signal", "No|Yes" , 1 );
btst = ParamToggle( "BrainTrend1 stop", "No|Yes" , 1 );
btsl = ParamToggle( "BrainTrend1 stop line", "No|Yes" , 1 );
period = Param( "Period", 14, 6, 20, 1 );
x1 = 53;
x2 = 47;
d = 2.3;
f = 7;
s = 1.5;
range = ATR( f );
Range1 = ATR( f ) / d;
Range2 = ( ATR( f ) * s ) / 4;
range3 = ATR( 10 );
R = ( ( HHV( H, period ) - C ) / ( HHV ( H, period ) - LLV ( L, period ) ) ) * -100;
EMA1 = EMA( R, Period );
EMA2 = EMA( EMA1, 5 );
Difference = EMA1 - EMA2;
ZeroLagEMA = EMA1 + Difference;
value2 = abs( ZeroLagEMA );


function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C ) / ( HHV( H, periods ) - LLV( L, periods ) );
}


for ( i = 1; i < Period - 1; i++ )
{


tm = 1;
bstop = 1;
sstop = 1;
p = 1;
}

for ( i = period + 10; i < BarCount; i++ )
{
C[0] = 0;
Value2[0] = 0;
p[0] = 0;
Plot1[0] = 0;
Plot2[0] = 0;
Val1 = 0;
Val2 = 0;
temp[0] = 0;
Value3[0] = 0;
tm[0] = 0;
p1 = 0;
bt1[0] = 0;
bt2[0] = 0;
r[0] = 0;
bt1a[0] = 0;
bt2a[0] = 0;
istop[0] = Val1[0];
stop = Val1[0];
bstop[0] = 0;
sstop = 0;
//==================================Indicators====== ======================
{
if ( value2 < x2 AND abs( Close - Close[i-2] ) > range1 )
p = 1 ;
else
{
if ( value2 > x1 AND abs( Close - Close[i-2] ) > Range1 )
p = 2 ;

else

p = 0;
}
}

if ( ( value2 < x2 AND p == 1 ) OR ( value2 < x2 AND p == 0 ) )

{
if ( abs( Close - Close[i-2] ) > Range1 )
{
Plot1 = H;
Plot2 = L;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}
else
{
if ( ( value2 > x1 AND p == 2 ) OR ( value2 > x1 AND p == 0 ) )

{
Plot1 = L;
Plot2 = H;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}

//==================KBrain Signal ====================================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 1 OR p == 0 )
Value3 = L - range3;

val1 = Value3;

p = 1;

temp = 1;
}
else
{
temp = temp[i-1];
}

{
if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 2 OR p == 0 )
Value3 = H + range3;

val2 = Value3;

p = 2;

temp = 2;;
}

}
}

{

if ( temp == 1 AND Plot1 > 0 AND tm != 1 )
tm = 1;

if ( temp == 2 AND Plot2 > 0 AND tm != 2 )
tm = 2;

}

//===============================stop=============== =========================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 2 )

{
value3 = L - range3;
va1 = Value3;
p1 = 2;
r = Va1;
bstop = Va1;
bt2 = bt2[i-1];
}

if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 1 )

{
Value3 = H + range3;
va2 = Value3;
p1 = 1;

r = Va2;
sstop = Value3;
bt1 = bt1[i-1];
}

}



if ( val1 == 0 AND val2 == 0 AND p == 0 )
{
bstop = bstop[i-1];
sstop = sstop[i-1];
}


if ( bstop < bstop[i-1] AND tm == 1 AND tm[i-1] == 1 )
bstop = bstop[i-1];

if ( sstop > sstop[i-1] AND tm == 2 AND tm[i-1] == 2 )
sstop = sstop[i-1];

}

//=============================SYSTEM=============== =======================
Mycolor = IIf( p == 1, colorLime, IIf( p == 2, colorRed, colorBlue ) );

PlotShapes( IIf( btst AND p == 1, shapeSmallCircle, Null ), colorWhite, 0, bstop, 0 );

Plot( IIf( btsl AND tm == 1, bstop, Null ), "", colorWhite, 1 );

PlotShapes( IIf( btst AND p == 2, shapeSmallCircle, Null ), colorWhite, 0, sstop, 0 );

Plot( IIf( btsl AND tm == 2, sstop, Null ), "", colorWhite, 1 );

PlotShapes( shapeUpArrow* ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 ), colorGreen, 0, bstop, 0 );

PlotShapes( shapeDownArrow* ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 ), colorRed, 0, sstop, 0 );


Buy = Cover = ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 );

Sell = Short = ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 );

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

_SECTION_END();

//=================TITLE============================ ================================================== ==================
/*_SECTION_BEGIN( "Title" );

if ( Status( "action" ) == actionIndicator )
(
Title = EncodeColor( colorWhite ) + "KBrain V 1.1. " + " - " + Name() + " - " + EncodeColor( colorRed ) + Interval( 2 ) + EncodeColor( colorWhite ) +
" - " + Date() + " - " + EncodeColor( colorYellow ) + "Op-" + O + " " + "Hi-" + H + " " + "Lo-" + L + " " +
"Cl-" + C + " " + "Vol= " + WriteVal( V ) + "\n" +
EncodeColor( colorLime ) +
WriteIf ( Buy , "\n"+"GO LONG / Reverse Signal at " + StrFormat("%.2f%", C) + " ", "" ) +
WriteIf ( Sell , "\n"+"EXIT LONG / Reverse Signal at " + StrFormat("%.2f%", C) + " ", "" ) + "\n" +
EncodeColor( colorWhite ) +
WriteIf( Sell , "Total Profit/Loss for the Last Trade Tk." + StrFormat("%.2f%", ( C - BuyPrice )) + "", "" ) +
WriteIf( Buy , "Total Profit/Loss for the Last trade Tk." + StrFormat("%.2f%", ( SellPrice - C )) + "", "" ) +
WriteIf( Long AND NOT Buy, "Trade : Long - Entry price Tk." + StrFormat("%.2f%", ( BuyPrice )), "" ) +
WriteIf( shrt AND NOT Sell, "Trade : Short - Entry price Tk." + StrFormat("%.2f%", ( SellPrice )), "" ) + "\n" +
WriteIf( Long AND NOT Buy, "Current Profit/Loss Tk." + StrFormat("%.2f%", ( C - BuyPrice )) + "", "" ) +
WriteIf( shrt AND NOT Sell, "Current Profit/Loss Tk." + StrFormat("%.2f%", ( SellPrice - C )) + "", "" ) );

_SECTION_END();
*/


//Explore Analysis
BuyPrice = ValueWhen( Buy, C );
SellPrice = ValueWhen( Sell, C );
Filter = ( Buy OR Sell );;
AddColumn( IIf( Buy, BuyPrice, Null ), "Buy ", 6.2, 1, colorGreen );
AddColumn( IIf( Sell, SellPrice, Null ), "Sell ", 6.2, 1, colorRed );

//Alerts
AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1);
AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short", 1);

////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////

// The current bar should be more than previous bar value + 5 points for buy in uptrend
BuyV = Buy;
// the current bar should be less than previous bar value - 5 points for sell in downtrend
SellV = Sell ;

// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1));
SellSB= BarsSince(Ref(SellV,-1));

// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,1);
//Datefine = 1;


// Check if it is time to close the postions.
EOD = IIf(TimeNum() < 153000, 0, 1);
noEOD = IIf(TimeNum() < 153000, 1, 0);

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
// We can signal sell only if previous signal was a buy.
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
Sell = EOD AND BuySB < SellSB;



messageboard = ParamToggle("Message Board","Show|Hide",0);


Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
Sell = EOD AND BuySB < SellSB;
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";

tar1 = entry + (entry * .0089);
tar2 = entry + (entry * .0178);
tar3 = entry + (entry * .0216);

bars = i;
i = 0;
}
if(Short == 1)
{
sig = "SELL";
entry = C;

tar1 = entry - (entry * .0099);
tar2 = entry - (entry * .0175);
tar3 = entry - (entry * .0216);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);

Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);


}


printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 70, x2, y , 7, 7 ) ;
GfxTextOut( ( " NK intraday "),88,y-71);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-46) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-21);
GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(IIf(TimeNum() < 153000, 0, (C-entry))),IIf(TimeNum() < 153000, 0, (entry-C))),2.2)), 170, y-21);;

}
 
#7
Your formula used basically is kbrain. Profit/loss given in it is different way.
I enclose a copy of it with heikinashi.




//KBrain System Coded by Karthikmarar. Blog. www.stocktechnician.blogspot.com email. [email protected]
//System based on the BrainTrend system in Metatrader
// The Turquiose colored Dot indicates start of a Up Trend
// The Magenta DOt indicates end of an Up move and beginning of a downmove
// The system is a Stop and reverse system
//Revision Index - V.1.1 resolves the scan issues
_SECTION_BEGIN("Heikin");
HaC =EMA((O+C+H+L)/4,3);
//HaO = AMA( Ref( HaC, -1 ), 0.8 );

HaO = AMA( Ref( HaC, -1 ), 0.5 );

HaH = Max( H, Max( HaC, HaO ) );
HaL = Min( L, Min( HaC, HaO ) );

e1=EMA(C,21);e2=MA(C,26);
ehh=e1>e2 ; ell=e1<e2 ;
//ri= (e1+e2)/2;Colri=IIf(ehh,colorBlue,colorRed);

ri= (e1+e2)/2;Colri=IIf(ehh,colorBrightGreen,colorRed);


//SetBarFillColor(IIf(Hac>Hao,colorBlue,colorRed));

SetBarFillColor(IIf(Hac>Hao,colorBrightGreen,colorRed));

//Colcan=IIf(Hac>ri,colorBlue,colorRed);


Colcan=IIf(Hac>ri,colorBrightGreen,colorRed);

PlotOHLC( HaO, HaH, HaL, HaC, "" + Name(), colcan, styleCandle | styleNoLabel );


mycolor=IIf((C*.993)>(MA(C,35)*.993),colorBrightGreen,colorRed) ;

//Plot( C*.993, "Close", mycolor , styleNoTitle | styleLine | styleThick);
//Plot( (MA(C,35)*.993), "Close", mycolor , styleNoTitle | styleLine | styleThick );



_SECTION_END();

_SECTION_BEGIN("KBrain");
//========================Initiation================ ========
bts=ParamToggle("BrainTrend1 signal","No|Yes" ,1);
btst=ParamToggle("BrainTrend1 stop","No|Yes" ,1);
btsl=ParamToggle("BrainTrend1 stop line","No|Yes" ,1);
period=Param("Period",14,6,20,1);
x1=53;
x2=47;
d=2.3;
f=7;
s=1.5;
range=ATR(f);
Range1 = ATR(f)/d;
Range2 = (ATR(f)*s)/4;
range3=ATR(10);
R = ((HHV(H,period) - C) /(HHV (H,period) -LLV (L,period))) *-100;
EMA1= EMA(R,Period);
EMA2= EMA(EMA1,5);
Difference= EMA1 - EMA2;
ZeroLagEMA= EMA1 + Difference;
value2=abs(ZeroLagEMA);


function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
}


for( i = 1; i < Period-1; i++ )
{


tm = 1;
bstop = 1;
sstop = 1;
p = 1;
}

for( i = period+10; i < BarCount; i++ )
{
C[0]=0;
Value2[0]=0;
p[0]=0;
Plot1[0]=0;
Plot2[0]=0;
Val1=0;
Val2=0;
temp[0]=0;
Value3[0]=0;
tm[0]=0;
p1=0;
bt1[0]=0;
bt2[0]=0;
r[0]=0;
bt1a[0]=0;
bt2a[0]=0;
istop[0]=Val1[0];
stop=Val1[0];
bstop[0]=0;
sstop=0;
//==================================Indicators====== ======================
{
if (value2 < x2 AND abs(Close-Close[i-2]) > range1)
p = 1 ;
else
{
if (value2 > x1 AND abs(Close-Close[i-2]) > Range1)
p = 2 ;

else

p=0;
}
}

if ((value2 < x2 AND p == 1) OR (value2 < x2 AND p == 0))

{
if (abs(Close-Close[i-2]) > Range1)
{
Plot1=H;
Plot2=L;
}
else
{
Plot1=Plot1[i-1];
Plot2=Plot2[i-1];
}
}
else
{
if ((value2 > x1 AND p == 2) OR (value2 > x1 AND p == 0))

{
Plot1=L;
Plot2=H;
}
else
{
Plot1=Plot1[i-1];
Plot2=Plot2[i-1];
}
}
//==================KBrain Signal ====================================
{
if (value2 < x2 AND (abs(Close-Close[i-2]) > Range1))
{
if (p == 1 OR p == 0)
Value3=L-range3;
val1=Value3;
p=1;
temp=1;
}
else
{
temp=temp[i-1];
}
{
if (value2 > x1 AND (abs(Close-Close[i-2]) > Range1))
{
if (p == 2 OR p == 0)
Value3=H+range3;
val2=Value3;
p=2;
temp=2;;
}

}
}
{

if (temp==1 AND Plot1>0 AND tm != 1)
tm= 1;

if (temp==2 AND Plot2>0 AND tm != 2)
tm=2;

}
//===============================stop=============== =========================
{
if (value2 < x2 AND (abs(Close-Close[i-2]) > Range1)AND p !=2)

{
value3=L-range3;
va1=Value3;
p1=2;
r=Va1;
bstop=Va1;
bt2=bt2[i-1];
}

if (value2 > x1 AND (abs(Close-Close[i-2]) > Range1)AND p !=1)

{
Value3=H+range3;
va2=Value3;
p1=1;

r=Va2;
sstop=Value3;
bt1=bt1[i-1];
}

}



if (val1 == 0 AND val2 == 0 AND p == 0 )
{
bstop=bstop[i-1];
sstop=sstop[i-1];
}


if (bstop<bstop[i-1] AND tm==1 AND tm[i-1]==1) bstop=bstop[i-1];
if (sstop>sstop[i-1] AND tm==2 AND tm[i-1]==2) sstop=sstop[i-1];

}
//=============================SYSTEM=============== =======================
Mycolor=IIf(p==1,colorLime,IIf(p==2,colorRed,colorBlue));

PlotShapes( shapeCircle* (bts AND tm==1 AND Ref(tm,-1)==2),colorTurquoise, 0, bstop, 0 );
PlotShapes( shapeCircle* (bts AND tm==2 AND Ref(tm,-1)==1), colorCustom12, 0, sstop, 0 );
PlotShapes( IIf(btst AND p==1,shapeSmallCircle,Null), colorTurquoise,0,bstop,0);
Plot(IIf(btsl AND tm==1,bstop,Null),"",colorPaleBlue,1);
PlotShapes( IIf(btst AND p==2,shapeSmallCircle,Null), colorCustom12,0,sstop,0);
Plot(IIf(btsl AND tm==2,sstop,Null),"",colorLightYellow,1);
Buy=Cover=(bts AND tm==1 AND Ref(tm,-1)==2);
Sell=Short=(bts AND tm==2 AND Ref(tm,-1)==1);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
//=================TITLE============================ ================================================== ==================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "KBrain V 1.1. " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"\n" +EncodeColor(colorYellow) +"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+

EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));

_SECTION_END();
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
Filter=(Buy OR Sell );;
AddColumn(IIf(Buy,BuyPrice,Null)," Buy ", 6.2,1,colorGreen);
AddColumn(IIf(Sell,SellPrice,Null)," sell ",6.2,1,colorOrange);

_SECTION_BEGIN("kgs stoch buy sell");


a=StochK(14,3) ;
b=StochD(14,3,3) ;

Buy = Cross( a,b ) ;
Sell = Cross( b,a ) ;
//Short = Sell;
//Cover = Buy;



Buy = b<20 ;
Sell = b>80 ;


//AlertIf( Buy, "", "MA cross BUY", 1,1+2 );

//AlertIf( Sell, "", "MA cross SELL", 2 ,1+2);

PlotShapes( shapeSmallCircle*Buy, colorLightGrey, 0, L, -10 );
PlotShapes( shapeSmallCircle*Sell, colorLightGrey, 0, H, 10 );
_SECTION_END();

Regards
 
#9
i think nobody is getting what i exactly want. so i am making it little bit simple. can anybody will add perticuler date and time with buy sell signals. means instead of buy sell arrows i want perticuler date and time with that arrors here is afl. please help


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


_SECTION_BEGIN("Volume Price Analysis - V.1.2");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartOptions(2, chartWrapTitle );
//=======================================================================================
DTL=Param("Linear regression period",60,10,100,10);
wbf=Param("WRB factor",1.5,1.3,2.5,.1);
nbf=Param("NRB factor",0.7,0.3,0.9,0.1);
TL=LinRegSlope(MA(C, DTL),2);
Vlp=Param("Volume lookback period",30,20,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(wbf*arg);
nrb=rg<(nbf*arg);
Vl=V<Ref(V,-1) AND V<Ref(V,-2);
upbar=C>Ref(C,-1);
dnbar=C<Ref(C,-1);
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc==0,arg,x);
Vb=V>Vrg OR V>Ref(V,-1);
ucls=x1<2;
dcls=x1>2;
mcls=x1<2.2 AND x1>1.8 ;
Vlcls=x1>4;
Vhcls=x1<1.35;
j=MA(C,5);
TLL=LinRegSlope(j,40) ;
Tlm=LinRegSlope(j,15) ;
tls=LinRegSlope(j,5);
mp=(H+L)/2;
_SECTION_END();
//==========================================================================================

//=======================================================================================================================

//============================================================================================================================
// commentary

_SECTION_BEGIN( "KBrain" );
//========================Initiation================ ========
bts = ParamToggle( "BrainTrend1 signal", "No|Yes" , 1 );
btst = ParamToggle( "BrainTrend1 stop", "No|Yes" , 1 );
btsl = ParamToggle( "BrainTrend1 stop line", "No|Yes" , 1 );
period = Param( "Period", 14, 6, 20, 1 );
x1 = 53;
x2 = 47;
d = 2.3;
f = 7;
s = 1.5;
range = ATR( f );
Range1 = ATR( f ) / d;
Range2 = ( ATR( f ) * s ) / 4;
range3 = ATR( 10 );
R = ( ( HHV( H, period ) - C ) / ( HHV ( H, period ) - LLV ( L, period ) ) ) * -100;
EMA1 = EMA( R, Period );
EMA2 = EMA( EMA1, 5 );
Difference = EMA1 - EMA2;
ZeroLagEMA = EMA1 + Difference;
value2 = abs( ZeroLagEMA );


function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C ) / ( HHV( H, periods ) - LLV( L, periods ) );
}


for ( i = 1; i < Period - 1; i++ )
{


tm = 1;
bstop = 1;
sstop = 1;
p = 1;
}

for ( i = period + 10; i < BarCount; i++ )
{
C[0] = 0;
Value2[0] = 0;
p[0] = 0;
Plot1[0] = 0;
Plot2[0] = 0;
Val1 = 0;
Val2 = 0;
temp[0] = 0;
Value3[0] = 0;
tm[0] = 0;
p1 = 0;
bt1[0] = 0;
bt2[0] = 0;
r[0] = 0;
bt1a[0] = 0;
bt2a[0] = 0;
istop[0] = Val1[0];
stop = Val1[0];
bstop[0] = 0;
sstop = 0;
//==================================Indicators====== ======================
{
if ( value2 < x2 AND abs( Close - Close[i-2] ) > range1 )
p = 1 ;
else
{
if ( value2 > x1 AND abs( Close - Close[i-2] ) > Range1 )
p = 2 ;

else

p = 0;
}
}

if ( ( value2 < x2 AND p == 1 ) OR ( value2 < x2 AND p == 0 ) )

{
if ( abs( Close - Close[i-2] ) > Range1 )
{
Plot1 = H;
Plot2 = L;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}
else
{
if ( ( value2 > x1 AND p == 2 ) OR ( value2 > x1 AND p == 0 ) )

{
Plot1 = L;
Plot2 = H;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}

//==================KBrain Signal ====================================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 1 OR p == 0 )
Value3 = L - range3;

val1 = Value3;

p = 1;

temp = 1;
}
else
{
temp = temp[i-1];
}

{
if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 2 OR p == 0 )
Value3 = H + range3;

val2 = Value3;

p = 2;

temp = 2;;
}

}
}

{

if ( temp == 1 AND Plot1 > 0 AND tm != 1 )
tm = 1;

if ( temp == 2 AND Plot2 > 0 AND tm != 2 )
tm = 2;

}

//===============================stop=============== =========================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 2 )

{
value3 = L - range3;
va1 = Value3;
p1 = 2;
r = Va1;
bstop = Va1;
bt2 = bt2[i-1];
}

if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 1 )

{
Value3 = H + range3;
va2 = Value3;
p1 = 1;

r = Va2;
sstop = Value3;
bt1 = bt1[i-1];
}

}



if ( val1 == 0 AND val2 == 0 AND p == 0 )
{
bstop = bstop[i-1];
sstop = sstop[i-1];
}


if ( bstop < bstop[i-1] AND tm == 1 AND tm[i-1] == 1 )
bstop = bstop[i-1];

if ( sstop > sstop[i-1] AND tm == 2 AND tm[i-1] == 2 )
sstop = sstop[i-1];

}

//=============================SYSTEM=============== =======================
Mycolor = IIf( p == 1, colorLime, IIf( p == 2, colorRed, colorBlue ) );

PlotShapes( IIf( btst AND p == 1, shapeSmallCircle, Null ), colorWhite, 0, bstop, 0 );

Plot( IIf( btsl AND tm == 1, bstop, Null ), "", colorWhite, 1 );

PlotShapes( IIf( btst AND p == 2, shapeSmallCircle, Null ), colorWhite, 0, sstop, 0 );

Plot( IIf( btsl AND tm == 2, sstop, Null ), "", colorWhite, 1 );

PlotShapes( shapeUpArrow* ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 ), colorGreen, 0, bstop, 0 );

PlotShapes( shapeDownArrow* ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 ), colorRed, 0, sstop, 0 );


Buy = Cover = ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 );

Sell = Short = ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 );

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

_SECTION_END();

////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////

// The current bar should be more than previous bar value + 5 points for buy in uptrend
BuyV = Buy;
// the current bar should be less than previous bar value - 5 points for sell in downtrend
SellV = Sell ;

// Bars since previous buy or sell signal.
BuySB = BarsSince(Ref(BuyV,-1));
SellSB= BarsSince(Ref(SellV,-1));

// Ignore the previous day bar
Datefine = IIf(Ref(DateNum(),1) == Ref(DateNum(),-1),1,1);
//Datefine = 1;


// Check if it is time to close the postions.
EOD = IIf(TimeNum() < 153000, 0, 1);
noEOD = IIf(TimeNum() < 153000, 1, 0);

// We can signal buy only if previous signal was a sell.
Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
// We can signal sell only if previous signal was a buy.
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
Sell = EOD AND BuySB < SellSB;



messageboard = ParamToggle("Message Board","Show|Hide",0);


Buy = BuyV AND BuySB > SellSB AND Datefine AND noEOD;
Sell = EOD AND BuySB < SellSB;
Short = SellV AND BuySB < SellSB AND Datefine AND noEOD;
Cover = EOD AND BuySB > SellSB;
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";

tar1 = entry + (entry * .0089);
tar2 = entry + (entry * .0178);
tar3 = entry + (entry * .0216);

bars = i;
i = 0;
}
if(Short == 1)
{
sig = "SELL";
entry = C;

tar1 = entry - (entry * .0099);
tar2 = entry - (entry * .0175);
tar3 = entry - (entry * .0216);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);

Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);


}


printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 70, x2, y , 7, 7 ) ;
GfxTextOut( ( " NK intraday "),88,y-71);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-46) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-21);
GfxTextOut( (" P/L : " + WriteVal(IIf(sig == "BUY",(IIf(TimeNum() < 153000, 0, (C-entry))),IIf(TimeNum() < 153000, 0, (entry-C))),2.2)), 170, y-21);;

}

//Alerts
AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1);
AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short", 1);
 

Similar threads