How to code? - page 62

 
Dan7974:
How can I code this?

If the market touches (X.XX50 or X.XX00)

then buy. How to identify last two numbers?

thanks.

This should do it:

if ( Point == 0.01 ) {xPrice = Close - MathMod(Close,0.50) ; }

else { xPrice = Close - ( MathMod(100*Close,0.50)*0.01 ) ; }

P1Buffer = xPrice + Point*50;

P2Buffer = xPrice ;

P3Buffer = xPrice - Point*50;

[/CODE]

When MathMod(Close,0.50) = 0 then the price ends in 00 or 50.

Here's my indicator to identify 00 lines:

[CODE]

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

//| _TRO_00_Lines |

//| |

//| |

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

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 LightGray

#property indicator_color2 LightGray

#property indicator_color3 LightGray

// indicators parameters

//---- buffers

double P1Buffer[];

double P2Buffer[];

double P3Buffer[];

double xPrice ;

int myStyle = 2 ;

int myWingDing = 250 ;

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

//| Custom indicator initialization function |

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

int init()

{

SetIndexBuffer(0, P1Buffer);

SetIndexBuffer(1, P2Buffer);

SetIndexBuffer(2, P3Buffer);

SetIndexArrow(0, myWingDing);

SetIndexArrow(1, myWingDing);

SetIndexArrow(2, myWingDing);

SetIndexStyle(0, DRAW_ARROW, myStyle, 1);

SetIndexStyle(1, DRAW_ARROW, myStyle, 1);

SetIndexStyle(2, DRAW_ARROW, myStyle, 1);

SetIndexEmptyValue(0,0);

SetIndexEmptyValue(1,0);

SetIndexEmptyValue(2,0);

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int i, dayi, 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--;

int limit = Bars - counted_bars;

//----

for(i = limit - 1; i >= 0; i--)

{

if ( Point == 0.01 ) {xPrice = Close - MathMod(Close,1.00) ; }

else { xPrice = Close - ( MathMod(100*Close,1.00)*0.01 ) ; }

P1Buffer = xPrice + Point*100;

P2Buffer = xPrice ;

P3Buffer = xPrice - Point*100;

} // for

return(0);

} // start
 

I need it for an EA though!

 

Coders please help

What to change in the code to move more up and down dots from candlesticks ?

Files:
diagram.gif  18 kb
 

Somebody might actually help you if you posted the code.

Lux

 

Here is the indicator

Indicator you can change the code to move up and down dots

Files:
 

proper use of Time[]

I'm a fair programmer but new to mql4. I'm working on a box trade (aka breakout trade) expert adviser. Essentially it should find the highest and lowest values for a specific time frame, and when a candle closes outside of that box I place a trade.

Essentially there are three states, I can start my EA in

1) after the close of the previous day, and before the box start time.

2) after the start of the box but before the end of the box.

3) after the end of the box.

What I find confusing is the Time[] array because the index keeps changing. Assume I enter at state 2. In the init function I was going to set a global variable giving the position of the start of the box. As quotes come in my start function is constantly called, and once the end of the box time was reached I would have the start and end positions. Of course that is not the case as the index on the Time array keeps rolling forward.

At best I can keep incrementing the position of the box start index, but that doesn't seem a very clean way to do things.

If you have a suggestion on how I should change my thinking away traditional c/c++ to mql4 I'd love to hear it.

Also when I'm done I would obviously benefit greatly from a code review by a more senior programmer. Would anyone like to volunteer for that?

Thanks for your time,

Markus

 
mweltin:
I'm a fair programmer but new to mql4. I'm working on a box trade (aka breakout trade) expert adviser. Essentially it should find the highest and lowest values for a specific time frame, and when a candle closes outside of that box I place a trade.

Essentially there are three states, I can start my EA in

1) after the close of the previous day, and before the box start time.

2) after the start of the box but before the end of the box.

3) after the end of the box.

What I find confusing is the Time[] array because the index keeps changing. Assume I enter at state 2. In the init function I was going to set a global variable giving the position of the start of the box. As quotes come in my start function is constantly called, and once the end of the box time was reached I would have the start and end positions. Of course that is not the case as the index on the Time array keeps rolling forward.

At best I can keep incrementing the position of the box start index, but that doesn't seem a very clean way to do things.

If you have a suggestion on how I should change my thinking away traditional c/c++ to mql4 I'd love to hear it.

Also when I'm done I would obviously benefit greatly from a code review by a more senior programmer. Would anyone like to volunteer for that?

Thanks for your time,

Markus

Hi. The Time[] function does not keep changing - only at the end of the current chart bar does it change. TimeCurrent() on the other hand returns a continuously changing value (albeit, with a 1 sec resolution).

You can get the exact time of any bar and timeframe using iTime() as well. There's quite a few ways to go about it...

 

open two orders on the same time (problem...)

Hi, i don't know why in some Opportunities the script open two orders on the same time.

someone can help me with this, please

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,EAName, MagicNo, 0,Green);

else

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,EAName, MagicNo, 0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

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

thank's

 

Help for code

Hi all,

I would like to code an indicator for compute the close value wich create a reversal of an indicator like HMA. For that i need to create a function for compute one value of HMA with a close values tab where i modify the current value in an dichotomy loop to find the value wich create the reversal.

Somebody can help me with my ComputeHull function ?

Here my code, without dichotomy reseach it is just a simple HMA indicator with computeHull function, the indicator is displayed but it is shifted down

Regards

//#property indicator_separate_window

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 Blue

//---- input parameters

extern int HullAntPeriod=12;

//---- buffers

double TempBuf1[];

double TempBuf2[];

double HullAntBuf[];

//Variable

int HalfHullAntPeriod;

int SqrtHullAntPeriod;

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

//| Specific functions |

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

double ComputeHull(int ActualBar)

{

double CloseTemp[];

double Temp[];

double Temp1, Temp2;

double result = -1;

int i;

//Copy Close Values to CloseTemp

ArrayResize(CloseTemp, HullAntPeriod+SqrtHullAntPeriod);

ArrayCopy(CloseTemp, Close, 0, ActualBar, HullAntPeriod+SqrtHullAntPeriod);

ArraySetAsSeries(CloseTemp, true);

ArrayResize(Temp, SqrtHullAntPeriod);

//HMA value computation

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

{

Temp1 = iMAOnArray(CloseTemp, 0, HalfHullAntPeriod, 0, MODE_LWMA, i);

Temp2 = iMAOnArray(CloseTemp, 0, HullAntPeriod, 0, MODE_LWMA, i);

Temp = 2*Temp1-Temp2;

}

ArraySetAsSeries(Temp, true);

result = iMAOnArray(Temp, 0, SqrtHullAntPeriod, 0, MODE_LWMA, 0);

//---- done

return(result);

}

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

//| Custom indicator initialization function |

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

int init()

{

//---- 1 additional buffers are used for temporary data.

IndicatorBuffers(3);

//---- drawing settings

SetIndexStyle(0,DRAW_LINE);

SetIndexStyle(1,DRAW_NONE);

//---- 2 indicator buffers mapping

SetIndexBuffer(0,HullAntBuf);

SetIndexBuffer(1,TempBuf1);

SetIndexBuffer(2,TempBuf2);

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("HULL ANTICIP("+HullAntPeriod+")");

SetIndexLabel(0,"HULL ANTICIPATION");

SetIndexLabel(1,NULL);

SetIndexLabel(2,NULL);

//---- Specific indicator initialization

HalfHullAntPeriod = MathFloor(HullAntPeriod/2);

SqrtHullAntPeriod = MathFloor(MathSqrt(HullAntPeriod));

//---- initialization done

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int bar, limit, i;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

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

HullAntBuf=ComputeHull(i);

//----

return(0);

}

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

 

Why doesn't this work?

int Highest;

double Place;

int Start()

{

Highest=iHighest(Symbol(),0,MODE_HIGH,1,0);Place=iHigh(Symbol(),0,Highest);

if(Gate==0){

if(iClose(Symbol(),0,0)>=Place){

OrderModify(ticket3,Ask,Ask-TrailingStop*Point-Spread,0,0,Green);

Gate=1;}

return(0);

}

I get errors. I can't make a simple trailing stop!!!!!!!

Reason: