Coding help - page 245

 
mladen:
macerina

The first part only (the rest is just a variation of that) :

if ema(7) < ema(21) and previous ema(7) < previous ema(21) then if ema(of rsi(14),9) < rsi(14) signal for buy

you can say it this way too :

if macd(7,12) < and previous macd(7,12) < 0 then if ema(of rsi(14),9) < rsi(14) signal for buy

Thanks for the reply mladen is it possible to code a mt4 indicator with this criteria

Thanks in advance

 
macerina:
Thanks for the reply mladen is it possible to code a mt4 indicator with this criteria Thanks in advance

macerina

That is a simple macd + rsi system. I believe that there is such already. If there is no such, it is easy to make an indicator and then it will be made

 
mladen:
Please post the part of the code where you are trying to achieve what you have described here : https://www.mql5.com/en/forum/174385/page162 (not the 3 take profits placing on orders and 3 trailing stops managing, but the part that is trying to do exactly what you have described) and then, maybe someone can help you with your coding.

//count open buy orders.

iOpenOrders_Buy = CntOrd(iOrderType_Buy,MagicNumber,Symbol());

//count open sell orders.

iOpenOrders_Sell = CntOrd(iOrderType_Sell,MagicNumber,Symbol());

if (iOpenOrders_Buy==3 || iOpenOrders_Sell==3)

{

if(TrailingStop>0 && TrailingStart > 0) TrailOrder (TrailingStart, TrailingStop);

}

if (iOpenOrders_Buy==1 || iOpenOrders_Sell==1)

{

if(TrailingStop_2>0 && TrailingStart_2 > 0) TrailOrder_3 (TrailingStart_2, TrailingStop_2);

}

//////////////////////////////////////////////////////////////////////////////////////////////

This was the part where the EA is looking for the number of Open orders for the attached pair.

If it finds 3 orders, it'll follow the usual Trailing Stop function. And if it finds there is only one trade running, then it'll follow the Second Trailing Stop function.

This is running 'OK' for a single pair but when I attach this EA to multiple charts(Pairs), it doesn't work as it fetches all the open orders via the 'OrdersTotal()' function.

One problem immediately comes to mind : how do you know that there were 3 orders and then only 1 was left (there is not a single line of code in that EA that is trying to find that out)

//End - Close open sell positions------------------------------------------

double OpenPrice=Ask;

int count=3;

if (count==3)

{

BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_1>0) //Checking if the order was opened or not

