How to code? - page 210

 

Lot's of thanks!!! cockeyedcowboy, that was really great!!

Now the error message is away!!

But the 2nd indicator isn't drawn and I don't no why

Buffer_Ma=iMAOnArray(Buffer_Mom,0,Periode_MA_Momentum,0,MODE_SMA,i);

 

You have a trouble with second buffer coz it have no data for calcs.

try to calc ALL elements in Buffer_Mom , then Buffer_Ma.

Example:

void start()

{

int counted_bars=IndicatorCounted();

int limit=Bars-counted_bars;

if(counted_bars>0) limit++;

for(int i=0; i<limit; i++)

{

Buffer_Mom=iMomentum(NULL,Timeframe_Momentum,Periode_Momentum,PRICE_CLOSE,i);

}

for( i=0; i<limit; i++)

{

Buffer_Ma=iMAOnArray(Buffer_Mom,0,Periode_MA_Momentum,0,MODE_SMA,i);

}

return(0);

}

Good luck.

 

Finding the OHLC of a specific bar

Can anyone tell me how I find out the closing price of a specific bar using MQL code? Can I reference a bar by it's time?

ie: closing_price_of_bar = Close("04:59:00 AM") ... if only it were that easy!

Thank you

 

hy folks !

ok i have another big problem...

how to code this condition :

enter long or short only first time

(so if i have many following long signal ea enter only at first time)

i'll pay everyone could help me on this

this is my simple code for buy condition:

//Buy

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

if(!IsTrade) {

//Check free margin

if (AccountFreeMargin() < (1000 * Lots)) {

Print("We have no money. Free Margin = ", AccountFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;

if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY order opened : ", OrderOpenPrice());

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

} else {

Print("Error opening BUY order : ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}
 
Sadly:
Can anyone tell me how I find out the closing price of a specific bar using MQL code? Can I reference a bar by it's time?

ie: closing_price_of_bar = Close("04:59:00 AM") ... if only it were that easy!

Thank you

Try this:

closing_price_of_bar = iClose(Symbol(),PERIOD_M1,iBarShift(Symbol(),PERIOD_M1,StrToTime("04:59"));

 

Buy or Sell

Hello everyone,

I have the Buy EA and Sell EA which are always open more than one position. I would like to get some help on how to change or modify the code that allow only 1(one) buy position and 1(one) sell position and in 1(one) account.

The SL and TP will be using Price Target, i.e. if the Buy price has reached the Price Target, it will close the position. The same with the Sell price.

I appriciate the help from the code-experts in this forum.

Thank you.

=s21=

Files:
opensell.mq4  2 kb
 

Buy and Sell

Oooops...

Here is the Buy EA.

Files:
openbuy.mq4  2 kb
 

Hi, if you need to have only one order opened, you can just add next condition: If (OrdersTotal()==0).

So you rules for BUY orders will be something like that:

if (Order == SIGNAL_BUY && (OrdersTotal==0) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))

[/CODE]

So you will not get second-third-... orders opened until you current order open.

dr.house7:
hy folks !

ok i have another big problem...

how to code this condition :

enter long or short only first time

(so if i have many following long signal ea enter only at first time)

i'll pay everyone could help me on this

this is my simple code for buy condition:

[CODE]

//Buy

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

if(!IsTrade) {

//Check free margin

if (AccountFreeMargin() < (1000 * Lots)) {

Print("We have no money. Free Margin = ", AccountFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;

if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY order opened : ", OrderOpenPrice());

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

} else {

Print("Error opening BUY order : ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}
 
Roger09:
Try this: closing_price_of_bar = iClose(Symbol(),PERIOD_M1,iBarShift(Symbol(),PERIOD_M1,StrToTime("04:59"));

Fab! I had to add 1 extra closing parenthesis in order to stop the interpreter from complaining of an error but it worked great.

Thank you, Roger09

 
Avalanche2k:
Hi, if you need to have only one order opened, you can just add next condition: If (OrdersTotal()==0).

So you rules for BUY orders will be something like that:

if (Order == SIGNAL_BUY && (OrdersTotal==0) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))

So you will not get second-third-... orders opened until you current order open.

thanks Avalanche,

but it's not a solution for me, because i have a TP, i don't wait until opposite condition

Others idea ? PM me i'll pay you