MQL4 Learning - page 72

 

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];

}
 

variable no defined ? help

Hi everyone

Im new here and totally rookie in programming

Im trying to compile very simple indicator which should show difference between open and close bar, but i have problem even with that,

the code looks like below:

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Aqua

double RozBufer[];

int init()

{

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,RozBuffer);

IndicatorShortName(Roznica);

return(0);

}

int deinit()

{

return(0);

}

int start()

{

int counted_bars=IndicatorCounted();

if (counted_bars < 0) return(-1);

if (counted_bars > 0) counted_bars--;

for (int i = Bars - counted_bars - 1; i >=0; i--) RozBuffer = Open - Close;

return(0);

Indicators name is Roznica what mean difference in Polish,

Compiler says:

'RozBuffer" - variable not defined

'Roznica' - variable not defined

I guess that its trivial question, but where is the problem in my code?

Thanks in advance for reply

 

Try

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Aqua

double RozBuffer[];

int init()

{

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,RozBuffer);

IndicatorShortName("Roznica");

return(0);

}

int deinit()

{

return(0);

}

int start()

{

int counted_bars=IndicatorCounted();

if (counted_bars < 0) return(-1);

if (counted_bars > 0) counted_bars--;

for (int i = Bars - counted_bars - 1; i >=0; i--) RozBuffer = Open - Close;

return(0);

}
 

Try

[CODE...

QUOTE]

It works , thanks a lot !

 
Kalenzo:
[CUT] This post was deprecated.

I don't quite get it... but why the post was deprecated?

 

closing orders at specific times in profit

I am trying to close trades after a certain number of bars... My problem is that the programming (period x 60 x (bars)) ....is allowing the closing of the orders immediately after the trade is opening.

Anyone have any idea why this would be happening? My order select function is programmed correctly I believe.

if(Period () * 60 * 3 > TimeCurrent()- OrderOpenTime() ) {

CloseOrder(OP_SELL); return(0);

} }

}

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

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

 

First of all:

if(Period () * 60 * 3 < TimeCurrent()- OrderOpenTime() ) {

and then, when you close orders, it's better to calculate from the end:

for(cnt=total-1;cnt>=0;cnt--)

 

Display comments in Indicators

Hello, I have an indicator that I'm making some modifications to and normally I would use Comment, Print or Screenmessage in an EA to display/Show a value on screen that I want to check to make sure calculations are correct but what can I use in an Indicator? I think I would need to create a type of Object but is there an easy code line I can add?

Thank you

 
Comment("my value is " + value);
 
Enforcer:
Comment("my value is " + value);

Ok, cool, so I can use the same command and in an EA

I need to space down "/n" correct? because the comment will overwrite the IndicatorShortName correct?