indicator doesn't show arrows - page 3

 

Well, I have to say you're right...but I have a problem with the order...look at this:


double TLR_average, Lot;
double now=1,last=0;
int direction=0, Ticket;
static bool first_order=false;

...

if(now>(last+(difference/1000)))
     {
       if(direction<1)
       {
        Lot=AccountFreeMargin()/Lotsdivisor;
        if (OrderSelect(0,SELECT_BY_POS)==true)
               if(OrderType()==OP_BUY)
                  {
                   OrderClose(OrderTicket(),OrderLots(),Ask,50);      
                   OrderSend(Symbol(),OP_SELL,Lot,Bid,50,0,0);
                  }
            if ( first_order == false )
            {
             Ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,50,0,0);
             if ( Ticket > 0 )
                 first_order = true;     
            }                 
        direction=1;
       } 
     }
       else  
         if(now<(last-(difference/1000)))
         {
           if(direction>-1)
           {
            Lot=AccountFreeMargin()/Lotsdivisor;
            if (OrderSelect(0,SELECT_BY_POS)==true)
               if(OrderType()==OP_BUY)
                  {
                   OrderClose(OrderTicket(),OrderLots(),Ask,50);      
                   OrderSend(Symbol(),OP_SELL,Lot,Bid,50,0,0);
                  }
            if ( first_order == false )
            {
             Ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,50,0,0);
             if ( Ticket > 0 )
                 first_order = true;     
            }                 
            direction=-1;
           }        
         } 
         
     last=TLR_average;


It just opens a sell order, but the EA doesn't close it any more or opens a new position...

The aim of the code is to open a position, and to close the old position and open a new position in the different direction if there is the signal!


Thanks for your help!



leMai

 
The order selection is odd and you can't close and open an order straight away. Look at the sample code to understand the order selection process and note the delay in the form of exit when a server command is sent. The server takes a finite time to execute your instructions.
 

I'm sorry, but this time you're wrong...I can just close and open and order in 2 lines while one tick. The code above works, but if I try something I always copy many things around, in this case a few parameters were wrong. But unfortunatelly I have a new problem with I new indicator...I don't want to ask every time because the faults are often similar, but I try to find a solution for hours and nothing works:


#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 LimeGreen
#property indicator_color4 Red
//---- input parameters
extern int FastEMA = 12;
extern int SlowEMA = 24;
extern int SignalEMA = 9;
extern double difference=0.05;
//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];
double UpArrow[];
double DnArrow[];

double now=1,last=0;
int direction=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(7);
   SetIndexBuffer(0, MACDBuffer);
   SetIndexBuffer(1, SignalBuffer);
   SetIndexBuffer(4, FastEMABuffer);
   SetIndexBuffer(5, SlowEMABuffer);
   SetIndexBuffer(6, SignalEMABuffer);
   SetIndexBuffer(2, UpArrow);
   SetIndexBuffer(3, DnArrow);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE,EMPTY);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 233);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 234);
   SetIndexDrawBegin(0, SlowEMA);
   SetIndexDrawBegin(1, SlowEMA);
   IndicatorShortName("ZeroLag MACD Arrow(" + FastEMA + "," + SlowEMA + "," + SignalEMA + ")");
   SetIndexLabel(0, "MACD");
   SetIndexLabel(1, "Signal");
//----
   return(0);
  }

int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
   
   limit=ArraySize(SignalBuffer);
   
   double EMA, ZeroLagEMAp, ZeroLagEMAq;
   for(int i = 0; i < limit; i++)
     {
       FastEMABuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
       SlowEMABuffer[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
     }
   for(i = 0; i < limit; i++)
     {
      EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i);
      ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - EMA;
      EMA = iMAOnArray(SlowEMABuffer, Bars, SlowEMA, 0, MODE_EMA, i);
      ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - EMA;
      MACDBuffer[i] = ZeroLagEMAp - ZeroLagEMAq; 
      
      now=MACDBuffer[i];
     
    
       if(now>(last+(difference/1000)))
       {
         if(direction<1)
         {
          UpArrow[i]=MACDBuffer[i];
          direction=1;
         } 
       }
         else  
           if(now<(last-(difference/1000)))
           {
             if(direction>-1)
             {
              DnArrow[i]=MACDBuffer[i];
              direction=-1;
             }        
           } 
         
       last=MACDBuffer[i];
           
     }
   for(i = 0; i < limit; i++)
    {
       SignalEMABuffer[i] = iMAOnArray(MACDBuffer, Bars, SignalEMA, 0, MODE_EMA, i);
       
    }   
   for(i = 0; i < limit; i++)
     {
       EMA = iMAOnArray(SignalEMABuffer, Bars, SignalEMA, 0, MODE_EMA, i);
       SignalBuffer[i] = SignalEMABuffer[i] + SignalEMABuffer[i] - EMA;
     }
  
   return(0);
  }


Again, there are to many arrows on the same position in the online chart, and I didn't find out why!

What is the solution this time? Please help me, and what can I do that I find it the next time by my own, and not only because I was trying it long enough?


Thank you!



leMai

 
leMai:

I'm sorry, but this time you're wrong...I can just close and open and order in 2 lines while one tick.


Again, there are to many arrows on the same position in the online chart, and I didn't find out why!

What is the solution this time? Please help me, and what can I do that I find it the next time by my own, and not only because I was trying it long enough?

Wrong is a poor choice of words on your part. You will be sorry in the future when you will come back with questions like " why do I get errors when trying to open a trade". I shall laugh and think of the old adage "you can lead a horse to water but you can't make it drink".


There are still fundamental errors in your code where you are not considering the size of the arrays.


   limit=ArraySize(SignalBuffer);
   for(int i = 0; i < limit; i++){
       FastEMABuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);

   EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i);


Look you fill the FastEMABuffer over range limit then you do IMAOnArray over the range Bars why?

The arrow placement logic looks wrong to me as well.
 

I found my mistake yesterday morning...the for-loop was wrong!

The reasons for the wrong parameters are, that if something doesn't work and I don't knowhow to fix the problem, I try each possibility, also if I already know that it won't work, just to see what happens!

The code I have send was the last code I was testing...so don't wonder why is seems completely illogic!


leMai

Reason: