Coding help - page 223

 
daniel1983:
Thank you Mladen, i did the changes, the indicator looks like this, but still don't do anything in chart...

//------------------------------------------------------------------

#property copyright "www.forex-tsd.com"

#property link "www.forex-tsd.com"

//------------------------------------------------------------------

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

//| Custom indicator initialization function |

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

int init()

{

//----

return(0);

}

int deinit() {

Comment("");

ObjectDelete("KeyLine");

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

double number = (iOpen(NULL,PERIOD_D1,1)+iHigh(NULL,PERIOD_D1,1)+iLow(NULL,PERIOD_D1,1))/3;

Comment("Key Line: ",number);

ObjectDelete("KeyLine");

ObjectCreate("KeyLine", OBJ_HLINE,1, CurTime(),number);

ObjectSet("KeyLine",OBJPROP_COLOR,Orange);

ObjectSet("KeyLine",OBJPROP_STYLE,STYLE_SOLID);

ObjectsRedraw();

return(0);

}

What i am doing wrong now?

Thank you

Do it like this :

#property indicator_chart_window

//------------------------------------------------------------------

//

//------------------------------------------------------------------

int init() { return(0); }

int deinit()

{

Comment("");ObjectDelete("KeyLine");

return(0);

}

int start()

{

double number = (iOpen(NULL,PERIOD_D1,1)+iHigh(NULL,PERIOD_D1,1)+iLow(NULL,PERIOD_D1,1))/3;

Comment("Key Line: ",number);

ObjectDelete("KeyLine");

ObjectCreate("KeyLine", OBJ_HLINE,0, CurTime(),number);

ObjectSet("KeyLine",OBJPROP_COLOR,Orange);

ObjectSet("KeyLine",OBJPROP_STYLE,STYLE_SOLID);

return(0);

}
Files:
test.mq4  1 kb
 

Ok Mladen, thank you very much for you'r time, i will see what i can do, as there is some problem with the code of the math, as it still dont take the prices for the first candle to do the math equation. thank you again, will have a look at this during weekend.

Daniel1983

 
daniel1983:
Ok Mladen, thank you very much for you'r time, i will see what i can do, as there is some problem with the code of the math, as it still dont take the prices for the first candle to do the math equation. thank you again, will have a look at this during weekend. Daniel1983

Daniel1983

To translate that mql code to everyday language : number is equal to previous day open + previous day high + previous day low divided by 3. That way the values from different time frames are not mixed and there will be no change in values untill the current day changes

 

Hi Mladen,

I have downloaded Support Resistance indicator fromThread: How to use Support and Resistance Effectively But when I put it on a chart appears the support and resistance. But if I delete the indicator the support and resistance remains in the chart. Do you know how I can do to delete it completely?

Many thanks in advance!!

Best regards, MGM

 
MGM:
Hi Mladen,

I have downloaded Support Resistance indicator fromThread: How to use Support and Resistance Effectively

But when I put it on a chart appears the support and resistance. But if I delete the indicator the support and resistance remains in the chart. Do you know how I can do to delete it completely?

Many thanks in advance!!

Best regards, MGM

MGM

Which indicator exactly (which post No)?

 
mladen:
MGM Which indicator exactly (which post No)?

Sorry, Maladen I have downloaded it fromThread:How to use Support and Resistance Effectivelypage 44. And now its working well. Excuse me for the question.

Many thanks anyway!

MGM

 

Dear Mladen

I want to write an EA to open two orders, the first one sell or buy and the second one pending.

If first order hit the target, EA remove the pending and repeat the cycle.

I have created a preliminary structure. Could you kindly check it.

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

//| Main Function |

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

int start()

{

if (Counter() == 0)

{

Long ();

Short();

}

if (Counter() == 1)

{

PendingRemover();

}

return(0);

}

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

//| Complementary Functions |

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

//---- Order Counter

int Counter()

{

int Pending = 0;

int Trading = 0;

for (int i=0; i<OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == False) break;

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

{

if(OrderType() == Buy or Sell Order) Trading++;

if(OrderType() == Pending Order) Pending++;

}

}

return(Trading+Pending);

}

//---- Pending Remover

void PendingRemover()

{

for (int i=0; i<OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == False) break;

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == Pending Order);

OrderDelete(Pending);

}

}

//---- Long Position Handler

void Long()

{

int Ticket1;

int Ticket2;

if (X > 0)

{

Ticket1 = OrderSend(Trading);

Ticket2 = OrderSend(Pending);

}

}

//---- Short Position Handler

void Short()

{

int Ticket1;

int Ticket2;

if (X < 0)

{

Ticket1 = OrderSend(Trading);

Ticket2 = OrderSend(Pending);

}

}

Best,

 
-IXI-:
Dear Mladen

I want to write an EA to open two orders, the first one sell or buy and the second one pending.

If first order hit the target, EA remove the pending and repeat the cycle.

I have created a preliminary structure. Could you kindly check it.

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

//| Main Function |

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

int start()

{

if (Counter() == 0)

{

Long ();

Short();

}

if (Counter() == 1)

{

PendingRemover();

}

return(0);

}

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

//| Complementary Functions |

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

//---- Order Counter

int Counter()

{

int Pending = 0;

int Trading = 0;

for (int i=0; i<OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == False) break;

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

{

if(OrderType() == Buy or Sell Order) Trading++;

if(OrderType() == Pending Order) Pending++;

}

}

return(Trading+Pending);

}

//---- Pending Remover

void PendingRemover()

{

for (int i=0; i<OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == False) break;

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == Pending Order);

OrderDelete(Pending);

}

}

//---- Long Position Handler

void Long()

{

int Ticket1;

int Ticket2;

if (X > 0)

{

Ticket1 = OrderSend(Trading);

Ticket2 = OrderSend(Pending);

}

}

//---- Short Position Handler

void Short()

{

int Ticket1;

int Ticket2;

if (X < 0)

{

Ticket1 = OrderSend(Trading);

Ticket2 = OrderSend(Pending);

}

}

Best,

-IXI-

As far as I see it all is OK

 

Dear Mladen

Thank you very much.

I add some codes to make a simple EA.

It is strange that the EA opens buy and sell orders at the same time! Any idea?

//---- Long Position Handler

void Long()

{

int Ticket1;

int Ticket2;

if (iMA(Symbol(),Period(),10,0,1,0,1)

> iMA(Symbol(),Period(),10,0,1,0,2))

{

Ticket1 = OrderSend(Symbol(),OP_BUY ,...);

Ticket2 = OrderSend(Symbol(),OP_SELLSTOP,...);

}

}

//---- Short Position Handler

void Short()

{

int Ticket1;

int Ticket2;

if (iMA(Symbol(),Period(),10,0,1,0,1)

< iMA(Symbol(),Period(),10,0,1,0,2))

{

Ticket1 = OrderSend(Symbol(),OP_SELL ,...);

Ticket2 = OrderSend(Symbol(),OP_BUYSTOP,...);

}

}

Best.

 

Hello,Mladen.Whether probably to add in Momentum-Atr the ema+ filter indicator? But only that EMA was too normalized? It will be probably better to add other average, SMA maybe.Frankly, I don't know what to make. I want to receive in this indicator a cross with MA.It is necessary in order that momentum crosses zero-entry. Crosses a MA -exit

Please help.

Thank you.

Reason: