Hi to all ,
I am very new to programming and struggle about two weeks to write an EA but still have issues.
Can anyone who have programming skills help will be much appreciated .
I want EA to manage my two orders with different dynamic stop loss based on MA .
But before the trailing starts I won't both trades to be moved in BE after some pips .
Here what I have written so far .
int otype = FindLastOrderType();
if (CountTrades() == 2 && otype == OP_BUY && OrderStopLoss() < OrderOpenPrice())
{
if(OrderSelect(ticket2, SELECT_BY_TICKET,MODE_TRADES))
{
TP = OrderTakeProfit();
price = FindLastBuyPrice();
SL = NormalizeDouble(price +50 * Point, Digits);
ticket = OrderModify(ticket2, OrderOpenPrice(), SL , 0, 0);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
if(OrderSelect(ticket3, SELECT_BY_TICKET,MODE_TRADES))
{
TP = OrderTakeProfit();
price = FindLastBuyPrice();
SL = NormalizeDouble(price + 50* Point, Digits);
ticket = OrderModify(ticket3, OrderOpenPrice(), SL , 0, 0);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
}
if (CountTrades() <= 2 && otype == OP_BUY && OrderStopLoss() > OrderOpenPrice())
{
MA1 = iMA(Symbol(), PERIOD_CURRENT, MA1period, 0, MODE_EMA, PRICE_CLOSE, 0);
MA2 = iMA(Symbol(), PERIOD_CURRENT, MA2period, 0, MODE_EMA, PRICE_CLOSE, 0);
CP = iClose (Symbol(),PERIOD_CURRENT,0);
if(OrderSelect(ticket2, SELECT_BY_TICKET,MODE_TRADES))
{
Lots = OrderLots();
if( CP < MA1)
{
ticket = OrderClose(ticket2,Lots,Ask,3,Red);
if(ticket<0)
{
Print("OrderClose failed with error #",GetLastError());
}
else
Print("OrderClose placed successfully");
}
}
if(OrderSelect(ticket3, SELECT_BY_TICKET,MODE_TRADES))
{
Lots = OrderLots();
if( CP < MA2)
{
ticket = OrderClose(ticket3,Lots,Ask,3,Red);
if(ticket<0)
{
Print("OrderClose failed with error #",GetLastError());
}
else
Print("OrderClose placed successfully");
}
}
}
For the first section I get error 4051 for invalid stop loss and for the second scale i get error 4108 for the Orderclose as unknown ticket . But when I run test in visual mode it does what i want but still getting this errors and don't want to risk to go live with it .
As per my research I have found that probably it is required for both sections to be added descending loop but unfortunately i don't know how and where to implement it.
Thanks you in advance whoever can help .
I am very new to programming and struggle about two weeks to write an EA but still have issues.
Can anyone who have programming skills help will be much appreciated .
I want EA to manage my two orders with different dynamic stop loss based on MA .
But before the trailing starts I won't both trades to be moved in BE after some pips .
Here what I have written so far .
int otype = FindLastOrderType();
if (CountTrades() == 2 && otype == OP_BUY && OrderStopLoss() < OrderOpenPrice())
{
if(OrderSelect(ticket2, SELECT_BY_TICKET,MODE_TRADES))
{
TP = OrderTakeProfit();
price = FindLastBuyPrice();
SL = NormalizeDouble(price +50 * Point, Digits);
ticket = OrderModify(ticket2, OrderOpenPrice(), SL , 0, 0);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
if(OrderSelect(ticket3, SELECT_BY_TICKET,MODE_TRADES))
{
TP = OrderTakeProfit();
price = FindLastBuyPrice();
SL = NormalizeDouble(price + 50* Point, Digits);
ticket = OrderModify(ticket3, OrderOpenPrice(), SL , 0, 0);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
}
if (CountTrades() <= 2 && otype == OP_BUY && OrderStopLoss() > OrderOpenPrice())
{
MA1 = iMA(Symbol(), PERIOD_CURRENT, MA1period, 0, MODE_EMA, PRICE_CLOSE, 0);
MA2 = iMA(Symbol(), PERIOD_CURRENT, MA2period, 0, MODE_EMA, PRICE_CLOSE, 0);
CP = iClose (Symbol(),PERIOD_CURRENT,0);
if(OrderSelect(ticket2, SELECT_BY_TICKET,MODE_TRADES))
{
Lots = OrderLots();
if( CP < MA1)
{
ticket = OrderClose(ticket2,Lots,Ask,3,Red);
if(ticket<0)
{
Print("OrderClose failed with error #",GetLastError());
}
else
Print("OrderClose placed successfully");
}
}
if(OrderSelect(ticket3, SELECT_BY_TICKET,MODE_TRADES))
{
Lots = OrderLots();
if( CP < MA2)
{
ticket = OrderClose(ticket3,Lots,Ask,3,Red);
if(ticket<0)
{
Print("OrderClose failed with error #",GetLastError());
}
else
Print("OrderClose placed successfully");
}
}
}
For the first section I get error 4051 for invalid stop loss and for the second scale i get error 4108 for the Orderclose as unknown ticket . But when I run test in visual mode it does what i want but still getting this errors and don't want to risk to go live with it .
As per my research I have found that probably it is required for both sections to be added descending loop but unfortunately i don't know how and where to implement it.
Thanks you in advance whoever can help .