How to code? - page 153

 
Roger09:
To chiwing

Try this:

#property copyright "Copyright ?2004, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net/"

#property show_inputs

bool result;

extern double OverSymbolDel = 1; //0:FASLE ; 1: TRUE

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

//| script "delete pending order" |

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

int start()

{

for (int number=OrdersTotal()-1; number >= 0; number--)

{

OrderSelect(number,SELECT_BY_POS,MODE_TRADES);

if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) continue;

if (OverSymbolDel ==0&& Symbol()==OrderSymbol() ) delPending();

if (OverSymbolDel ==1) delPending();

}

}

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

void delPending()

{

OrderPrint();

int ticket =OrderTicket();

result=OrderDelete(ticket);

if (!result) Print("Error when delete Order ", GetLastError() );

}

if ( (OverSymbolDel ==0 ) && (Symbol()==OrderSymbol() ) delPending();

change to

if ( (OverSymbolDel ==0 ) && (Symbol()==OrderSymbol() )) delPending();

 

GetClientRect???

How should I do though I want to acquire the client coordinates of the chart?

I want to know lower right coordinates without using OBJPROP_CORNER.

My best regards.

 

Eu h1 ea

please help me to modify the best one

 

Help with Logic

Hi all,

I would like a little help with some code logic. I am trying to build an EA of a system I am looking at but am a little puzzled how to write the logic for Buy and Sell Signals. Here is the Pseudo logic of what I want to turn into MQL:

BUY LOGIC:

If (MA_1 > MA_2) and (Previous(MA_1 < MA_2)) // A moving average cross mean we have a "GET READY" signal

// Once we have a "GET READY" signal the following conditions need to be true

// in order for the system to create a "BUY_SIGNAL".

// Note: the following conditions do not necessarily have to become true on the exact same bar,

but need to trigger true within + or - 2 bars of the "GET READY" bar.

( CLOSE > MA3 ) // Price closes above a MA

( CCI Crosses above the ZERO line ) // CCI crosses up above zero

( Fast Stochastic crosses above Slow Stochastic ) // Stochastic triggers to the up side

The Sell Logic is just the opposite of the buy logic.

I don't need full EA code just the logic converted to MQL 'IF' and 'LOOP' statements to workout the signal. I think I can figure out the OpenOrder code etc... from many examples already in this thread.

Any help anyone can give would be much appreciated.

Thanks,

Moxy

 

You're best bet is to look in the metaeditor help file.

Take a look at functions like iMa, iStochastic and iCCI. They have examples and if you combine those with information you'll get from looking at the code in any EA you'll find it easy.

Good luck

Lux

 
luxinterior:
You're best bet is to look in the metaeditor help file.

Take a look at functions like iMa, iStochastic and iCCI. They have examples and if you combine those with information you'll get from looking at the code in any EA you'll find it easy.

Good luck

Lux

Hi Lux,

Thanks for the reply. I can workout out the individual iMA statements etc... the problem i have is how to reference the different time bars once a signal is triggered. For example... If I have a GET READY signal I need to look at the 2 bars before and 2 bars after (5 bars in total) for the other indicators to confirm I have a BUY SIGNAL on the open of the next bar. Not sure if I am making sense !!

I guess it is... how would i structure the necessary FOR loops etc.. when I need to reference bars both before and after the bar being processed.

Regards,

Moxy

 
Moxy:
Hi Lux,

Thanks for the reply. I can workout out the individual iMA statements etc... the problem i have is how to reference the different time bars once a signal is triggered. For example... If I have a GET READY signal I need to look at the 2 bars before and 2 bars after (5 bars in total) for the other indicators to confirm I have a BUY SIGNAL on the open of the next bar. Not sure if I am making sense !!

I guess it is... how would i structure the necessary FOR loops etc.. when I need to reference bars both before and after the bar being processed.

Regards,

Moxy

You do this by using the shift variable in iMA(). You can also do this with Open, High, Low, Close values i.e. Close[3] which is 3 bars away from current bar.

 

Moving average of Moves

Ok need a bit of help with code, I am looking to determine a set of average moves around a MA, so from the oldest BAR, I look for the moves above and below, put them into an array then average that array.

here is the code I am starting with, looking for a bit of assistance to get it done.

double AverageMove()

{

int cbars = iBars(Symbol(),EntryTimeFrame);

int counted_bars = 0,RangeCounter=0,ndx=0,iLimit=0;

double retval,averagemove,pHValue,pLValue,MAvalue,RangeValue[],EntryPoint,cHigh,cLow;

bool reset,TradeShort,TradeLong;

iLimit=Bars-1;

if(Symbol() != "AUDNZD") return(0);

for(ndx=0; ndx<iLimit; ndx++)

{

MAvalue = iMA(Symbol(),EntryTimeFrame,EntryMAInterval,0,MovingAverageType,PRICE_MEDIAN,ndx);

pHValue = High[ndx];

pLValue = Low[ndx];

if(MAvalue pLValue)

{

if(Symbol() =="AUDNZD") Print("MAValue="+MAvalue+" pHValue="+pHValue+" plValue="+pLValue);

reset = true;

if(EntryPoint > 0 && cHigh > 0)

{

RangeCounter++;

RangeValue[RangeCounter]=cHigh - EntryPoint;

}

if(EntryPoint > 0 && cLow > 0)

{

RangeCounter++;

RangeValue[RangeCounter]=EntryPoint - cLow;

}

EntryPoint = MAvalue;

}

if(pHValue < MAvalue && reset) TradeShort = true;

if(pLValue > MAvalue && reset) TradeLong = true;

if(TradeLong)

{

reset = false;

cHigh = pHValue;

}

if(TradeShort)

{

reset = False;

cLow = pLValue;

}

}

ArraySetAsSeries(RangeValue,true);

retval=iMAOnArray(RangeValue,RangeCounter,13,1,PRICE_MEDIAN,0);

Print("Average Move"+retval);

}

 

I would like to know the client area at the chart.

Hellow,

I would like to know the client area at the chart.

Please advise me.

Assuming that the point of the left top corner is (0,0), please let me know the coordinats of the the right bottom.

In this case, ObjectSet("",OBJPROP_CORNER,3)shoud not be used.

Many thans and best regards,

 

Moxy,

If I understand you correctly then you will have to code this line for line in an EA.

example

MA1, index-1 before

MA1, index now

MA1, index+1 after

you have the basic there

Reason: