Ask! - page 129

 
forexarchitect:
hello guys

I have a question here... how do I change the following;

extern double MaxLot = 1.50;

double max_lot = GetMaxLot(OP_BUY, OP_SELL);

if (max_lot >= MaxLot) lot = CalcHedgeLot(order_type);

(order_type)]: ", lot);

if (lot == -1) return (lot);

lot = NormalizeDouble(lot, LotPrec);

if (lot > MaxLot) lot = MaxLot;

if (lot < MinLot) lot = MinLot;

return (lot);

}

the above check for OP_BUY AND OP_SELL

question: how do I change it to any OP_BUY ORany OP_SELL

appreciate

You must modify the GetMaxLot() function code, or maybe you can use GetMaxLot(OP_BUY, OP_BUY); and GetMaxLot(OP_SELL, OP_SELL); (depends on the code - can do like that or not).

But I guess it worth to try

Goen

 
Goen:
Is this what you looking for ?

-----------

int bars_count=WindowBarsPerChart();

int bar=WindowFirstVisibleBar();

-----------

Goen

Thank you, Goen .

 
Goen:
You must modify the GetMaxLot() function code, or maybe you can use GetMaxLot(OP_BUY, OP_BUY); and GetMaxLot(OP_SELL, OP_SELL); (depends on the code - can do like that or not).

But I guess it worth to try

Goen

thanks for answering..

what do I need to change here? appreciate your help

double GetMaxLot(int type1, int type2)

{

double max_lot = 0.0;

int cnt = OrdersTotal();

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

{

if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderMagicNumber() != Magic) continue;

if (OrderType() != type1 && OrderType() != type2) continue;

if (max_lot == 0 || OrderLots() >= max_lot)

{

max_lot = OrderLots();

}

}

return (max_lot);

}

 

a bit in a loss here...

 

how to add alert to tis indicator?

i hv got an MA crossover indicator which work really well, but it doesn't hv the sound alert support tat make me miss a lot of trade, can u please teach me how to add alert to tis indicator as I know nothing about the meta code thing....thanks...

here is the code for the indicator together wif the indicator itself, thanks...

/*[[

Name := EMA Cross

Author := Hapsa

Link := http://www.metaquotes.net/

Separate Window := No

Separate Window := No

First Color := Red

First Draw Type := Symbol

First Symbol := 108

Use Second Data := Yes

Second Color := DarkOliveGreen

Second Draw Type := Symbol

Second Symbol := 108

]]*/

#property copyright "Hapsa"

#property link ""

extern int SlowPeriod=20;

extern int FastPeriod=5;

#property indicator_buffers 3

#property indicator_chart_window

#property indicator_color1 Red

#property indicator_color2 Green

double L20[];

double L50[];

double shift=0,val1=0,val2=0;

int init()

{

IndicatorBuffers(3);

SetIndexStyle(0,DRAW_ARROW);

SetIndexStyle(1,DRAW_ARROW);

SetIndexArrow(0, 108);

SetIndexArrow(1, 108);

SetIndexBuffer(0,L20);

SetIndexBuffer(1,L50);

//---- indicators

//----

return(0);

}

int start()

{

int counted_bars=IndicatorCounted();

//----

int i = Bars - counted_bars - 1;

while (i>=0)

{

val1=0;

val2=0;

double iMaSlowPrevious = iMA(NULL,0,SlowPeriod,0,MODE_EMA, PRICE_CLOSE, i-1);

double iMaSlowCurrent = iMA(NULL,0,SlowPeriod,0,MODE_EMA, PRICE_CLOSE, i);

double iMaFastPrevious = iMA(NULL,0,FastPeriod,0,MODE_EMA, PRICE_CLOSE, i-1);

double iMaFastCurrent = iMA(NULL,0,FastPeriod,0,MODE_EMA, PRICE_CLOSE, i);

if (iMaFastPreviousiMaSlowCurrent ) val1=High;

if (iMaFastPrevious>iMaSlowPrevious && iMaFastCurrent<iMaSlowCurrent ) val2=Low;

L20=val1+5*Point;

L50=val2-5*Point;

i--;

}

//----

return(0);

}

Files:
cross.mq4  2 kb
cross.ex4  3 kb
 
forexarchitect:
thanks for answering..

what do I need to change here? appreciate your help

double GetMaxLot(int type1, int type2)

{

double max_lot = 0.0;

int cnt = OrdersTotal();

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

{

if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

if (OrderSymbol() != Symbol()) continue;

if (OrderMagicNumber() != Magic) continue;

if (OrderType() != type1 && OrderType() != type2) continue;

if (max_lot == 0 || OrderLots() >= max_lot)

{

max_lot = OrderLots();

}

}

return (max_lot);

}

Yes, you can use GetMaxLot(OP_BUY,OP_BUY); to get the maxlot for buy open trade only, and GetMaxLot(OP_SELL,OP_SELL); to get the maxlot for sell open trade only.

You can make simplify this code "if (max_lot == 0 || OrderLots() >= max_lot)" with "if (OrderLots() > max_lot)"

Coz if max_lot = 0 automatically it will be lower than any lot of the open trades. And sign ">=" change with ">" coz if it have same value, no need to update max_lot with the same value, useless effort. It will update only if the new value greater than max_lot.

By changing that code, it could make your process faster.

Goen

 

stoploss issue

Hello,

I'm new to all this forex/metatrading but am trying to understand how it all works.

Now I am trying to write an EA and I'm afraid I'm missing something fundamental.

If, in my code, I replace

OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",MAGIC,0,Red);

with

OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Ask+Point*10,0,"",MAGIC,0,Red);

And test this new version out in the strategy tester, I get LESS orders. How can adding a stoploss diminish the number of order entries? I can imagine that the number rises in the case that adding a stop order causes orders to exit more early and thus new orders can be added more quickly, but LESS orders...?

Any idea?

Thanks

 
azertyken2:
Hello,

I'm new to all this forex/metatrading but am trying to understand how it all works.

Now I am trying to write an EA and I'm afraid I'm missing something fundamental.

If, in my code, I replace

OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",ordercount,0,Red);

with

OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Ask+Point*10,0,"",ordercount,0,Red);

And test this new version out in the strategy tester, I get LESS orders. How can adding a stoploss diminish the number of order entries? I can imagine that the number rises in the case that adding a stop order causes orders to exit more early and thus new orders can be added more quickly, but LESS orders...?

Any idea?

Thanks

10 pips may be too close to the broker-imposed stops limit (varies between brokers) - meaning if it's a minimium of 10 pips and price happens to swing 1 pip inside this as the order is being placed, the order will be rejected...

 

Omelette, you are right, increasing the stoploss fixed it, thanks! :-)

 
#property indicator_color1 Magenta

#property indicator_color2 Yellow

extern bool TrendDirectionUp=true;

string Color1;

string Color2;

int init() {

if(TrendDirectionUp==true)//Conditionj 1

{

Color1=Yellow;

Color2=CLR_NONE;

}

if(TrendDirectionUp==false)//Condition2

{

Color1=CLR_NONE;

Color2=Magenta;

}

SetIndexStyle(0,DRAW_ARROW,0,star_size,Color1);

SetIndexStyle(1,DRAW_ARROW,0,star_size,Color2);

SetIndexArrow(0,172);//333

SetIndexArrow(1,172);//334

SetIndexBuffer(0,b1);

SetIndexBuffer(1,b2);

return(0);

}

Right now, both Color(s) 1 & 2 show 'black' on the graph!!

Can any expert Guru help me solve this issue???

Thanks in Advance!

Reason: