I've written some code on an Expert Advisor to trade on the Fiji-trend-indicator. The EA recognises the first arrow indicator and executes a trade accordingly, however, when the second arrow is supposed to show up on a back test, the rest of the code doesn't do anything.
I see that the custom price box in the indicator that follows the bid price on the chart stops moving up or down in value when the EA executes the first trade, maybe that's where thing go wrong?
double CloseAllTradesThisPair()
{
for (int i=OrdersTotal();i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol()==Symbol())
{
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),10,Red);
}
}
}
extern bool bought = false;
extern bool sold = false;
double Lotsize = AccountBalance()/5000;
double Lots = NormalizeDouble(Lotsize,2);
void OnTick()
{
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
return(0);
}
double uparrow = iCustom(Symbol(),PERIOD_CURRENT,"fiji-trend-indicator",2,0);
double dnarrow = iCustom(Symbol(),PERIOD_CURRENT,"fiji-trend-indicator",3,0);
if(uparrow < 1000 && i==0)
{
double buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,10,0,0,NULL,0,0,Green);
bought = true;
}
if(dnarrow < 1000 && i==0)
{
double sellticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,10,0,0,NULL,0,0,Red);
sold = true;
}
if(bought != true && dnarrow < 1000 )
{
CloseAllTradesThisPair();
double sticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,10,0,0,NULL,0,0,Red);
}
if(sold != true && uparrow < 1000)
{
CloseAllTradesThisPair();
double bticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,10,0,0,NULL,0,0,Green);
}
}