Drawing a line with two points

 

I would like to draw a simple line 10 points above from my entry.  But this line needs to start 2 candles ago and end 2 candles in front of my entry candle.

Is this possible? Can someone post a sample code?

Thanks!

 
rtrades :

I would like to draw a simple line 10 points above from my entry.  But this line needs to start 2 candles ago and end 2 candles in front of my entry candle.

Is this possible? Can someone post a sample code?

Thanks!

Show your idea in a picture. Explain what is " my entry"?

 
rtrades: Is this possible? Can someone post a sample code?
  1. Of course, it's possible. Find the index of your entry bar. Get the time of two bars before. Get the time of two bar after. Draw your TLine. What's the problem?

  2. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help 2017.04.21

 
rtrades:

I would like to draw a simple line 10 points above from my entry.  But this line needs to start 2 candles ago and end 2 candles in front of my entry candle.

Is this possible? Can someone post a sample code?

Thanks!

It is only an example

//+------------------------------------------------------------------+
//|                                                      Ejemplo.mq5 |
//+------------------------------------------------------------------+
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
CPositionInfo Posicion;
CTrade Trade;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   ejemplo();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ejemplo()
  {
   if(PositionsTotal() == 0)
     {
      Trade.Buy(0.01, NULL, 0, 0, 0, NULL);
      Posicion.Select(Symbol());
      double PriceLine = Posicion.PriceOpen() + 10 * Point();

      datetime TimeStart = iTime(Symbol(), PERIOD_CURRENT, 2);

      datetime TimeEnd = Posicion.Time() + 2 * PeriodSeconds(PERIOD_CURRENT);


      string name = "myLine";
      ObjectCreate(0, name, OBJ_TREND, 0, TimeStart, PriceLine, TimeEnd, PriceLine);
      ObjectSetInteger(0, name, OBJPROP_RAY, false);
      ObjectSetInteger(0, name, OBJPROP_COLOR, clrAqua);
     }
  }
//+------------------------------------------------------------------+
 
Antonio Simon Del Vecchio:

It is only an example

It worked but it creates line sideway..




 
rtrades: It worked but it creates line sideway..

That is because you did not implement the example properly. Show your code so we can point out your error!

 
Fernando Carreiro:

That is because you did not implement the example properly. Show your code so we can point out your error!

      Posicion.Select(Symbol());
      double PriceLine = Posicion.PriceOpen() + 10 * Point();

      datetime TimeStart = iTime(Symbol(), PERIOD_CURRENT, 2);
      datetime TimeEnd = Posicion.Time() + 2 * PeriodSeconds(PERIOD_CURRENT);
      string name = "myLine";
      ObjectCreate(0, name, OBJ_TREND, 0, TimeStart, PriceLine, TimeEnd, PriceLine);
      ObjectSetInteger(0, name, OBJPROP_RAY, false);
      ObjectSetInteger(0, name, OBJPROP_COLOR, clrAqua);
        
 
Antonio Simon Del Vecchio:

It is only an example

Ok I got it working but When I implement it on the On-tick function it slows down the chart. Anyone know how to fix this?

 
That's because you create hundreds of objects. On every tick.

 
Dominik Egert:
That's because you create hundreds of objects. On every tick.

Ok that makes sense. But how can I stop that from happening?
 
You need to track if you have created the object already or not.
Reason: