How to code? - page 182

 

...

It is not an error in code

Go to Tools->History center and than choose and download 1 minute data from the symbol you want to test (all you need for 90% accuracy is 1 minute data, no need to download the rest)

Badguy:
Hi Coders

I'm still learning my first steps in MQL-Code.

what's the reason when I have following message in the journal:

Testgenerator:

unmatched data error ( volume limit 159 at 2009.05.06 19 15 exceeded )

where I must look in the code?

Thanks
 
abundance:
My friend & I are working on an EA. At some stage it (the EA) needs to read & retrieve the price at a certain time, say, 17:00 EST... etc.

Can any senior please advise how to do so, instead of counting the price bars backward? Maybe there is already a function written for it. Kindly help. Thank you all & God Bless!

B rgds/abundance

iBarShift(..) helps to find the number of bar on your chart, then use Close or Open.

 
Roger09:
iBarShift(..) helps to find the number of bar on your chart, then use Close or Open.

Thank you Roger. That was helpful. And sorry for not making it clearer. We need both Bid & Ask prices. How do we get them? Pl excuse if it is silly question

B rgds/abundance

 

Data error

Hi mladen

thanks for your fast response.

I think it's not a problem from the tickdata, because when I test with another EA it works fine.

I think it's problem with the Custom-Indicator.

I will built in follow indi: AllAverages_v2.3

double ALL_AVERAGES_0 = iCustom(NULL,ALL_AVERA_TF,"AllAverages_v2.3",ALL_AVERA_PERIOD,ALL_AVERA_SHIFT,ALL_AVERA_METHOD,ALL_AVERA_PRICE,0);

now I have following Message: invalid index buffer number in iCustom function

How to define this iCustom correctly?

Hi mladen I found the problem

I forgot one parameter: Color

the correct definition:

double ALL_AVERAGES_0 = iCustom(NULL,ALL_AVERA_TF,"AllAverages_v2.3",ALL_AVERA_PERIOD,ALL_AVERA_SHIFT,ALL_AVERA_METHOD,ALL_AVERA_PRICE,ALL_AVERA_COLOR,0);

mladen:
It is not an error in code Go to Tools->History center and than choose and download 1 minute data from the symbol you want to test (all you need for 90% accuracy is 1 minute data, no need to download the rest)
Files:
 
abundance:
Thank you Roger. That was helpful. And sorry for not making it clearer. We need both Bid & Ask prices. How do we get them? Pl excuse if it is silly question B rgds/abundance

All prices on charts are Bid. Ask=Bid+MarketInfo(Symbol(),MODE_SPREAD)*Point;

 

Restricting Trades

So I started writing a basic EA with one of those template generating EA builders. I seem to have gotten the premise of the EA template down, however I need a way to make the EA only enter one trade at max. Right now it keeps generating trades and causes the draw down to be rediculous. Here is the trade lot code:

//Check position

bool IsTrade = False;

for (int i = 0; i < Total; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {

IsTrade = True;

if(OrderType() == OP_BUY) {

//Close

//+------------------------------------------------------------------+

//| Signal Begin(Exit Buy) |

//+------------------------------------------------------------------+

if (CloseBuy1_1 >= CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+

//| Signal End(Exit Buy) |

//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

}

//Trailing stop

if(UseTrailingStop && TrailingStop > 0) {

if(Bid - OrderOpenPrice() > Point * TrailingStop) {

if(OrderStopLoss() < Bid - Point * TrailingStop) {

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

} else {

//Close

If anyone could help, it would be greatly appreciated.

 
Styex:
So I started writing a basic EA with one of those template generating EA builders. I seem to have gotten the premise of the EA template down, however I need a way to make the EA only enter one trade at max. Right now it keeps generating trades and causes the draw down to be rediculous. If anyone could help, it would be greatly appreciated.
if (OrdersTotal() == 0)

{

//Check position

bool IsTrade = False;

for (int i = 0; i < Total; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {

IsTrade = True;

if(OrderType() == OP_BUY) {

//Close

//+------------------------------------------------------------------+

//| Signal Begin(Exit Buy) |

//+------------------------------------------------------------------+

if (CloseBuy1_1 >= CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+

//| Signal End(Exit Buy) |

//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continue;

}

//Trailing stop

if(UseTrailingStop && TrailingStop > 0) {

if(Bid - OrderOpenPrice() > Point * TrailingStop) {

if(OrderStopLoss() < Bid - Point * TrailingStop) {

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

if (!EachTickMode) BarCount = Bars;

continue;

}

}

}

} else {

//Close

}
 

Thanks OnTheRoad

I found this EA, I don't understand some of it.

bool get_signal()

{

bool enable_trade = false;

int trend_up = 0;

int trend_down = 0;

int i;

ArrayInitialize( TradeSign, false );

if( Bars >= 100 ){

for( i = 0 ; i < DEF_MA_NUM ; i++ ){

Buf_MA[0][ i ] = calc_SMA( PERIOD_M30, MA_prm_1, i );

Buf_MA[1][ i ] = calc_SMA( PERIOD_M30, MA_prm_2, i );

Buf_MA[2][ i ] = calc_SMA( PERIOD_M30, MA_prm_3, i );

Buf_MA[3][ i ] = calc_SMA( PERIOD_M30, MA_prm_4, i );

Buf_MA[4][ i ] = calc_SMA( PERIOD_M30, MA_prm_5, i );

}

double vRSI = iRSI( Symbol(), PERIOD_M5, RSI_period5, PRICE_CLOSE, 0 );

double vRSI2 = iRSI( Symbol(), PERIOD_M1, RSI_period1, PRICE_CLOSE, 0 );

for( i = 0 ; i < DEF_MA_TYP ; i++ ){

if((Buf_MA[2] < Buf_MA[1]) && (Buf_MA[1] < Buf_MA[0])){

trend_up++;

}

}

if((trend_up > 3) && (vRSI <= RSI_lower) && (vRSI2 <= RSI_lower)){

TradeSign[SIG_Buy] = true;

enable_trade = true;

}

for( i = 0 ; i < DEF_MA_TYP ; i++ ){

if((Buf_MA[2] > Buf_MA[1]) && (Buf_MA[1] > Buf_MA[0])){

trend_down++;

}

}

if((trend_down > 3) && (vRSI >= RSI_upper) && (vRSI2 >= RSI_upper)){

TradeSign[SIG_Sell] = true;

enable_trade = true;

}

}

return(enable_trade);

}

double calc_SMA( int timeframe, int period, int offset )

{

double vMA = 0;

double sum=0;

int i;

for( i = 0 ; i < period ; i++ ){

sum += iClose( Symbol(), timeframe, i + offset );

}

vMA = sum / period;

return(vMA);

}

there is a part where "trendup>3", is this calculated from array? How does an array works, so can give "trendup>3" ? Is this for knowing average from a single line (that line is likely to go up or down)? I don't understand how it works.
Files:
 

How to reset experts when reached target profit? i'm using martingale strategy but it doesnt open lots in sequence...

example: lots 0.1, 0.2, 0.4, 0.8, 1.6

open lots: 0.1, 0.2, 0.4 -> take profit at lots 0.4 but the next lots is 0.8, 0.1, 0.2, 0.4...

anybody can help...???

int T=0;

for(int i=0;i<OrdersTotal();i++) {

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderComment()==Name_ExpertS)

{ T++;

if(OrderType()==OP_BUY) s=1;

if(OrderType()==OP_SELL) s=2;

Last=OrderOpenPrice();

}}

if (Lots<0.1) Lots=0.1;

for (int j=0;j<T;j++)

{

Lots=LotsUP[j];

}
 

High/Low with Criteria

I am trying to code an indicator that looks for specific things before stating that a candle is the true high or true low. This is basically the criteria (I attached a chart to help explain):

1. Look for Close that is lower then all 20 closes prior (second arrow is this point), then (2) 12 bars later the close must be higher then the 12 closes before (the third arrow). This up trend will continue until (3) there is a close that is lower then the 7 closes prior (the fourth arrow).

I have been trying to use the iLowest function without much success. I think that my best bet is to use an array but my knowledge of arrays is limited.

Any ideas or examples on how to use ArrayMinimum and ArrayMaximum? Or if there is a way to get the iLowest and iHighest to work?

Files: