Download MetaTrader 5
To add comments, please log in or register
Develop trading robots to order. Make profit with Freelance service!
Blackriver67
119
Blackriver67 2015.10.07 10:20 

Dear all,

I am working on an index (see code below) which should draw arrows for trading signals which are based on calculations on the enty timeframe (e.g. H4)

and on higher timeframes (e.g. D1 and W1). Under the bottom line it should draw certain arrows for different typs of entry signals and if an entry signal has

occured (where I would have entered a trade) it should then draw an arrow if the an exit signals occurs. So much for the plan but the implementation drives

me crazy meanwhile because as a non-professional programer I tried to solve it by trail and error in many ways and have no more idea although I think it is

just a small issue...

The problem is that so far I just get it working if I recalculate the whole history over and over again ("limit = Bars; //Recalc all Bars") which is quite unefficient

for 20 pairs with other indicators and EAs and which I want to avoid. See below the result as it should be:

 

But in terms of efficiency I recalc just the last 42 bars ("limit=MathMax(Bars-counted_bars,delta_PTF);  //Recalc Number of Bars of Prime Timeframe") because

the indicator also repaints values of a higher timeframe (i.e. W1 => 10080 / 240 = 42) and then I get the result below. Have a look at the difference between

before and after the grey horizontal line which represents the 42 bars:


And if I just recalc the last bar ("limit = Bars-counted_bars;  //Recalc last Bar") then it displays no exit arrows at all and it draws multiple enty signals which it

shouldn't...


So please have mercy and help me out of that my mind has become stuck meanwhile. Any help is highly appreciated...

Thanks all!

PS: Below is the code:

   int Sig_Dist = ATR_0 * Sig_Dist_ATR_Mult;
   int limit, delta_PTF=0, delta_TTF=0;
   datetime TimeArray_PTF[];
   datetime TimeArray_TTF[];

   if(Prime_TF > Period()) delta_PTF = MathCeil(Prime_TF / Period());
   if(Trend_TF > Period()) delta_TTF = MathCeil(Trend_TF / Period());
//   Print(IntegerToString(delta_PTF), " ", IntegerToString(delta_TTF)); 

   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit = Bars; //Recalc all Bars
//   limit = Bars-counted_bars;  //Recalc last Bar
//   limit=MathMax(Bars-counted_bars,delta_PTF);  //Recalc Number of Bars of Prime Timeframe

   ArrayCopySeries(TimeArray_PTF,MODE_TIME,Symbol(),Prime_TF);
   ArrayCopySeries(TimeArray_TTF,MODE_TIME,Symbol(),Trend_TF);
  
   i_HTF=0;
   i_PTF=0;
   i_TTF=0;
   i_LTF=0;

   for(i_ETF=0; i_ETF<limit; i_ETF++)
     {
      while(Time[i_ETF] < TimeArray_PTF[i_PTF]) i_PTF++;
//      i_PTF = iBarShift(Symbol(), Prime_TF, Time[i_ETF]);
//      MAO_Prime     = iOsMA(NULL,Prime_TF,12,26,9,0,i_PTF+MAO_Offset);

      while(Time[i_ETF] < TimeArray_TTF[i_TTF]) i_TTF++;
//      i_TTF = iBarShift(Symbol(), Trend_TF, Time[i_ETF]);
//      MAO_Trend     = iOsMA(NULL,Trend_TF,12,26,9,0,i_TTF+MAO_Offset);
//      MAO_Entry     = iOsMA(NULL,Entry_TF,12,26,9,0,i_ETF+MAO_Offset);
//      Print(TimeToStr(Time[i_ETF],TIME_DATE)," ", DoubleToString(MAO_Prime,5), " ", DoubleToString(MAO_Trend,5), 
//            " ", DoubleToString(MAO_Entry,5));

      Long_Buffer[i_ETF] = 0;
      Short_Buffer[i_ETF] = 0;
      Long_Ex_Buffer[i_ETF] = 0;
      Short_Ex_Buffer[i_ETF] = 0;
      Long_Pos_Buffer[i_ETF] = Long_Pos_Buffer[i_ETF+1];
      Short_Pos_Buffer[i_ETF] = Short_Pos_Buffer[i_ETF+1];

      Func_Calc_Signals();
      
//---- Exit Signals ---------
      if(Long_Pos_Buffer[i_ETF+1] == 1 && EX_Entry_Code == 232) //is exiting long
        {
         Long_Ex_Buffer[i_ETF] = High[i_ETF] + Sig_Dist * TV_Pip_Adj * Point;
         SetIndexArrow(2,240);  //Arrow Exit Long
         Long_Pos_Buffer[i_ETF] = 0;
//         Print("Long Ex ", TimeToStr(Time[i_ETF],TIME_DATE)," ",TimeToStr(Time[i_ETF],TIME_MINUTES), " LP: ", 
//               IntegerToString(Long_Pos_Buffer[i_ETF]),  " SP: ", IntegerToString(Short_Pos_Buffer[i_ETF]));
        }
      
      if(Short_Pos_Buffer[i_ETF+1] == 1 && EX_Entry_Code == 231) //is exiting short
        {
         SetIndexArrow(3,239);  //Arrow Exit Short
         Short_Ex_Buffer[i_ETF] = Low[i_ETF] - Sig_Dist * TV_Pip_Adj * Point;
         Short_Pos_Buffer[i_ETF] = 0;
//         Print("Short Ex ", TimeToStr(Time[i_ETF],TIME_DATE)," ",TimeToStr(Time[i_ETF],TIME_MINUTES), " LP: ", 
//               IntegerToString(Long_Pos_Buffer[i_ETF]),  " SP: ", IntegerToString(Short_Pos_Buffer[i_ETF]));
        }

//---- Entry Signals ---------
      if(Long_Pos_Buffer[i_ETF+1] == 0 && JUMP_Sig_Code == 233) //is going long
        {
         SetIndexArrow(0,241); //Arrow JUMP Long
         Long_Buffer[i_ETF] = Low[i_ETF] - Sig_Dist * TV_Pip_Adj * Point;
         Long_Pos_Buffer[i_ETF] = 1;
//         Print("Long ", TimeToStr(Time[i_ETF],TIME_DATE)," ",TimeToStr(Time[i_ETF],TIME_MINUTES), " LP: ", 
//               IntegerToString(Long_Pos_Buffer[i_ETF]),  " SP: ", IntegerToString(Short_Pos_Buffer[i_ETF]));
        }

      if(Short_Pos_Buffer[i_ETF+1] == 0 && JUMP_Sig_Code == 234) //is going short
        {
         SetIndexArrow(1,242); //Arrow JUMP Short
         Short_Buffer[i_ETF] = High[i_ETF] + Sig_Dist * TV_Pip_Adj * Point;
         Short_Pos_Buffer[i_ETF] = 1;
//         Print("Short ", TimeToStr(Time[i_ETF],TIME_DATE)," ",TimeToStr(Time[i_ETF],TIME_MINUTES), " LP: ", 
//               IntegerToString(Long_Pos_Buffer[i_ETF]),  " SP: ", IntegerToString(Short_Pos_Buffer[i_ETF]));
        }

//      Print("Bar ", TimeToStr(Time[i_ETF],TIME_DATE)," ",TimeToStr(Time[i_ETF],TIME_MINUTES), " LP: ", 
//            IntegerToString(Long_Pos_Buffer[i_ETF]),  " SP: ", IntegerToString(Short_Pos_Buffer[i_ETF]));
     }
Keith Watford
Moderator
7887
Keith Watford 2015.10.07 10:32  

Please shorten the width of your Print lines of code

Your post and code is twice the width of my screen

Makes it difficult to read, so I won't 

Blackriver67
119
Blackriver67 2015.10.07 10:40  
GumRai:

Please shorten the width of your Print lines of code

Your post and code is twice the width of my screen

Makes it difficult to read, so I won't 

Done. Hope you can read it now, GumRai.
Keith Watford
Moderator
7887
Keith Watford 2015.10.07 10:56  

Sorry,

I have no idea what you are trying to achieve 

Blackriver67
119
Blackriver67 2015.10.07 11:20  
GumRai:

Sorry,

I have no idea what you are trying to achieve 

What I want to achieve is that the indicator draws just ONE entry arrow as soon as an entry signal occurs and if there was an entry signal that it draws an

exit arrow as soon as an exit signal occurs. Like it does in the first screenshot.

BUT I want to achieve that without recalculating the whole history at every tick. And that is the problem. My code just works if I recalculate the whole

history over and over again.

Keith Watford
Moderator
7887
Keith Watford 2015.10.07 11:39  

What I mean is that I don't know what your code is aiming to achieve.

You wrote the code, so you can follow it, I can't. The use of non reader-friendly variable names doesn't help. 

Blackriver67
119
Blackriver67 2015.10.07 12:11  
GumRai:

What I mean is that I don't know what your code is aiming to achieve.

You wrote the code, so you can follow it, I can't. The use of non reader-friendly variable names doesn't help. 

The point is that I am trying to keep the infomation if an entry signal occured (e.g. long_position_buffer[]) in order to draw an entry arrow

only once and to draw an exit arrow only if there was an enty arrow before.


long_buffer[i] = 0; //displays entry arrows

long_ex_buffer[i] = 0; //displays exit arrows

long_position_buffer[i] = long_position_buffer[i+1]


if(long_position_buffer[i+1] == 0 && long_entry_signal == true) {long_buffer[i] = long_entry_arrow; long_position_buffer[i] = 1;}

if(long_position_buffer[i+1] ==1 && long_exit_signal == true) {long_ex_buffer[i] = long_exit_arrow; long_position_buffer[i] = 0;}


BUT this type of logic only works if I recalculate the whole history which I do not want. So I am looking for a clue how I can adopt

this logic or hint for another solution which works for my problem...

Blackriver67
119
Blackriver67 2015.10.08 13:42  

Hey all,

has really no one an idea why I am getting serveral entry arrows on the same condition although I am using a buffer to check if there is already an open trade

or can point me to the right topic to do further search by myself?

/
To add comments, please log in or register