{

sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + " Buy order 1 sent successfully. Ticket=" + BuyOrder_1;

count = count - 1;

//////////////////////////////////////////////////////////////

Thus count is decreasing and opening orders till count=1. So 3 orders are opening as count=3 initially.

 
Oridroo:
//count open buy orders.

iOpenOrders_Buy = CntOrd(iOrderType_Buy,MagicNumber,Symbol());

//count open sell orders.

iOpenOrders_Sell = CntOrd(iOrderType_Sell,MagicNumber,Symbol());

if (iOpenOrders_Buy==3 || iOpenOrders_Sell==3)

{

if(TrailingStop>0 && TrailingStart > 0) TrailOrder (TrailingStart, TrailingStop);

}

if (iOpenOrders_Buy==1 || iOpenOrders_Sell==1)

{

if(TrailingStop_2>0 && TrailingStart_2 > 0) TrailOrder_3 (TrailingStart_2, TrailingStop_2);

}

//////////////////////////////////////////////////////////////////////////////////////////////

This was the part where the EA is looking for the number of Open orders for the attached pair.

If it finds 3 orders, it'll follow the usual Trailing Stop function. And if it finds there is only one trade running, then it'll follow the Second Trailing Stop function.

This is running 'OK' for a single pair but when I attach this EA to multiple charts(Pairs), it doesn't work as it fetches all the open orders via the 'OrdersTotal()' function.

//End - Close open sell positions------------------------------------------

double OpenPrice=Ask;

int count=3;

if (count==3)

{

BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_1>0) //Checking if the order was opened or not

{

sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + " Buy order 1 sent successfully. Ticket=" + BuyOrder_1;

count = count - 1;

//////////////////////////////////////////////////////////////

Thus count is decreasing and opening orders till count=1. So 3 orders are opening as count=3 initially.

The question was the following : how does it know that there were 3 opened orders once, and then only one is left? The fact that there is only one opened order left does not show anything. You have to check the list of closed orders for the 2 other orders that were a part of a triplet, and since brokers can change your comment field, there is no way how you can know that some orders were a part of a same triplet (no field in the list of orders that can be used to mark that some orders are belonging to a same group of orders).

You could try using files for saving ticket numbers that belonged to triplets, but, in a case of trying to use the same EA from another terminal, you can get terrible errors. The same thing can happen when you reinstall metatrader. Using global variables is ever worse (they are almost the same thing like using files - but worse), so there is no meaningful way that you can track triplets of orders correctly

So how do you find out that 1 opened order is that last opened order of the 3 or it is a first opened order of a new triplet of orders?

 
mladen:
The question was the following : how does it know that there were 3 opened orders once, and then only one is left? The fact that there is only one opened order left does not show anything. You have to check the list of closed orders for the 2 other orders that were a part of a triplet, and since brokers can change your comment field, there is no way how you can know that some orders were a part of a same triplet (no field in the list of orders that can be used to mark that some orders are belonging to a same grup of orders). So how do you find out that 1 opened order is that last opened order of the 3 or it is a first opened order of a new triplet of orders?

Mladen,

Ckeck you pm, need coder

Dream of a BIG icon for PM !

 
mladen:
So how do you find out that 1 opened order is that last opened order of the 3 or it is a first opened order of a new triplet of orders?

There is a condition:

if (MA_Difference_1>=Value_Diff && iOpenOrders_Buy ==0)

So by this I'm ensuring that if there is any existing buy order, it wont open any new buy order in spite of getting the conditions met. It'll open a new order only when there wont be any existing buy/sell order.

And as it's opening 3 orders at a time of same kind(buy/sell) and if two of them is closed already, then the left one is of that same kind for sure.

I have tested it. So there is no confusion about it.

 
Oridroo:
There is a condition:

if (MA_Difference_1>=Value_Diff && iOpenOrders_Buy ==0)

So by this I'm ensuring that if there is any existing buy order, it wont open any new buy order in spite of getting the conditions met. It'll open a new order only when there wont be any existing buy/sell order.

And as it's opening 3 orders at a time of same kind(buy/sell) and if two of them is closed already, then the left one is of that same kind for sure.

I have tested it. So there is no confusion about it.

There is a lot of assumption in the whole thing. First one is that when you try to open 3 orders, it will actually open 3 orders. What if it opens just 1? . And so on ...

Sorry. But is seems that we are talking about different things all the time. I hope someone can help you, since I can not

Happy trading

 
mladen:
There is a lot of assumption in the whole thing. First one is that when you try to open 3 orders, it will actually open 3 orders. What if it opens just 1? . And so on ...

Sorry. But is seems that we are talking about different things all the time. I hope someone can help you, since I can not

Happy trading

If you can't, it's OK.

I have been testing it for a while with different brokers and it hasn't 'Failed' to open 3 orders so far.

Anyway, I think you could tell at least what point/logic makes an EA enable to distinguish between different pairs while I'm calling 'OrdersTotal()'?

Any little EA example will be Fine.

 
macerina:
Thanks for the reply mladen is it possible to code a mt4 indicator with this criteria Thanks in advance

macerina

Check the indicator at this post : https://www.mql5.com/en/forum/173574/page432 . It is almost exactly the same as the one described by aspen graphic code

 

Thank you Mladen for the code ... Does this have the double macd comparision and 50 crossover as you have explained in the previous logic.

Thanks in advance

Reason: