how to plot APPLYSTOP function

sr114

Well-Known Member
#11
It shows errors because the code snippet of the picture is just one part of the whole code.

It doesn't help you if I post the whole code. Then you don't learn anything. Just look at the code posted at AmiBroker website and play around with it.
in the image found that the tick is used with applystops.
can this tick be used with stopTypeNBar - N-bar stop?

if yes - any info?

rgds and thanx
 

trash

Well-Known Member
#12
in the image found that the tick is used with applystops.
can this tick be used with stopTypeNBar - N-bar stop?

if yes - any info?

rgds and thanx

Ticks in the title of the picture refers to Ticksize.

So 20 ticks or pips in EURUSD are 0.0020 or 20 * Ticksize and Ticksize being defined in Information window as 0.0001.

Ticks are not needed in n-bar stop.

N-bar stop means .. exit n-bars after buy or short entry.

Code:
StopLevel = Param( "N-bars", 10, 1, 100, 1 );
ApplyStop( stopTypeNBar, stopModeBars, StopLevel );
So in above code snippet default value is exit 10 bars after entry.

But you can combine multiple Applystop code lines within one code.
The one that gets reached first gets executed first and the other becomes obsolete.

Code:
bars = Param( "N-bars", 10, 1, 100, 1 );
ApplyStop( stopTypeNBar, stopModeBars, bars );
StopLevel = Param( "Stop Loss (point)", 20, 1, 100, 1 ) * TickSize;
ApplyStop( stopTypeLoss, stopModePoint, StopLevel, True );
 
Last edited:

sr114

Well-Known Member
#13
Ticks in the title of the picture refers to Ticksize.

So 20 ticks or pips in EURUSD are 0.0020 or 20 * Ticksize and Ticksize being defined in Information window as 0.0001.

Ticks are not needed in n-bar stop.

N-bar stop means .. exit n-bars after buy or short entry.

Code:
StopLevel = Param( "N-bars", 10, 1, 100, 1 );
ApplyStop( stopTypeNBar, stopModeBars, StopLevel );
So in above code snippet default value is exit 10 bars after entry.

But you can combine multiple Applystop code lines within one code.
The one that gets reached first gets executed first and the other becomes obsolete.

Code:
bars = Param( "N-bars", 10, 1, 100, 1 );
ApplyStop( stopTypeNBar, stopModeBars, bars );
StopLevel = Param( "Stop Loss (point)", 20, 1, 100, 1 ) * TickSize;
ApplyStop( stopTypeLoss, stopModePoint, StopLevel, True );
U made the day for me - i was wandering what this n-bar is? was a bit shaky apprehensive in using the n-bar stop.

the profit stop and trail stops rare executing in proper way.

want to know another thing. in the system - when the max profit is reached , want to exit out if the max profit comes down n % ( n is defined thru the param). what is the proper code snippets for the applystop profit target?

[max profit = PositionOpen==1, HHV(C,x) - EntryPrice, - while long
PositionOpen==-1, EntryPrice - LLV(C,x) - while short

b1=(1-n/100)*Maxprofit - want to use this in the profit target applystop]

thanx for the info.
rgds
 

trash

Well-Known Member
#14
want to know another thing. in the system - when the max profit is reached , want to exit out if the max profit comes down n % ( n is defined thru the param). what is the proper code snippets for the applystop profit target?

[max profit = PositionOpen==1, HHV(C,x) - EntryPrice, - while long
PositionOpen==-1, EntryPrice - LLV(C,x) - while short

b1=(1-n/100)*Maxprofit - want to use this in the profit target applystop]

thanx for the info.
rgds
Code:
StopLevel = Param( "Stop Loss (%)", 0.5, 0.1, 10, 0.1 );
TgtLevel = Param( "Profit target (%)", 0.5, 0.1, 10, 0.1 );

ApplyStop( stopTypeLoss, stopModePercent, StopLevel, True );
ApplyStop( stopTypeProfit, stopModePercent, TgtLevel, True );
For plotting the lines and shapes see the link to the example of AmiBroker percent trail stop given by Tomasz/Marcin and my pic showing shapes code.

 
Last edited:

sr114

Well-Known Member
#15
Code:
StopLevel = Param( "Stop Loss (%)", 0.5, 0.1, 10, 0.1 );
TgtLevel = Param( "Profit target (%)", 0.5, 0.1, 10, 0.1 );

ApplyStop( stopTypeLoss, stopModePercent, StopLevel, True );
ApplyStop( stopTypeProfit, stopModePercent, TgtLevel, True );
For plotting the lines and shapes see the link to the example of AmiBroker percent trail stop given by Tomasz/Marcin and my pic showing shapes code.

got it buddy - a big thanx and regards to u buddy

u made my day - i wa just wandering for the stop loss part inmy system

thanx again buddy

rest can be done

rgds
 

mehtaka

Active Member
#16
So????

Simply adjust the code given by Tomasz.

Instead of stoptypetrailing use stoptypeloss and stoptypeprofit.
Instead of stopmodepercent use stopmodepoint.
Instead of Highestsince(....) use Valuewhen(Buy, Buyprice - stoplevel) and/or Valuewhen(Buy, Buyprice + tgtlevel)

And it will look like below


And one hint in regards to plotshapes
Thank you Sr114
I tried doing that..still not able to plot the lines...below is the code which i did
do point me out whats wrong in it..

StopLevel = 2*ATR(14);

ApplyStop( stopTypeLoss, stopModePoint, StopLevel, True );

Equity( 1, 0 ); // evaluate stops, all quotes

SetOption("EveryBarNullCheck", True );
Buystop = IIf( Buy, BuyPrice-Stoplevel , Null );
Shortstop = IIf( Short, ShortPrice+Stoplevel , Null );

Plot( Buystop, "Buystop", colorRed );
Plot( Shortstop, "Shortstop", colorGreen );
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Sell==2, shapeHollowCircle, shapeNone), colorOrange, 0,High, Offset=30);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);
PlotShapes(IIf(Cover==2, shapeHollowCircle, shapeNone), colorDarkGreen, 0,Low, Offset=-30);
 

sr114

Well-Known Member
#17
Hi Trash

TgtLevel = Param( "Profit target (%)", 0.5, 0.1, 10, 0.1 );

ApplyStop( stopTypeProfit, stopModePercent, TgtLevel, True );
this means when the close is n% from the signal bar the profit stop will be activated and we are out.

but if we need that when the difference between the close and signal bar is equal to n% and then it retraces certain percentage , we will come out of the trade

ex.
sig bar close = 100, present bar close = 110 , so the profit is 10 and and if the close retraces so that this difference is 8 then we will exit from the trade - so at 20% of the max difference we set the profit target exit.

how to implement it in the applystop stoptypeprofit?

another query: the apply stop profit mode was triggered but subsequently when i reopened the chart - after setting the parameters of profit target the plot shapes of the profit target are not displaying in the chart while erlier it was displayed? whats the reason? any reason? only the regular exit ( condition1 = regular exit) is appearing in the chart

asking so much - as this equity function is foing over my head

rgds
 
Last edited:

sr114

Well-Known Member
#18
Thank you Sr114
I tried doing that..still not able to plot the lines...below is the code which i did
do point me out whats wrong in it..

StopLevel = 2*ATR(14);

ApplyStop( stopTypeLoss, stopModePoint, StopLevel, True );

Equity( 1, 0 ); // evaluate stops, all quotes

SetOption("EveryBarNullCheck", True );
Buystop = IIf( Buy, BuyPrice-Stoplevel , Null );
Shortstop = IIf( Short, ShortPrice+Stoplevel , Null );

Plot( Buystop, "Buystop", colorRed );
Plot( Shortstop, "Shortstop", colorGreen );
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Sell==2, shapeHollowCircle, shapeNone), colorOrange, 0,High, Offset=30);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);
PlotShapes(IIf(Cover==2, shapeHollowCircle, shapeNone), colorDarkGreen, 0,Low, Offset=-30);


look at the image - apply stop is working fine - specially the condition 1 - regular exit

condition 1 = regular exit
condition 2= profit target

u are using same condition for exiting in different scenerio. so if u want to exit with profit locking use the applystop type profit and u will get the exit. for the plotting - read again the code snippet in the ami ukb of Tomasz

actually read the applystop function and get the preference of the exit

rgds
 
Last edited:

mehtaka

Active Member
#19


look at the image - apply stop is working fine - specially the condition 1 - regular exit

condition 1 = regular exit
condition 2= profit target

u are using same condition for exiting in different scenerio. so if u want to exit with profit locking use the applystop type profit and u will get the exit. for the plotting - read again the code snippet in the ami ukb of Tomasz

actually read the applystop function and get the preference of the exit

rgds
I am getting the exit on the chart or the backtest properly...
need to plot the lines so that i can visually see it, where my initially stop is.
 
Last edited:

Similar threads