Ordersend() function executing too many orders

 
Hi everyone

I am kinda new to programming and am currently trying to code my own EA.

when im tried to backtest my EA using the ordersend() function, the EA starts to execute too many new orders and thus ccausing the EA to overload and thus getting the error 148.

According to my understanding, the ordersend() is programmed to execute a single trade rather than multiple trades. Could the problem lie in my trading condition before entering a new new trade??

Thanks for all the help!
 
cheesybites12:
Hi everyone

I am kinda new to programming and am currently trying to code my own EA.

when im tried to backtest my EA using the ordersend() function, the EA starts to execute too many new orders and thus ccausing the EA to overload and thus getting the error 148.

According to my understanding, the ordersend() is programmed to execute a single trade rather than multiple trades. Could the problem lie in my trading condition before entering a new new trade??

Thanks for all the help!
If you only want one trade just call OrderSend() once, don't call it again and again for each tick . . . before you call it are you checking to see if you already have an open Order ?
 
// Trading condition
double rhigh = iHigh(Symbol(), Period(), iHighest(Symbol(), Period(), MODE_HIGH, TradingPeriod, 0));
double rlow = iLow(Symbol(), Period(), iLowest(Symbol(), Period(), MODE_LOW, TradingPeriod, 0));

double ahigh = iHigh(Symbol(), Period(), iHighest(Symbol(), Period(), MODE_HIGH, TradingPeriod1, 0));
double alow = iLow(Symbol(), Period(), iLowest(Symbol(), Period(), MODE_LOW, TradingPeriod1, 0));

// Enter Long position
if(Bid >= rhigh || Bid >= ahigh )
{
OrderSend(Symbol(), OP_BUYLIMIT, LotSize, rhigh, Slippage, StopLoss, 0, "EAName", MagicNumber, 0, Green);
}
else if (Ask <= rlow || Bid >= alow)
{
OrderSend(Symbol(),OP_SELLSTOP, LotSize, rlow, Slippage, StopLoss1, 0, "EAName", MagicNumber, 0, Red);
}

this is my trading condition. as long as it breaks a 20 day high, enter a position. however when i run it, all it does is just entering a new position the moment the EA starts.


 
cheesybites12:
<CODE REMOVED>

this is my trading condition. as long as it breaks a 20 day high, enter a position. however when i run it, all it does is just entering a new position the moment the EA starts.


Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. RaptorUK already toll you to check first before opening another. When "it breaks a 20 day high, enter a position." The next tick you enter a position. The next tick you enter a position...
 
oh sorry okay i just edited my post.
 

I now understand why William and Simon's posts appear so caustic at times

// Trading condition
double rhigh = iHigh(Symbol(), Period(), iHighest(Symbol(), Period(), MODE_HIGH, TradingPeriod, 0));
double rlow = iLow(Symbol(), Period(), iLowest(Symbol(), Period(), MODE_LOW, TradingPeriod, 0));

double ahigh = iHigh(Symbol(), Period(), iHighest(Symbol(), Period(), MODE_HIGH, TradingPeriod1, 0));
double alow = iLow(Symbol(), Period(), iLowest(Symbol(), Period(), MODE_LOW, TradingPeriod1, 0));

// Enter Long position
if(Bid >= rhigh || Bid >= ahigh )
{
OrderSend(Symbol(), OP_BUYLIMIT, LotSize, rhigh, Slippage, StopLoss, 0, "EAName", MagicNumber, 0, Green);
}
else if (Ask <= rlow || Bid >= alow)
{
OrderSend(Symbol(),OP_SELLSTOP, LotSize, rlow, Slippage, StopLoss1, 0, "EAName", MagicNumber, 0, Red);
}

Without any clue about the difference between TradingPeriod and TradingPeriod1, do you really expect that anyone will be able to pinpoint your problem?

Reason: