How to code? - page 318

 
mladen:
dasio It is looping through all the hours of the current day already. I placed the iClose() and iOpen() just as an example of a call from a time frame different than 1 hour. If you want to access different day than the current then replace the "0" on the datetime startTime=iTime(NULL,PERIOD_D1,0);part with any day you wish the data collected for

Thank you.

Maybe i have to study.

I don't understan how i can do separate calculate for 00:00 candle - 01:00 - 02:00 etc.

Sorry

 

Signal Problems

Mladen

Thank you, I ve looked closely....Im still experimenting the code.I will be notifying when through.

 

dasio

This part

int i=iBarShift(NULL,PERIOD_H1,startTime);

sets the i to the shift of the first hourly candle in the specified day (that is why datetime startTime=iTime(NULL,PERIOD_D1,0);was added - to find out the starting time of the day) after that it will loop through each 1 hour bar values till the day remains the same (for example on Friday it will not loop 24 times but 22 or 23 depending on your broker)

If you need to feel some array that has to be done a bit differently Ilet me now uf that was your idea)

dasio:
Thank you.

Maybe i have to study.

I don't understan how i can do separate calculate for 00:00 candle - 01:00 - 02:00 etc.

Sorry
 

How to make an Expert stops ?

Hello coders,

How to code some extra coding lines so that an Experts stops after a winning trade?

Pips are in the bag, then make the Expert stops...

Thanks a lots

Tomcat98

 
mladen:
dasio

This part

int i=iBarShift(NULL,PERIOD_H1,startTime);

sets the i to the shift of the first hourly candle in the specified day (that is why datetime startTime=iTime(NULL,PERIOD_D1,0);was added - to find out the starting time of the day) after that it will loop through each 1 hour bar values till the day remains the same (for example on Friday it will not loop 24 times but 22 or 23 depending on your broker)

If you need to feel some array that has to be done a bit differently Ilet me now uf that was your idea)

Thank you,

i'm understanding little more.

However i need it for example.

I must associate to variables something like this:

(candle 00:00 ; Variable = Close+High

candle 01:00 ; Variable1 = Close+Open

candle 02:00 ; Variable2 = high+low;

And so on for all the hour candle of the day.

So the variables are defined how double.

After it i have to do some math calculation with the variable and associate the result to a buffer (it is not a problem )

The issue for me is the variable association....

 

Another problem...I'm trying to study the programming and sometimes (onlysimetimes?eheh) i need help.

If i have an ea that place two pending order how can i code if i want that when one pending order is opened the other pending order must be delete?

Thank you

 

You have to use 2 loops :

First you have to count orders to find out if some of the pending orders has become a "regular" order (so you have to do a regular count of orders that have types OP_BUY or OP_SELL and, if you wish, to count the rest of orders too).

If there are opened orders, then you have to loop once again and delete all orders that are not either OP_BUY or OP_SELL type orders.

Code could be something like this :

int opened =0;

int pending =0;

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

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol() !=Symbol()) continue;

if(OrderMagicNumber()!=MagicNumber) continue;

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

opened++;

else pending++;

}

if (opened>0 && pending>0)

{

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

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol() !=Symbol()) continue;

if(OrderMagicNumber()!=MagicNumber) continue;

if(OrderType()!=OP_BUY && OrderType()!=OP_SELL)

OrderDelete(OrderTicket());

}

}
dasio:
Another problem...I'm trying to study the programming and sometimes (onlysimetimes?eheh) i need help.

If i have an ea that place two pending order how can i code if i want that when one pending order is opened the other pending order must be delete?

Thank you
 

Close all sell or all buy position only ( when hit target profit)

Hi All .. im new to FX and EA. I have tried to find an EA for "close all sell" or "close all buy" when hit target but couldn't find. I found only close all sell or all buy without the "HIT TARGET or PROFIT". Is it possible if someone could help me to create 1 EA with below features:-

1)Close all sell if profit hit X target.

2)Close all buy if profit hit X target.

3)Include trailing stop (If possible, if cannot no problem)

4) Do not close if equity or margin level less than X % if close all buy or close all sell (If possible, if cannot no problem)

Note:

If no 4 is quite difficult to code so just no 1,2 and 3 in one EA.

If no 4 and 3 difficult so just no 1 and 2 in one EA

If still difficult just create no 1 and 2 separately.

It would be really grateful if someone could provide me with the above.

Thanks in advance

 
pipsmonitor:
Hi All .. im new to FX and EA. I have tried to find an EA for "close all sell" or "close all buy" when hit target but couldn't find. I found only close all sell or all buy without the "HIT TARGET or PROFIT". Is it possible if someone could help me to create 1 EA with below features:-

1)Close all sell if profit hit X target.

2)Close all buy if profit hit X target.

3)Include trailing stop (If possible, if cannot no problem)

4) Do not close if equity or margin level less than X % if close all buy or close all sell (If possible, if cannot no problem)

Note:

If no 4 is quite difficult to code so just no 1,2 and 3 in one EA.

If no 4 and 3 difficult so just no 1 and 2 in one EA

If still difficult just create no 1 and 2 separately.

It would be really grateful if someone could provide me with the above.

Thanks in advance

Hi Pipsmonitor,

Maybe found something here on this page https://www.mql5.com/en/forum/181179 also did a goggle search on the forum header bar used closed on profit found some there you may be able to use, also might try a search for trailing Eas, know of a Ema trailing and BBand stop trailing Ea.

 

Hi,

i'm try to merge this two code but i have trouble with it.

I need that when one pending order is filled the other must be cancelled.

Thank you for your disponibility

int opened =0;

int pending =0;

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

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol() !=Symbol()) continue;

if(OrderMagicNumber()!=Magic) continue;

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

opened++;

else pending++;

}

if (opened>0 && pending>0)

{

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

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol() !=Symbol()) continue;

if(OrderMagicNumber()!=Magic) continue;

if(OrderType()!=OP_BUY && OrderType()!=OP_SELL)

OrderDelete(OrderTicket());

}

} [/PHP]

[PHP] extern int Magic = 68415;

extern int Orario_Inizio = 0;

extern int Orario_Fine = 6;

extern int Buffer = 0;

extern double Lotti = 0.1;

extern int TakeProfit = 10;

extern int StopLoss = 50;

double Massimo;

double Minimo;

int BarCount;

int BarStart;

int BarShift;

double MinLot;

double LotSize;

int i;

int ticket;

string Status;

string BuyStatus1;

string SellStatus1;

double Range;

string CommentoRange;

double pipMultiplier = 1;

int init()

{

}

int start()

{

if (Digits==3 || Digits==5)

{pipMultiplier = 10;}

else {pipMultiplier = 1; }

double TakeProfit1 = TakeProfit*Point*pipMultiplier;

double StopLoss1 = StopLoss*Point*pipMultiplier;

double Buffer1 = Buffer*Point*pipMultiplier;

double StopLossPrice = NormalizeDouble(StopLoss1,Digits);

double TakeProfitPrice = NormalizeDouble(TakeProfit1,Digits);

double BufferPrice = NormalizeDouble(Buffer1,Digits);

//CALCOLA LE BARRE DEL RANGE

if(Orario_Inizio>Orario_Fine)

{

BarCount=24+Orario_Fine-Orario_Inizio;

}

if(Orario_Inizio<Orario_Fine)

{

BarCount=Orario_Fine-Orario_Inizio;

}

//CALCOLA IL MASSIMO E IL MINIMO DEL RANGE

if(Hour()>=Orario_Fine)

{

BarStart=Hour()-Orario_Fine;

BarShift=BarStart+BarCount;

Minimo=iLow(NULL,PERIOD_H1,BarStart);

Massimo=0;

for(i=BarStart;i<=BarShift;i++)

{

Massimo=MathMax(Massimo,iHigh(NULL,PERIOD_H1,i));

Minimo=MathMin(Minimo,iLow(NULL,PERIOD_H1,i));

Range=(Massimo-Minimo)/Point;

}

}

else

{

Massimo=0;

Minimo=0;

return(0);

}

//CONTROLLA SE E' L'ORARIO PER POTER TRADARE

if(Hour()==Orario_Fine && OrdersTotal()<2)

{

//CONTROLLA SE IL MASSIMO E' STATO ROTTO. CONDIZIONE BUY

double OpenPriceBuy = NormalizeDouble((Massimo+BufferPrice),Digits);

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lotti,OpenPriceBuy,0,OpenPriceBuy-StopLossPrice,OpenPriceBuy+TakeProfitPrice,NULL,Magic,0,Blue);

//CONTROLLA SE IL MINIMO E' STATO ROTTO. CONDIZIONE SELL

double OpenPriceSell = NormalizeDouble((Minimo-BufferPrice),Digits);

ticket=OrderSend(Symbol(),OP_SELLSTOP,Lotti,OpenPriceSell,0,OpenPriceSell+StopLossPrice,OpenPriceSell-TakeProfitPrice,NULL,Magic,0,Red);

if (ticket != -1)

return(0);

}

}
Reason: