Download MetaTrader 5
To add comments, please log in or register
Looking for like-minded people? You will find lots of them on the Forum!
brettosm8
241
brettosm8 2014.03.30 11:10 

Hi there,

I put a VLINE and 2 HLINEs on a chart.

The VLINE is the day a signal occurs that I want to trade.

The HLINE's are profit targets.

I want to calcuate the high or low of the bar I dop the VLINE on because that will be the signal invalidation value. If price reaches it before positions are opened the orders to open should be deleted.

Below is how I'm trying to calculate the number of days since the last server day. I'm only looking at vertical line at the moment.

for(int k=0;k<ObjectsTotal();k++)
      {
      Print("Object "+k+": ",ObjectName(k));
      if(StringFind(ObjectName(k),"Vertical",0)>=0)
         {
         ObjectArray[k]=ObjectGet(ObjectName(k),OBJPROP_TIME1);
         double SecondsSinceSignal=StringToInteger(TimeCurrent()-ObjectArray[k]);
         double MinutesSinceSignal=SecondsSinceSignal/60;
         double HoursSinceSignal=MinutesSinceSignal/60;
         double DaysSinceSignal=HoursSinceSignal/24;
         int DaysResult=MathRound(DaysSinceSignal);
         
         Print("Seconds since signal bar: ",SecondsSinceSignal);
         Print("Minutes since signal bar: ",MinutesSinceSignal);
         Print("Hours since signal bar: ",HoursSinceSignal);
         Print("Days since signal bar: ",DaysSinceSignal);
         Print("DaysResult: ",DaysResult);
         }
      else
         {
         ObjectArray[k]=ObjectGet(ObjectName(k),OBJPROP_PRICE1);
         }
      }//End for loop

I place a vline on the most right bar with a result of 1. For every bar I move to the left the result increases by 1 until when the result should read 6 but reads 8.

The below captures show the prints from the most right bar and moving left.

Got any idea how to get consistant result or approach the whole thing better?

Thanks.

brettosm8
241
brettosm8 2014.03.30 11:14  

"Below is how I'm trying to calculate the number of days since the last server day."

should read

"...number of days from the last/current server day to the day the VLINE is on."

qjol
3243
qjol 2014.03.30 11:26  
brettosm8
241
brettosm8 2014.03.31 01:55  
That looks good, will give it a go. Thanks.
qjol:
iBarShift
brettosm8
241
brettosm8 2014.03.31 11:51  
Yep, worked a charm. Thanks.
/
To add comments, please log in or register