Newbie programming.

 
Hi, gurus,

I am very new here and I modified some codes from internet and composed one here, but it didn't pass the test run, very likely due to programming problem. Can anyone here help correct my mistakes? Many thanks in advance. It would be good if there is a diagnostic program for debug purpose.


extern double Lots =0.1;
extern double TrailingStop = 50;
extern double StopLoss = 30;
extern double MovingPeriodL = 5;
extern double MovingPeriodS = 2
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double ADXDIP, ADXDIM, RSI, MAL, MAS;
int cnt, ticket, total;


if(Bars < 100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit < 10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}



ADXDIP = iADX(NULL, 0, 5, PRICE_CLOSE, MODE_PLUSDI, 0);
ADXDIM = iADX(NULL, 0, 5, PRICE_CLOSE, MODE_MINUSDI, 0);
RSI=iRSI(NULL,0,7,PRICE_CLOSE,0);
MAL=iMA(NULL,0,MovingPeriodL,0,MODE_EMA,PRICE_CLOSE,0);
MAS=iMA(NULL,0,MovingPeriodS,0,MODE_EMA,PRICE_CLOSE,0);

total = OrdersTotal();
if(total < 1)

{
// no opened orders identified
if(AccountFreeMargin() < (1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}


void CheckForOpen()
{
int res;

////---- sell conditions
if(MAS<MAL && ADXDIM>ADXDIP && RSI>10)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,5,5,"MA DI RSI",MAGICMA,0,Red);
return;
}
if(ADXDIP > ADXDIM)
{OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // close position
return(0); // exit
}
//---- buy conditions
if(MAS>MAL && ADXDIP>ADXDIM && RSI<90)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,5,5,"MA DI RSI",MAGICMA,0,Blue);
return;
}
if(ADXDIM > ADXDIP)
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); // close position
return(0); // exit
}
//----
}

for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY) // long position is opened
{
// check for trailing stop
if(TrailingStop > 0)
{
if(Bid - OrderOpenPrice() > Point*TrailingStop)
{
if(OrderStopLoss() < Bid - Point*TrailingStop)
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - Point*TrailingStop,
OrderTakeProfit(), 0, Green);
return(0);
}
}
}
}
else // go to short position
{
// check for trailing stop
if(TrailingStop > 0)
{
if((OrderOpenPrice() - Ask) > (Point*TrailingStop))
{
if((OrderStopLoss() > (Ask + Point*TrailingStop)) ||
(OrderStopLoss() == 0))
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + Point*TrailingStop,
OrderTakeProfit(), 0, Red);
return(0);
}
}
}
}
}
}
//----
}
}
//+-----------------
 

Ming

> but it didn't pass the test run

Got any more detail?

Were there errors in the Journal?

Were any orders opened?

Did it simply lose all the Balance?

What? :)

-BB-

 
BarrowBoy:

Ming

> but it didn't pass the test run

Got any more detail?

Were there errors in the Journal?

Were any orders opened?

Did it simply lose all the Balance?

What? :)

-BB-


Got it figured out by myself. Thanks.
Reason: