mayank
March 2, 2018, 9:37am
1
type or pStopLevel = 1 - Param("trailing stop %", 3, 0.1, 10, 0.1)/100;
Buy = Cross( MACD(), Signal() );
Sell = 0;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel;
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * stoplevel, trailstop );
trailARRAY[ i ] = trailstop;
}
}
PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot( Close,"Price",colorBlack,styleBar);
Plot( trailARRAY,"trailing stop level", colorRed );aste code here
i wanto to add selll order signal when signal cross macd, how can i add it in this code
Assuming you want to exit at the closing price of the day, just replace:
Sell = 0;
with
Sell = Cross(Signal(), MACD());
SellPrice = C;
mayank
March 2, 2018, 2:12pm
3
first i would like to mention the code is from http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/
i m learning how to code .
the code is giving sell signal till SL hits. i dont know how to add sell loop in this code that when sell signal generate then again a buy signal should come
Add another if statement to check for your other Sell signal. The exit role model is already there in the KB code. Use flags to distinguish between trail exit and standard Sell exit. That's basically it. If everything is set and done it will act and look similar to lower example (which only serves as proof that I am not posting things made up out of thin air).
Don't expect copy & paste ready code. Try to understand the exiting one. "Don't know..." is not an excuse. Start doing something. Use debugging to see what happens when. Read the forums.
mayank
March 3, 2018, 11:21am
5
fxshrat:
debugging
sometime the buying price on analysis window and on the chart are slight different , now trying to plot SL price on chart
PanoS
March 3, 2018, 9:50pm
6
hello @mayank
this is only about photos
a Video of How to use the Snipping Tool in Windows
Also with Amibroker we can go to the Menu, Edit > Image > export to file
Have a nice day
2 Likes
mayank
March 4, 2018, 12:58am
7
hi ,thank you I will remember next time while uploading photo