MQL4 Learning - page 57

 

Need Help in Reversing Trades

I simply want to reverse buy to sell or sell to buy.

I basically tried OrderClose followed by Ticket=Ordersend

Tried it within the same and different curly braces.

It didnt work in Real live trading but worked just fine in Demo

I got an error message when tried to do it in Real Live.

I have been losing as my EA kept failing to reverse my position.

I tried another way as well.

I first close the open position, go to return(0) so tht the EA will start again and be ready to open the opposite position when it restart.

This still didnt work.

Is there anybody out there who knows how to solve this one?

Thanks in advance

 

where is wrong

Dear friends:

Could you please tell me where is wrong. i compile my first indicator. but it show nothing in the windonw.

Regards

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red

double CrossUp[];

double CrossDown[];

extern int FasterEMA = 10;

extern int SlowerEMA = 20;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0, DRAW_HISTOGRAM);

SetIndexBuffer(0, CrossUp);

SetIndexStyle(1, DRAW_HISTOGRAM);

SetIndexBuffer(1, CrossDown);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start() {

int limit, i;

double fasterEMAnow, slowerEMAnow;

int counted_bars=IndicatorCounted();

//---- check for possible errors

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

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

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

fasterEMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i);

slowerEMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i);

if (fasterEMAnow > slowerEMAnow) {

CrossUp = 1;

}

else if (fasterEMAnow < slowerEMAnow) {

CrossDown = -1;

}

}

return(0);

}

__________________

I need time ,I need money, I need more patien

 
ztdep:
Dear friends:

Could you please tell me where is wrong. i compile my first indicator. but it show nothing in the windonw.

Very weird, I can see the picture.

Files:
ind.jpg  67 kb
 

Help pls....I'm stuck

I simply want to reverse buy to sell or sell to buy.

I basically tried OrderClose followed by Ticket=Ordersend

OrderClose(...) //Close Current Order

Ticket=OrderSend(....)//To open new order

It didnt work in Real live trading but worked just fine in Demo

I got an error message when tried to do it in Real Live.

I have been losing as my EA kept failing to reverse my position.

I tried another way as well.

I first close the open position, go to return(0) so tht the EA will start again and be ready to open the opposite position when it restart.

This still didnt work.

Is there anybody out there who knows how to solve this one?

Thanks in advance

 

Clarification on the for loop

I'm not a trained programmer but have learned a few things from trial and error and have been able to create simple indicators for myself, but there are still lots of basic things that I'm unclear on.

The for loop is one of them. Is there a material difference between code that goes "for(i=0;i0;i--)"? When does one use one and not the other?

 

It's up to your logic. Sometimes you have to count from 1 to 10, sometimes opposite.

 

Ok here is a dumb noob question.........

How do you make an EA trade more often ???

When part of it determines the parameters for time needed before executing a trade? I am messing with a cpl EA's and it is one thing I am aware of how to do.

Thanks

 

Mql4 Coding Help

Hi guys

I have a problem with a code.

I would like to know how to perform a routine every time a candle exceed a MM, only 1 time, and the order can not be repeated until next crossing.

Code example:

int limit=1;

double MMA;

for (int shift=1; shift<=limit; shift++) {

MMA=iMA(NULL,timeFrame,FastEMA,0,MODE_EMA,PRICE_CLOSE,shift);

//---- sell conditions

if (MMA>Ask + 0.0010){

SellValue=1;

break;

}

//---- buy conditions

if (MMA<Ask - 0.0010){

BuyValue=1;

break;

}

}

The code above repeat the order for many times after take profit and before the next line cross.

I want the orders that it can open not exceed 1 order per cross. Or a limit variable (N orders).

So, If somebody could help, I would be grateful.

Thanks in advance.

 
int limit;

int start(){

double MMA0,MMA1;

MMA0=iMA(NULL,timeFrame,FastEMA,0,MODE_EMA,PRICE_CLOSE,0);

MMA1=iMA(NULL,timeFrame,FastEMA,0,MODE_EMA,PRICE_CLOSE,1);

//---- sell conditions

if (MMA1Ask + 0.0010){

SellValue=1;

break;

}

//---- buy conditions

else if (MMA1>Ask - 0.0010&&MMA0<Ask - 0.0010){

BuyValue=1;

break;

}

else {

SellValue=0;

BuyValue=0;

}

if(SellValue==0&&BuyValue==0)limit=0;

if(SellValue==1&&limit==0){

OrderSend(......;

limit=1;

}

if(BuyValue==1&&limit==0){

OrderSend(......;

limit=1;

}

}
 

Thanks, Roger!

I made the changes but still repeating orders before the next cross. Another sugestion?

cheers.

Reason: