MQL4 Learning - page 87

 

Move lines in an indicator

What commands can i use to move lines???

is it objectset()???

What command can i use to move the line to stoploss price(this price is set by me)??

Can someone translate this:

name of the stoploss line: stoploss1

name of the take profit line: takeprofit1

if stoploss1 stoploss price

move stoploss 1 to stoploss price

end if

if takeprofit1 takeprofit price

move take profit1 to takeprofit price

end if

I want to do those if to improve performance of the moving line.

Thanks everybody.

 

Not really too sure what you're trying to ask but thought you might find the code in this indicator I wrote some time ago of use.

Good luck

Lux

Files:
 
luxinterior:
Not really too sure what you're trying to ask but thought you might find the code in this indicator I wrote some time ago of use.

Good luck

Lux

The thing is i have an indicator that plots 2 lines that gives sound alarm. So i use them as take profit and stoploss alarm.

So what i want is the same indicator to moves the lines to my profit and stoploss prices. Instead of my moving the lines manualy.

The name of the lines are stoploss1 and takeprofit1.

Thanks.

 

Position of bar

Apologies if this question has been already answered, I am very new to MQL and I was not able to find it in search.

Does anyone know how to get the position of a bar in an EA. For example, if I have the highest price from a given bar, and then I want to find the lowest price from that highs bars position.

double highestPrice = High;

int highestBarPosition = someFunction();

double lowestPrice = Low;

what should I put in someFunction() please.

Many thanks J

 

You've actually already answered your own question.

The iHighest function returns the index of the highest bar during the specified period so just store that in an integer and use it in your iLowest function.

Good luck

Lux

 

Strange 130 Error

I am getting a OrderModify error 130 for my EA. The weird part is that the EA functions normally if I set the StopLoss and TargetProfit to numbers like 1500 and 1900. It is calculating it correcting, making the the SL and TP 1500 and 1900 pips away respectively, however, I want the SL and TP to be 19 and 15 pips away. I've also tried 190 and 150 and that kicked out the 130 error too, so I'm wondering why I wouldn't be able to send an ordermodify unless the sl and tp were set so far away from the ticket open.

Also I use OrderSend and then immediately follow it with an OrderModify because my broker does not allow the OrderSend function to use a stoploss or tp when sent.

Any ideas on what could be the cause? or where I can look in my code for possible problems?

-mercswish

 

Move lines in an indicator

--------------------------------------------------------------------------------

What commands can i use to move lines???

is it objectset()???

What command can i use to move the line to stoploss price(this price is set by me)??

Can someone translate this:

name of the stoploss line: stoploss1

name of the take profit line: takeprofit1

if stoploss1 stoploss price

move stoploss 1 to stoploss price

end if

if takeprofit1 takeprofit price

move take profit1 to takeprofit price

end if

I want to do those if to improve performance of the moving line.

Thanks everybody.

 

Quote:

Originally Posted by luxinterior

Not really too sure what you're trying to ask but thought you might find the code in this indicator I wrote some time ago of use.

Good luck

Lux

The thing is i have an indicator that plots 2 lines that gives sound alarm. So i use them as take profit and stoploss alarm.

So what i want is the same indicator to moves the lines to my takeprofit and stoploss prices. Instead of me moving the lines manualy.

The name of the lines are stoploss1 and takeprofit1.

Thanks.

 
raul_jr00:
Move lines in an indicator

What commands can i use to move lines???

is it objectset()???

Thanks everybody.

Look at ObjectMove() function.

 

Indicator drawing problem

I have a problem with my simple indicator .

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 DodgerBlue

#property indicator_color2 Orange

extern int EMA_Period = 12;

extern int shift = 1;

double EMA[];

double Dynamic[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexBuffer(0,EMA);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(1,Dynamic);

SetIndexStyle(1,DRAW_LINE);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int i, limit;

int counted_bars = IndicatorCounted();

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

if (counted_bars > 0) counted_bars--;

limit=Bars-counted_bars;

//----

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

EMA = iMA(NULL,0,EMA_Period,shift,MODE_EMA,PRICE_CLOSE,i);

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

Dynamic = EMA+((Close-EMA)/(Close/EMA));

//----

return(0);

}

It draws the EMA line OK, but draws only three bars of the dynamic line history.

I'm sure I've overlooked something silly, but I'm at a loss.

Any help would be appreciated.

-------------------

OK. Sorted.

Should read -

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

Dynamic = EMA+((Close-EMA)/(Close/EMA));

Reason: