How can I code a Sell order in this code

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;



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;


Sell = Cross(Signal(), MACD());
SellPrice = C;

first i would like to mention the code is from
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.



sometime the buying price on analysis window and on the chart are slight different , now trying to plot SL price on chart

hello @mayank

this is only about photos :wink:

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


hi ,thank you I will remember next time while uploading photo