% Trailing stoploss Optimised System

yasu222

Active Member
#1
Hi!

I require the Enhanced optimized System with the help of following indicator. Please anybody code it.

Stop_Trail%

perc:=Input("Trailing Loss % :",0,100,14);
loss:=C*perc/100;
trail:=
If(C>PREV AND Ref(C,-1)>PREV,
Max(PREV,C-loss),
If(C<PREV AND Ref(C,-1)<PREV,
Min(PREV,C+loss),
If(C>PREV,C-loss,C+loss)));
Trail

Thanks in Advance
 
#3
Hi!

I require the Enhanced optimized System with the help of following indicator. Please anybody code it.

Stop_Trail%
PHP:
RequestTimedRefresh( 1 );
_SECTION_BEGIN("Prev ");
prev=AMA2(C, 1, 0);
d=IIf(C>Ref(Max(Max(H, Ref(H, -20)), Max(Ref(H, -10), Ref(H, -15))), -1), Min(Min(L, Ref(L, -20)), Min(Ref(L, -10), Ref(L, -15))), 
IIf(C<Ref(Min(Min(L, Ref(L, -20)), Min(Ref(L, -10), Ref(L, -15))), -1), Max(Max(H, Ref(H, -20)), Max(Ref(H, -10), Ref(H, -15))), PREV));
a=Cross(Close, d);
b=Cross(d, Close);
state=IIf(BarsSince(a)<BarsSince(b), 1, 0);
s=state>Ref(state, -1);
ss=state<Ref(state, -1);
sss=state==Ref(state, -1);
col=IIf(state == 1, 51, IIf(state ==0, 4, 1));
Plot(C, "", Col, 64);
_SECTION_END();

_SECTION_BEGIN("Breakout Setting");
beginTradeTime= ParamTime( "No trade B4 ", "091500" );
endTradeTime= Param("End Time",151000,151000,233000,10);

EndDay = ParamTime( "No trade after ", "15:09:00" );
EndDay2 = ParamTime( "close position ", "15:09:00" );

tn = TimeNum();
dn = DateNum();
Exit = Ref( tn < EndDay2, -1 ) AND ( tn >= EndDay2 OR dn < Ref( dn, 1 ) );

Buy = Sell = Short = Cover = 0;

//Buy=Cross(C,d);

//Short=Cross(d,C);
Buy = Cross(Close, d);
Short = Cross (d, Close);

Buysetup=Flip(C,d);
Shortsetup=Flip(d,C);

Sell=Shortsetup OR exit;
Cover=Buysetup OR exit;

Buy=ExRem(Buy,Short);
Short=ExRem(Short,Buy);

Sell=ExRem(Sell,Cover);
Cover=ExRem(Cover,Sell);

BuyPrice1=Max(Ref(C,-1),O)+0.5;// 0.5 - for better fill
ShortPrice1=Min(Ref(C,-1),O)+0.5;

sellPrice1=Min(Ref(C,-1),O)+0.5;
CoverPrice1=Max(Ref(C,-1),O)+0.5;

BuyPrice = ValueWhen(Buy,BuyPrice1); bp=NumToStr(BuyPrice,1.2);
ShortPrice = ValueWhen(Short,shortPrice1); shp=NumToStr(ShortPrice,1.2);
SellPrice = ValueWhen(Sell,sellPrice1);
CoverPrice = ValueWhen(Cover,coverPrice1);

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), 43, layer = 0,yposition = Low, offset = -20);
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = High, offset = -20); //shapeSmallCircle

//PlotShapes( IIf(Cover, shapeHollowUpArrow,shapeNone), colorAqua, layer = 0,yposition = Low, offset = 30);
//PlotShapes( IIf(Sell,shapeHollowDownArrow,shapeNone), colorPink, layer = 0, yposition = High, offset = -30);

StopLevel = Param( "Stop Loss (%)", 0.06, 0.01, 10, 0.01 );
TgtLevel = Param( "Profit target (%)", 0.45, 0.01, 10, 0.01 );

ApplyStop( stopTypeLoss, stopModePercent, StopLevel, True );
ApplyStop( stopTypeProfit, stopModePercent, TgtLevel, True );

Equity( 1, 0 );

sellcond1=Sell==1; covercond1=Cover==1;
sellcond2=Sell==2; covercond2=Cover==2;
sellcond3=Sell==3; covercond3=Cover==3;


//PlotShapes(IIf(sellcond1,shapeSmallDownTriangle,sh apeNone),colorOrange,0,H,-25);
PlotShapes(IIf(sellcond3,shapeHollowDownArrow,shapeNone),colorOrange,0,H,-15);
PlotShapes(IIf(sellcond2,shapeStar,shapeNone),colorOrange,0,H,-15);

//PlotShapes(IIf(covercond1,shapeSmallUpTriangle,sha peNone),colorLime,0,L,-25);
PlotShapes(IIf(covercond3,shapeHollowUpArrow,shapeNone),colorAqua,0,L,-25);
PlotShapes(IIf(covercond2,shapeStar,shapeNone),colorAqua,0,L,-25);

WriteIf( Sell == 1, "Regular exit",WriteIf( Sell == 3, "Profit Tgt",WriteIf( Sell == 2, "Max stop", "" ) ));
WriteIf( Cover == 1, "Regular exit",WriteIf( Cover == 3, "Profit Tgt",WriteIf( Cover == 2, "Max stop", "" ) ));

GraphXSpace=10;

_SECTION_END();
no=20;
res=HHV(H, no);
sup=LLV(L, no);
avd=IIf(C>Ref(res, -1), 1, IIf(C<Ref(sup, -1), -1, 0));
avn=ValueWhen(avd!=0, avd, 1);
s5d=IIf(avn==1, sup, res);
Plot(s5d, "", colorRed, styleLine|styleDashed|styleStaircase);
_SECTION_BEGIN("MASSAGE BOARD");

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1 )
{
entry = C[i];
sig = "BUY";
bars = i;
i = 0;
}
if(Short[i] == 1 )
{
sig = "SELL";
entry = C[i];
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);

messageboard =1;// ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 10;
x = 0;
x2 = 130;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 45, x2, y , 7, 7 ) ;
GfxTextOut( ( "PROFIT TREND"),2,y-47);
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 1, y-33);
GfxTextOut( ("Cur P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 1, y-19);;
}
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorYellow, styleLine|styleLine, Null, Null, Offset);
//Magfied Market Price
FS=20;
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite ); 
GfxSetTextColor (colorBrightGreen );
Hor=1;
Ver=8;
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack ); 
_SECTION_END();


try this %Stop_Trail + %target
 

umeshmandal

Well-Known Member
#6
I think no support for backward things...
Yasu, After a long gap we have a Member here who is not offended by the the very name of METASTOCK ! :D


Purush: I have been "tracking" him, he never lets an opportunity to go by to help anyone seeking it for Metastock.
I am sure yours will get solved here by him. !

Great going Purush ! :thumb: :clapping:
 

yasu222

Active Member
#7
Yasu, After a long gap we have a Member here who is not offended by the the very name of METASTOCK ! :D


Purush: I have been "tracking" him, he never lets an opportunity to go by to help anyone seeking it for Metastock.
I am sure yours will get solved here by him. !

Great going Purush ! :thumb: :clapping:
whats your problem :mad:
 

Similar threads