pls merge these afls

bunti_k23

Well-Known Member
#1
Code:
NW[0] = 0; 
NW[BarCount-1] = Null; 
 for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = H[i];
sig = "BUY";
sl = Ref(NW,-1);
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
  
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = L[i];
sl = Ref(NW,-1);
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
  
  
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, NW[BarCount-1], Ref(NW, -1));
sl = ssl[BarCount-1];
 
Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
 
 
 
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
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 - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "bunti_k23"),13,y-100);
GfxTextOut( (" "),27,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);
 
}
pls add these target lines into the afl below ,also add the 4th line which shd be the stoploss line .it will be above or below the signal candle opposite to the target lines .:)

Code:
_SECTION_BEGIN("MADE BY bunti_k23");



e1=EMA(C,3);
e2=EMA(H,15);
e3=EMA(L,15);

//Plot(e1,"",colorYellow,styleLine |styleThick);
//Plot(e2,"",colorLightYellow,styleDots );
//Plot(e3,"",colorLightYellow,styleDots );

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



////////////////////////
Length = 8;
Price = EMA(Close, Length);
 
// Keltner
kLength = Length;
kN = 1.5;
kATR = ATR(kLength);
kUpper = Price + kN * kATR;
kLower = Price - kN * kATR;
 
// Bollinger
bbLength = Length;
bbN = 2;
bbStDevValues = StDev(Close, bbLength);
bbUpper = Price + bbN * bbStDevValues;
bbLower = Price - bbN * bbStDevValues;
 
IsSignal =
    bbUpper <= kUpper AND
    bbLower >= kLower;
 ///////////////////////////////////
Derived=WMA(((H+L)/2)+(O-C),3); 
i=WMA(Derived,3); 
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5; 
Lower=(Derived-StDev(Derived,7))-ATR(2)/1; 
color=IIf(BarsSince(Cross(Lower,C))> 
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed); 
Plot(C,"",Color,64); 
//Plot(Upper,"upper band",colorGreen); 
//Plot(Lower,"lower band",colorDarkRed); 


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

Buy=Cross(Close,Upper) AND Cross(e1,e2)AND ISSIGNAL < 1 AND PDI(10) > Ref(PDI(10),-1) AND MDI(10) < ADX(10) AND PDI(10) > ADX(10);
Sell=Cross(Lower,Close) AND Cross(e3,e1) AND ISSIGNAL < 1 AND MDI(10) > Ref(MDI(10),-1) AND PDI(10) < ADX(10) AND MDI(10) > ADX(10);
Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);
SetBarFillColor(Col);


Cover=Buy;
Short=Sell;
PlotShapes(IIf(Buy,shapeUpArrow ,shapeNone),colorWhite,0,L,-35);
PlotShapes(IIf(Sell,shapeDownArrow , shapeNone),colorWhite,0,H,-35);
_SECTION_END();  

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

casoni

Well-Known Member
#2
Hello bunti_k23 ,
You want to combine , your system + NRTR / NMA !!
or you just want to plot 3 target levels from your buy / short conditions ??
 

bunti_k23

Well-Known Member
#3
Hello bunti_k23 ,
You want to combine , your system + NRTR / NMA !!
or you just want to plot 3 target levels from your buy / short conditions ??
I just want the target lines with 1 extra line as a stoploss which will b abv or blow the signal incase of buy or sell.and they shd b adjustable .
 

casoni

Well-Known Member
#4
Hello

check this

_SECTION_BEGIN("MADE BY bunti_k23");



e1=EMA(C,3);
e2=EMA(H,15);
e3=EMA(L,15);

//Plot(e1,"",colorYellow,styleLine |styleThick);
//Plot(e2,"",colorLightYellow,styleDots );
//Plot(e3,"",colorLightYellow,styleDots );

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



////////////////////////
Length = 8;
Price = EMA(Close, Length);

// Keltner
kLength = Length;
kN = 1.5;
kATR = ATR(kLength);
kUpper = Price + kN * kATR;
kLower = Price - kN * kATR;

// Bollinger
bbLength = Length;
bbN = 2;
bbStDevValues = StDev(Close, bbLength);
bbUpper = Price + bbN * bbStDevValues;
bbLower = Price - bbN * bbStDevValues;

IsSignal =
bbUpper <= kUpper AND
bbLower >= kLower;
///////////////////////////////////
Derived=WMA(((H+L)/2)+(O-C),3);
i=WMA(Derived,3);
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5;
Lower=(Derived-StDev(Derived,7))-ATR(2)/1;
color=IIf(BarsSince(Cross(Lower,C))>
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed);
Plot(C,"",Color,64);
//Plot(Upper,"upper band",colorGreen);
//Plot(Lower,"lower band",colorDarkRed);


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

Buy=Cross(Close,Upper) AND Cross(e1,e2)AND ISSIGNAL < 1 AND PDI(10) > Ref(PDI(10),-1) AND MDI(10) < ADX(10) AND PDI(10) > ADX(10);
Sell=Cross(Lower,Close) AND Cross(e3,e1) AND ISSIGNAL < 1 AND MDI(10) > Ref(MDI(10),-1) AND PDI(10) < ADX(10) AND MDI(10) > ADX(10);
Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);
SetBarFillColor(Col);


Cover=Buy;
Short=Sell;
PlotShapes(IIf(Buy,shapeUpArrow ,shapeNone),colorWhite,0,L,-35);
PlotShapes(IIf(Short,shapeDownArrow , shapeNone),colorWhite,0,H,-35);
_SECTION_END();

//dummy [ your stoploss ]
bs=ValueWhen(Buy,Ref(L,-1),1);
ss=ValueWhen(short,Ref(H,-1),1);
NW = IIf(Buysetup,bs,ss);

for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = H;
sig = "BUY";
sl = nw;//Ref(NW,-1);
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = L;
sl = nw;//Ref(NW,-1);
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, NW[BarCount-1], Ref(NW, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", 3, styleLine|styleDots, Null, Null, Offset);




messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
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 - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "bunti_k23"),13,y-100);
GfxTextOut( (" "),27,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
//GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
//GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
//GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);

}
 

bunti_k23

Well-Known Member
#5
have u checked it? is it running on ur system? showing error on my system .
variable 'sig' used without having being initialized..and more errors....:confused:
 

bunti_k23

Well-Known Member
#7
afl woking but result is not good
Pls elaborate a little more....which afl u have chkd? 1St one without target lines or 2nd one with target lines.how u came to this conclusion that it is not working? Plz mention the details so i can try further for improvization.

Thankyou
Amit:)
 

casoni

Well-Known Member
#8
have u checked it? is it running on ur system? showing error on my system .
variable 'sig' used without having being initialized..and more errors....:confused:
Oh..i am extremely sorry Sir , [for the trouble you had ]

its working at my end .. see images posted here


 

bunti_k23

Well-Known Member
#9
Thanks for the help.much appreciated sirji:clapping:
Kindly tweak it for ami 5.6 Ver if possible:)hope not a hard task.
 

casoni

Well-Known Member
#10
Thanks for the help.much appreciated sirji:clapping:
Kindly tweak it for ami 5.6 Ver if possible:)hope not a hard task.
Hello bunti_k23
error you see ,it comes when you check [ code check and profile ]
once you do that formula dosent plot .
if you just apply the formula, it plots , as it did at my end
and i just merged your 2 files ,

Error is in Loop , and i am not good at Loops , .
to get rid of loop error ask Kelvin hand or trash , they are clever coders

i can give you anothe version which plots stoploss and tagets ...
they are without loops , but for that i need time .

lets hope Kelvin hand or trash makes this eror free and this can be used
in every system [ i.e univesal stoploss / target ]

Thank you