Need code for drawing horizontal lines for hidden s/l and t/p ...
digitalmythology:
Greetings, This is my first post, hope I get it right! I am coding an EA that uses hidden s/l and hidden t/p. I would like to draw horizontal lines of different colors for these values, say Green for entry, Red for stoploss, and gold for takeprofit. YES, I am well aware that they could be automatically drawn if I just place a s/l and t/p with my broker, but quite frankly I don't particulary want to go broke. Sometimes it works, sometimes not ... Lines are sometimes placed in wrong place or not at all.Sometimes only t/p line is placed, sometimes none are placed.Sometimes has different effect on different timeframes / currency pairs ??!? What am I doing wrong ? Please help ... If you need any account info :Accont Type : Demo / StandardBroker Digits : 5 digit brokerBroker : GoMarketsTimeFrame : 1H (Would like it to be correct for all Timeframes) Anyway, here is the code for my Draw_Lines() function :
Greetings, This is my first post, hope I get it right! I am coding an EA that uses hidden s/l and hidden t/p. I would like to draw horizontal lines of different colors for these values, say Green for entry, Red for stoploss, and gold for takeprofit. YES, I am well aware that they could be automatically drawn if I just place a s/l and t/p with my broker, but quite frankly I don't particulary want to go broke. Sometimes it works, sometimes not ... Lines are sometimes placed in wrong place or not at all.Sometimes only t/p line is placed, sometimes none are placed.Sometimes has different effect on different timeframes / currency pairs ??!? What am I doing wrong ? Please help ... If you need any account info :Accont Type : Demo / StandardBroker Digits : 5 digit brokerBroker : GoMarketsTimeFrame : 1H (Would like it to be correct for all Timeframes) Anyway, here is the code for my Draw_Lines() function :
Thanks in Advance ... - dm
void Draw_Lines()
{
if(OrdersTotal() > 0)
{
for(cnt=0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
// entry = OrderOpenPrice();
if (OrderType() == OP_BUY)
{
entry = OrderOpenPrice();
draw_stoploss = entry - (stoploss * Point * 10);
draw_takeprofit = entry + (takeprofit * Point * 10);
line_title = "Buy";
// Entry Line
ObjectCreate(line_title, OBJ_HLINE, 0, 0, entry);
ObjectSet(line_title, OBJPROP_COLOR, Green); // Buy line
ObjectSet(line_title, OBJPROP_WIDTH, 1);
ObjectSet(line_title, OBJPROP_STYLE, STYLE_SOLID);
// Stoploss Line
ObjectCreate("Stoploss", OBJ_HLINE, 0, 0, draw_stoploss);
ObjectSet("Stoploss", OBJPROP_COLOR, Red);
ObjectSet("Stoploss", OBJPROP_WIDTH, 1);
ObjectSet("Stoploss", OBJPROP_STYLE, STYLE_SOLID);
// Takeprofit Line
ObjectCreate("Takeprofit", OBJ_HLINE, 0, 0, draw_takeprofit);
ObjectSet("Takeprofit", OBJPROP_COLOR, Gold);
ObjectSet("Takeprofit", OBJPROP_WIDTH, 1);
ObjectSet("Takeprofit", OBJPROP_STYLE, STYLE_SOLID);
}
if (OrderType() == OP_SELL)
{
entry = OrderOpenPrice();
draw_stoploss = entry + (stoploss * Point * 10);
draw_takeprofit = entry - (takeprofit * Point * 10);
line_title = "Sell";
// Entry Line
ObjectCreate(line_title, OBJ_HLINE, 0, 0, entry);
ObjectSet(line_title, OBJPROP_COLOR, Green); // Buy line
ObjectSet(line_title, OBJPROP_WIDTH, 1);
ObjectSet(line_title, OBJPROP_STYLE, STYLE_SOLID);
// Stoploss Line
ObjectCreate("Stoploss", OBJ_HLINE, 0, 0, draw_stoploss);
ObjectSet("Stoploss", OBJPROP_COLOR, Red);
ObjectSet("Stoploss", OBJPROP_WIDTH, 1);
ObjectSet("Stoploss", OBJPROP_STYLE, STYLE_SOLID);
// Takeprofit Line
ObjectCreate("Takeprofit", OBJ_HLINE, 0, 0, draw_takeprofit);
ObjectSet("Takeprofit", OBJPROP_COLOR, Gold);
ObjectSet("Takeprofit", OBJPROP_WIDTH, 1);
ObjectSet("Takeprofit", OBJPROP_STYLE, STYLE_SOLID);
}
Print("Entry = " + DoubleToStr(entry, 7));
Print("Stoploss = " + DoubleToStr(stoploss, 7));
Print("TakeProfit = " + DoubleToStr(takeprofit, 7));
}
}
return(0);
}
Aren't you checking if the open order has same magicnumber and same Symbol()?
Regards,
deVries
Greetings,
This is my first post, hope I get it right!
I am coding an EA that uses hidden s/l and hidden t/p. I would like to draw horizontal lines of different colors for these values, say Green for entry, Red for stoploss, and gold for takeprofit. YES, I am well aware that they could be automatically drawn if I just place a s/l and t/p with my broker, but quite frankly I don't particulary want to go broke.
Sometimes it works, sometimes not ...
Lines are sometimes placed in wrong place or not at all.
Sometimes only t/p line is placed, sometimes none are placed.
Sometimes has different effect on different timeframes / currency pairs ??!?
What am I doing wrong ? Please help ...
If you need any account info :
Accont Type : Demo / Standard
Broker Digits : 5 digit broker
Broker : GoMarkets
TimeFrame : 1H (Would like it to be correct for all Timeframes)
Anyway, here is the code for my Draw_Lines() function :
Thanks in Advance ...
- dm