need very basic AFL help.(buy sell inside if)

#1
hello expert pls help actually i want one strategy to automate, but not getting inside below if to trigger placeorder function,
i have written pls check and correct if anyone want to help, its a exploration what i want whenever i run scanner or explore it check condition to watchlist stocks and if condition met it buy or sell,,,


buy = some condition,
sell = some condition;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Sell,Buy);
Cover = ExRem(Buy,Sell);

buyPrice = LastValue( Buy);
sellPrice = LastValue( Sell);
ShortPrice = LastValue(Short);
CoverPrice = LastValue(Cover);
PlotShapes( shapeUpArrow*Buy, colorAqua,0, L, -20);
PlotShapes( shapeDownArrow*Sell, colorAqua,0,H, -20) ;

Filter=Buy OR Sell;
Addcolumn(Buy,"Buy",1);
Addcolumn(Sell,"Sell",1);


_TRACE ("outside if");

//=============autotrader buy sell format============
if(Status("action")==actionExplore)
{
if ( LastValue(BuyPrice ) == 1 )
{


_TRACE ("inside buy if");
tradeType = "BUY";
targetb =BuyPrice + (BuyPrice*0.005);
target = targetb;

stoploss = dopen;
Plot(targetb,"",colorGreen,styleDots);
Plot(dopen,"",colorBlue,styleDots);

qty = readQuantityFromFile(QUANTITY_FILE, Name(), AT_QUANTITY);

placeBracketOrder(AT_EXCHANGE, Name(), tradeType, qty, buyPrice, target, stoploss, 0, 1);


}


if ( LastValue(SellPrice ) == 1 )
{


_TRACE ("oinside sell if");
tradeType = "SELL";
targets = SellPrice + (SellPrice*0.005);
target = targets;

stoploss = dopen;
Plot(targets,"",colorGreen,styleDots);
Plot(dopen,"",colorBlue,styleDots);

qty = readQuantityFromFile(QUANTITY_FILE, Name(), AT_QUANTITY);
placeBracketOrder(AT_EXCHANGE, Name(), tradeType, qty, sellPrice, target, stoploss, 0, 1);



}

if ( LastValue(ShortPrice ) == 1 )
{


_TRACE ("oinside sell if");
tradeType = "SELL";
targets = SellPrice + (SellPrice*0.005);
target = targets;

stoploss = dopen;
Plot(targets,"",colorGreen,styleDots);
Plot(dopen,"",colorBlue,styleDots);

qty = readQuantityFromFile(QUANTITY_FILE, Name(), AT_QUANTITY);
placeBracketOrder(AT_EXCHANGE, Name(), tradeType, qty, sellPrice, target, stoploss, 0, 1);

}


if ( LastValue(CoverPrice ) == 1 )
{


_TRACE ("oinside sell if");
tradeType = "SELL";
targets = SellPrice + (SellPrice*0.005);
target = targets;

stoploss = dopen;
Plot(targets,"",colorGreen,styleDots);
Plot(dopen,"",colorBlue,styleDots);

qty = readQuantityFromFile(QUANTITY_FILE, Name(), AT_QUANTITY);
placeBracketOrder(AT_EXCHANGE, Name(), tradeType, qty, sellPrice, target, stoploss, 0, 1);




}}
 
#2
SYNTAX of LastValue
LastValue (ARRAY, lastmode = True )
RETURNS
NUMBER

Read the syntax of Lastvalue. It returns Number. You can't nest two lastvalues.

It should be

if ( LastValue(Buy) == 1 )
{


_TRACE ("oinside sell if");
tradeType = "SELL";
targets = SellPrice + (SellPrice*0.005);
target = targets;

stoploss = dopen;
Plot(targets,"",colorGreen,styleDots);
Plot(dopen,"",colorBlue,styleDots);

qty = readQuantityFromFile(QUANTITY_FILE, Name(), AT_QUANTITY);
placeBracketOrder(AT_EXCHANGE, Name(), tradeType, qty, sellPrice, target, stoploss, 0, 1);

}
 

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?